Web-based chess lab with FastAPI backend, python-chess engines (now including MCTS + CNN value net), and a React + TypeScript + Tailwind frontend.
backend/– FastAPI app, AI engines, M2M runner.frtend/– Vite React UI with react-chessboard.knight-shift-ai-whitebook.md– Original design doc.PROJECT_TODO.md– Status tracker derived from the whitebook.
Requirements: Python 3.11+, pip.
cd backend
python -m venv .venv
.venv\Scripts\activate # or source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 6789GET /health– service status.POST /games– create a game (mode: h2h|h2m|m2m,ai_level: level1..level5|ultimate|mcts|mcts_cnn,player_color: white|black).GET /games/{id}– fetch game state (FEN, move history, status).POST /games/{id}/move– submit human move (from_square,to_square,promotionoptional).POST /games/{id}/ai-move– ask AI to move (used for H2M or M2M); accepts optionaltime_limit(seconds) to enforce per-move budget.POST /games/{id}/resign– resign game.POST /m2m/match– run AI vs AI match once (returns detail + moves). Supports per-side time limits viatime_limit_white/time_limit_black.POST /m2m/batch– run batch of AI matches (aggregated results) with optional per-side time limits.POST /m2m/time-benchmark– run a sweep of per-move time limits for two engines and returns aggregated stats + a PNG (base64) chart.GET /m2m/matches/GET /m2m/tests– listings.
Requirements: Node 18+ and pnpm/npm/yarn.
cd frtend
npm install
npm run dev
# Vite dev server defaults to http://localhost:6790Set VITE_API_BASE in .env if the backend is not on http://localhost:6789.
/playincludes a per-move AI time control for H2M./m2mincludes per-move limits for matches/batches and a “Time-scaled Benchmark” tool that runs background sweeps and renders a 2D chart comparing two engines across time budgets.- All batch/benchmark runs are persisted under
tests/so progress survives page refresh and can be re-read from the Test Packages list.
Generate data and fine-tune the tiny CNN value head used by the mcts_cnn engine:
cd backend
python -m app.training.selfplay --games 20 --max-moves 140 --time-limit 0.8 --epochs 8
# Model saved to backend/app/engine/checkpoints/mcts_value.pt by default- Pages:
/Home overview./playBoard: H2H / H2M with controls, status bar, move list./m2mStart AI vs AI matches (async, parallel) and view the match list./replay/:matchIdStep through completed M2M games./historyView recent H2H/H2M and M2M results.
- Choose mode (H2H/H2M) and AI level, pick your color, and start a new game on
/play. - If you pick black, the AI opens; promotion defaults to queen for now.
- Use "AI Move" to trigger the engine when it is its turn; status bar shows check/finish state.
- On
/m2m, run quick AI vs AI matches; click "Replay" to open the viewer. Matches appear immediately with running status and update as they finish. - Replay viewer supports autoplay with adjustable speed.
- Prep once:
pip install -r backend/requirements.txtandnpm install --prefix frtend - Run
python launcher.pyto start backend (6789), frontend (6790), and open the browser automatically. - Optional:
pyinstaller --onefile launcher.pyto build a single-file launcher; still requires Node/npm and Python deps available on the host.
- Replay viewer for finished games is stubbed in the plan (
PROJECT_TODO.md). - Data storage is in-memory for MVP; swap with Redis/DB if persistence is needed.