# RushChess

A local, professional chess workbench: play, analyse, manage databases,
study, train, prepare openings, and run engine events — with **RushChess**
(the ~2700-Elo UCI engine written in the Rush language, `../rush_lang/`) and
**Stockfish 17.1**. No dependencies, no build step: vanilla ES modules + a
stdlib-only Python bridge.

## Run

Double-click **`RushChess.exe`** (no Python needed — it starts the server
and opens the browser), or:

```
python server.py          # http://localhost:8642 (opens automatically)
```

Without the server the app still works from the browser (Play falls back to
a built-in JavaScript AI; engine features show as offline).

Rebuild the exe after changing `server.py`:
`python -m PyInstaller --onefile --name RushChess server.py`, then move
`dist/RushChess.exe` next to `index.html` (it resolves the GUI and engines
relative to its own location).

## Modes

| Mode | What it does |
|---|---|
| **Play** | vs engines (RushChess levels / Stockfish Elo 1320–full) or two players; time controls with increment, premoves, draw offers, resign/takeback, move confirmation, autosave, post-game review handoff |
| **Analysis** | multi-tab games, two simultaneous engines, MultiPV, live eval bar/graph, clickable lines, insert-as-variation, automated game review (accuracy, blunder tags, engine comments), threat display, opening explorer |
| **Database** | named databases on IndexedDB, PGN import/export, filters (player/event/ECO/result/Elo/opening/favorites/tags), virtualized list, duplicate removal, statistics, mini-board preview |
| **Study** | studies with nested chapters, variation trees, comments, embedded questions, notes, bookmarks, progress, reveal-next-move, PGN import/export, autosave |
| **Training** | tactics mined from your own games (engine-verified), guess-the-move from database games, coordinates trainer; ratings, streaks, session history |
| **Tournament** | round robin (single/double), Swiss, knockout; engine and human participants; standings with Buchholz/Sonneborn-Berger, crosstable, result editing, PGN export |
| **Engine match** | A vs B over N games, opening book, color alternation, win/draw adjudication, Elo estimate ± error, crash detection, resume, PGN export |
| **Board editor** | free placement, castling/en-passant/counters, legality validation, endgame presets, FEN, copy-as-image, jump to Analysis/Play |
| **Openings** | White/Black repertoires as trees, spaced-repetition drills, coverage check against your databases, transposition detection, weak-line report |
| **Broadcast** | replay a round's PGN on a board wall with staggered playback, featured board with live eval, presentation fullscreen |

## Interface

- Dockable panels (resize, collapse, move via header context menu, per-mode
  layout persistence), dark + light themes, three densities
- Command palette (`Ctrl+K`), configurable shortcuts (Settings → Shortcuts),
  menus, context menus on moves/games/panels
- Variation-tree notation with NAGs, comments, promote/delete, figurine
  option, inline evals, search
- Board: six piece sets — **Neo (flat modern, chess.com-style — default)**,
  Classic, **Lichess (Cburnett)**, **Merida**, Minimal, Letters — five board
  themes, premoves, user arrows/circles (right-drag; Shift=red, Alt=blue),
  keyboard SAN entry, blindfold, zoom, coordinate styles, animation speed;
  live evaluation bar with numeric score
- Four sound styles (Neo/chess.com-style click, standard synth, wooden,
  digital), volume, low-time warning
- Game review classifies every move (Brilliant / Best / Excellent / Good /
  Book / Inaccuracy / Mistake / Blunder), reports per-side accuracy, and
  estimates each player's Elo from average centipawn loss
- Analysis is the default workspace with a live engine that auto-runs
- Searchable settings backed by one central store (`rc.settings.v1`)

## Architecture

```
server.py            engine instance pools over UCI (/api/status /api/go /api/newgame)
css/                 tokens (themes/density) · app shell · board · panels
js/core/             rules.js (0x88 movegen, perft-validated) · doc.js (variation
                     tree, PGN with variations/comments/NAGs) · openings.js
js/svc/              settings · commands+shortcuts · engines (analysers) · gamedb
                     (IndexedDB + explorer index) · enginegame (match runner) ·
                     idb · sound · localai
js/ui/               icons (inline SVG) · dom (h/VirtualList) · widgets (menus,
                     dialogs, palette, toasts) · dock · appbus
js/board/            board.js component · pieces.js sets
js/panels/           session (board+doc wiring) · notation · enginepanel ·
                     evalgraph · explorer
js/modes/            one module per mode
js/main.js           boot, mode registry, global commands, settings UI
```

Rules correctness: move generation validated against published perft counts
(startpos, Kiwipete, CPW 3–5); a perft self-test is importable from
`js/core/rules.js`.

## Rebuilding RushChess (engine)

On this machine's non-UTF-8 locale, transpile + compile manually:

```powershell
$env:PYTHONUTF8 = "1"; $env:PYTHONPATH = "..\rush_lang\src"
python -m rushc transpile ..\rush_lang\examples\chess_engine\chess.rush |
    Out-File -Encoding utf8 engine\chess.cpp
g++ -O2 -std=c++20 engine\chess.cpp -o engine\rushchess.exe -static
```

Stockfish: official 17.1 AVX2 build (`engine/stockfish.exe`).

**Custom engines:** drop any UCI engine `.exe` into `engine/` and restart —
it appears in Play, Analysis, Engine match and Tournament automatically
(generic depth/movetime strength presets).

**Piece set credits:** `pieces/cburnett/` by Colin M.L. Burnett
(CC BY-SA 3.0) and `pieces/merida/` by Armando Hernández Marroquín
(freeware), both distributed via the lichess-org/lila repository.

## Data

Everything is stored locally: settings/layouts/shortcuts in localStorage,
games/studies/repertoires/tournaments/matches/training in IndexedDB
(database `rushchess`). Legacy v0 keys (`rc-theme`, `rc-sound`) migrate
automatically on first run.
