Commit 4cf1c318 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: puzzles working — create table, seed 20 puzzles, fix offset bug

- Created puzzles table in Supabase with RLS
- Seeded 20 Arabic chess puzzles (rating 500-1400)
- Fixed daily puzzle offset (was % 100, now % actual count)
- Added puzzle_rating, puzzle_streak, best_puzzle_streak to profiles
- Fixed ELO defaults (new profiles now get 1200 instead of 0)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 2dd53307
......@@ -22,7 +22,9 @@ if ($method === 'GET') {
$seed = crc32($today);
// Fetch puzzles and use the seed to deterministically select 3
$offset = abs($seed) % 100;
$countRes = supabase_rest('GET', "puzzles?select=id", [], $token);
$total = count($countRes['data'] ?? []);
$offset = $total > 3 ? abs($seed) % max(1, $total - 3) : 0;
$res = supabase_rest('GET', "puzzles?select=id,fen,moves,rating,themes,title&order=id.asc&offset={$offset}&limit=3", [], $token);
if ($res['status'] >= 200 && $res['status'] < 300) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment