8000 GitHub - ntucker/chess: Learn chess openings interactively · GitHub
[go: up one dir, main page]

Skip to content
ntuckerPublic

About

Learn chess openings interactively

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

290 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Opening Night logo: a gold chess knight in a spotlight on a dark stage, framed by red curtains

Opening Night

Learn your lines. An app for learning chess openings by playing them, on the web and on Android. GOALS.md says what it aims to be.

For now it has one screen: a game against Maia, an engine trained to play like people of a rating rather than to find the best move, or, one step harder than Maia's strongest rating, against Patricia, an aggressive engine, or Stockfish, which plays its best move. You can play either color, step back and forward through the moves, play a different move from any earlier position, and start over.

Get started

You need Node.js 22 or later, with Corepack enabled for Yarn 4.

corepack enable
yarn install
yarn web        # or: yarn android

yarn start opens the Expo dev server, where you can pick a platform or scan the QR code with Expo Go.

Script What it does
yarn start Start the Expo dev server
yarn web / yarn android Start it and open that platform
yarn typecheck Type-check with TypeScript
yarn lint Lint with ESLint
yarn format Format with Prettier
yarn test Run the unit tests (Jest)
yarn vendor:silk [path] Rebuild the vendored Silk packages from a Silk checkout (default ../silk)
yarn brand Redraw the logo and every icon made from it (scripts/make-brand.mjs)
yarn maia Download Maia's models and convert them for the app (see Maia)
yarn patricia Build Patricia for WebAssembly from a pinned commit and scripts/patricia/browser.patch into assets/patricia/ (needs Emscripten; see scripts/build-patricia.mjs)
yarn stockfish Copy Stockfish from the pinned stockfish package into assets/stockfish/, and full Stockfish into public/stockfish/ (every yarn install runs it; see Evaluation bar)
yarn import-study <name> Turn the lichess studies and Wikibooks pages listed in scripts/import-study/studies.ts into a lesson file in assets/lessons/, with popularity from the lichess explorer, which needs a lichess token in LICHESS_TOKEN or a proxy that adds one, notes rewritten by Claude through a signed-in claude CLI, and a generated idea note for each book move no guide explains (Claude's, Stockfish's and the explorer's answers committed in scripts/import-study/answers/, so a rerun rebuilds the same file and --no-model calls no model; usage in scripts/import-study/index.ts)
yarn cover-opponent <source> Check that a lesson answers every line a known opponent plays, from the opponent's lesson and then club players' common moves, and write a PGN source that fills the gaps with Stockfish's moves (Fable picking among near-equal ones); --measure only counts the gaps. Sources and settings are in scripts/import-study/coverOpponent.ts

How it fits together

Part Library Where
App shell and routing Expo SDK 58, Expo Router src/app/
Network Reactive Data Client 0.19 src/resources/
Design system Silk (@reactive/silk-native) src/components/
Board chessground in an Expo DOM component src/components/Board.tsx
Chess rules chessops src/game/
Opponent Maia at a rating from 1100 to 1900 (1500 by default), then Patricia at three node limits (the last its full strength), then Stockfish: lite, then full Stockfish as the hardest step; the rating in the opponent's name bar ("plays like a 1500") opens a rating slider to pick it on (Patricia's and Stockfish's ratings are estimates), as does a footnote under the scoresheet src/opponent/
Evaluation bar, and the opponent when chosen Stockfish 19 lite in WebAssembly, run on the device; full Stockfish 19, downloaded when first chosen as the opponent src/stockfish/

Silk isn't on npm yet, so the app installs it from the tarballs in vendor/.

Maia

Maia is a set of neural networks, one for each rating from 1100 to 1900, trained on lichess games to predict the move a player of that rating would make. For example, the 1100 network opens 1. e4 and answers 1. e4 with 1... e5. The app plays the move its network rates most likely, as Maia does on lichess, without searching ahead.

The networks ship with the app (assets/maia/, 1.2 MB each) and run on the device in plain TypeScript (src/maia/network.ts), so the app needs no server and works offline. A move takes about 25 ms on a laptop. It is worked out off the main thread (a Web Worker on the web, a background JavaScript runtime on Android), so the app keeps responding meanwhile. yarn maia downloads the original models from the Maia repository and rewrites them in the app's smaller format (scripts/convert-maia.mjs describes it).

Each network can also estimate how often each side wins, draws or loses from a position, learned from the results of games between players of its rating. Only the 1900 network keeps this part (its file is 1.7 MB); the evaluation bar can use it instead of Stockfish (see Evaluation bar).

The models are licensed under the GPL-3.0, which is different from the app's own license; see assets/maia/LICENSE.

Evaluation bar

The bar beside the board shows how the position stands: White's share of the bar is White's expected score, and the leading side's end shows its advantage in pawns, or M3 when it mates in 3. A footnote under the scoresheet ("Evaluation by Stockfish · Maia") picks who judges:

  • Stockfish (the default): Stockfish 19 lite, a 1.8 MB WebAssembly build with a small network. It searches each position once, ranking its three best moves, for 2,000,000 positions (about depth 19): about 3 s in Node and 5 to 6 s on a recent phone. The bar and the engine's lines update as each depth finishes, and for half the positions the score stops moving after about 0.5 s; move labels and the Stockfish opponent wait for the finished search. Pawns turn into an expected score with lichess's curve.
  • Maia: the 1900 network's estimate of how players of that rating score from here, converted to pawns the way Leela Chess Zero does. It uses less memory, since Stockfish isn't started.

On 240 positions from club-level games, judged against full Stockfish 19 at depth 24, Stockfish lite at depth 12 was off by 3.4 percentage points of expected score on average, and Maia 1900 by 10.4. Maia also misses mates: after 1. e4 e5 2. Qh5 d6 3. Nf3 Be6 4. Nc3 Nf6 5. Qh4 Be7 6. Ng5 O-O 7. Bd3 Bd7 8. Nd5 Nxd5, White mates with Qxh7, and Maia gives White 59%.

The top opponent, Full Stockfish, is the package's full build: Stockfish 19 with its large network, a 99 MB WebAssembly file (79 MB compressed). Neither git nor the app holds it: the web export serves it from public/stockfish/, and the app downloads it the first time it's picked and keeps it (on Android, from the live site).

Stockfish runs in a Web Worker. On the web that's in the page; on Android, whose JavaScript engine (Hermes) has no WebAssembly, it's inside a hidden web view (src/stockfish/EngineView.tsx, an Expo DOM component). Either way it searches off every thread that draws the app. It is licensed under the GPL-3.0 and ships unmodified as separate files that the app only talks to with UCI text commands; see assets/stockfish/LICENSE and the source at https://github.com/nmrugg/stockfish.js and https://github.com/official-stockfish/Stockfish.

Web deploys

Every push to main publishes the web app to GitHub Pages, at https://ntucker.github.io/chess/ (.github/workflows/web.yml). Every pull request from this repository also gets a preview at https://ntucker.github.io/chess/pr-preview/pr-<number>/, linked in a comment on the pull request. Previews skip minifying to build faster, keep their own settings and lesson progress, and are removed when the pull request closes. Each copy of full Stockfish's 99 MB counts toward Pages' 1 GB site limit, so a preview loads the live site's copy, unless its pull request changes the Stockfish build. Once main changes the build, an older preview can't load it until it's built again. Fork and Dependabot pull requests only build.

The workflow writes both into the gh-pages branch, which holds a single commit. A publish from main also keeps the hashed files of the site's last 10 builds (scripts/replace-site.mjs), so a page opened before a deploy still finds the files it loads late, such as Maia's worker or a lesson. A page older than that says a new version is out and offers a reload. The one-time setup is to set Source to Deploy from a branch, branch gh-pages, folder / (root), in the repository's Settings → Pages. Do it after the workflow has published main once, or the site is empty until it does.

To try the Pages build locally, export it the way the workflow does and serve dist/ at /chess/:

PAGES_BASE_PATH=/chess yarn expo export --platform web

Each build's phone layout is also checked in a real browser, at three phone sizes (the Layout job, scripts/check-layout.mjs); its screenshots are the run's layout-check artifact. To run it on that export:

yarn playwright install chromium   # once
PAGES_BASE_PATH=/chess yarn check:layout

Android builds

Every push to main that changes more than Markdown also builds the Android app (.github/workflows/android.yml) and replaces the APK at https://github.com/ntucker/chess/releases/download/android/opening-night.apk. To install it, open that link on the phone and open the download. The first time, Android asks to allow installs from the browser: tap Settings, turn on Allow from this source, and go back. Then tap Update (or Install); if Play Protect warns about an unknown app, choose to install anyway.

Builds are signed with the key in Expo's template, like local release builds, so each one installs over the last and keeps the app's data. A Google Play build is signed with another key: switching to it takes one uninstall.

Contributing with Claude

To work on this repo through a Claude project on claude.ai:

  1. Create a project and attach ntucker/chess (or your fork) and reactive/silk.

  2. Install user-kit.

  3. Send this in the project chat, then paste the text the coordinator replies with into the project's instructions:

    Set up this project: read .agents/projects/setup.md from main in ntucker/chess and follow it.
    
  4. For Android checks, link your computer to the project.

Use the Staff Reviewer bot template to run your own fork with autoland.

About

Learn chess openings interactively

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0