Language: AssemblyScript
Targets: WebAssembly (WASI preview 1) & Native (wasm2c)
License: GPL-3.0-or-later
UCI ID: RatchetHCE 0.4.0 (id author the Ratchet contributors)
UCI options: Hash (1-1024 MB, default 128), Threads (1), no ponder or Syzygy
Source: https://github.com/ratchet-chess/ratchet-hce · https://github.com/ratchet-chess/uci-over-wasi
Downloads: https://github.com/ratchet-chess/ratchet-hce/releases/tag/v0.4.0 (use wasm2c native x86-64 or x86-64-v3 for GUIs)
Play Now: https://ratchetchess.com/
Background
I started toying with chess engines a few months ago for Iterative Deepening, an open edutainment incremental game walking through the history of chess engines from Shannon material to NNUE. The history hooked me as I kept digging deeper. Chess was one of the first fields where a machine passed the best humans. As LLMs start doing that in other fields, I think that history is worth knowing. Along the way, the project's own engine (Ratchet) has taken over my time and grown. At v0.3.15, I split it into ratchet (which moves on to NNUE later) and RatchetHCE (hand-crafted evaluation only).
I wanted something other than C++, Rust, and Emscripten like most browser engines I see and settled on AssemblyScript because I am most familiar with reading and debugging TypeScript-like languages. It compiles straight to a 123 KB WebAssembly module with manual typed-array memory and no GC.
UCI over WASI and the Play page
I did not find a standard interface for WebAssembly chess engines, since existing browser builds each ship their own Emscripten glue. I started uci-over-wasi as a baseline idea: a WASI preview-1 command module speaking UCI on stdin and stdout, paired with a small host for browsers, Bun, and Node.
On cross-origin isolated pages, the browser Worker sends mid-search stop over a SharedArrayBuffer ring. On plain static hosting without COOP/COEP headers, it falls back to JSPI so single-threaded modules still handle stop and go infinite. The Play site at ratchetchess.com uses a small service worker to add COOP/COEP headers so wasi-threads modules can also use multiple threads on GitHub Pages.
Using this interface, I adapted 17 open-source engines to prove it out and run on the Play page alongside RatchetHCE: Stockfish 10, Stockfish 11, Viridithas 20.0.0, Marvin 6.3.0, Mantissa 3.7.2, Simbelmyne 1.10, Clovis III, Zurichess Neuchatel, and nine Stash versions (9.0.1 through 37.0). The Engines page also has a drag-and-drop WASI checker if you want to toy with it and verify your own .wasm build in the browser.
WebAssembly vs. native quirks and limits
RatchetHCE is written for browser limits from the start. Every target: Chrome, Firefox, Bun, Node, and the wasm2c native executables, run the same WASI build and produce the same node signature.
- Bitboards Native: 64-bit ints, POPCNT, TZCNT, LZCNT. WASM: Core WASM has i64, popcnt, ctz, and clz.
- Sliding attacks Native: BMI2 PEXT / PDEP. WASM: Not available; uses magic bitboards.
- SIMD Native: AVX2 / AVX-512 / VNNI. WASM: Fixed-width simd128 only. No relaxed SIMD, keeping node counts deterministic across CPUs.
- Memory Native: 64-bit, prefetch, large pages, NUMA. WASM: 32-bit linear memory (4 GiB ceiling, ~3.8 GiB in Chrome/Firefox), never shrinks, no prefetch. Hash caps at 1024 MB.
- Threads Native: Lazy SMP. WASM: uci-over-wasi supports wasi-threads for adapted engines, RatchetHCE stays single-threaded.
- Files & clocks Native: Local books, Syzygy, high-res clock. WASM: No filesystem; the GUI handles books and adjudication. Browser clocks step at 5 us (Chrome) or 20 us (Firefox).
This engine is heavily developed with AI coding agents under my direction. Because language models are trained on public chess code and literature, every feature requires reviewing the Chess Programming Wiki and other engines first so forms that may be model-internal still get explicit citations. Every function comment names the form followed and rejected, mapped to exact commits in engines/ratchet/SOURCES.md and indexed by feature in engines/ratchet/FEATURES.md.
Move similarity is checked across 34 engines over 8,238 positions (100 ms, 2 passes, Hash 16) in results/similarity.md: RatchetHCE 0.4.0 repeats itself on 95.0% of positions and peaks at 54.1% agreement (ethereal-0e47e9b, then 53.3% ethereal-12.75, 52.6% clockwork-20260705 and lynx-dc203270, 52.5% weiss-c735b8f, 52.1% stash-0016be8 and stockfish-9587eeeb), in line with independent strong HCE peers (51-54%) and well below same-lineage pairs (57-63%) and NNUE peers (57-61%) in the same pool. Tool credits are in README.md.
Datasets
The eval is tuned by Texel's method, by Peter Österlund. The v0.4.0 eval was refit on ~2.75M positions:
- 2.00M self-play at ~25k npm, with Stefan Pohl's UHO_Lichess openings.
- 742k Clockwork's v5_25knpm (https://data.cwchess.org/), ODbL.
Builds and relative speeds
For desktop GUIs and rating lists, use the wasm2c native binaries (ratchetHCE-0.4.0-<os>-x86-64 or -x86-64-v3 for AVX2/BMI2, plus ratchetHCE-0.4.0-macos-arm64 for Apple Silicon). These translate the WASI build to C via WABT's wasm2c + SIMDe and compile statically with gcc/clang, with no runtime or DLL dependencies. Releases also include the bare .wasm, browser Worker .js, THIRD-PARTY-NOTICES.txt, and SHA256SUMS.
Every packaged file is verified against the v0.4.0 release node signature: 15048273 nodes at bench depth 12.
Quiet desktop (Ryzen 9 5950X, bench depth 12, 15048273 nodes, median of 3 passes):
Code: Select all
Build / Runtime knodes/s vs Bun WASI Notes
--------------------------------------------------------------------------------------------------------
Native (wasm2c + gcc, x86-64-v3) 2504 1.13x Recommended for GUIs (AVX2/BMI2)
Native (wasm2c + gcc, x86-64) 2266 1.02x Baseline x86-64
Node 26.12.1 (V8, WASI) 2262 1.02x Direct bench/search.ts: 2322 knodes/s
Bun 1.4.4 (JSC, WASI) 2218 1.00x Reference for internal ratings, direct: 2257
Code: Select all
Runtime knodes/s vs Bun Cold knodes/s
-------------------------------------------------------
Chrome 156 (V8) 1446 1.001x 1434
Bun 1.4.2 (JSC) 1445 1.000x 1437
Node 24.21.0 (V8) 1441 0.997x 1441
Firefox 159 (SM) 1414 0.979x 1387
Matches run on a local Linux cluster (ratchet-bench driving fastchess). Testing uses node-clock SPRTs, wall-clock confirmations, SPSA tunes, and Bun/Node speed reads depending on the change.
Internal ratings play the WASI build under Bun (closest to the browser target), calibrated against CCRL Blitz anchors at 53+0.44, Hash 128, 8moves_v3, draw adjudication, no resign, 6-piece Syzygy, on a 5950X. Because the wasm2c native binary is ~13% faster than Bun (x86-64-v3), expect it to play slightly stronger on the clock than the Bun numbers below.
Code: Select all
Version CCRL Blitz fit (Bun) Games Notes
-----------------------------------------------------------------------------------------------------------
v0.1.0 2955 +/- 26 500 Initial rated cut
v0.2.0 3208 +/- 21 700
v0.3.0 3351 +/- 19 700
v0.3.15 3470 +/- 14 800 Pre-split baseline
v0.4.0 3492 +/- 9 1400 simd128 + speed pass, 21-bit TT, 2.75M Texel + eval/scaling, SPSA,
7 placed latest commit HCE anchors