Skip to content

Generated Wasm bindings

This directory contains browser-loadable files generated from the Rust engine. These files are build artifacts, but they are committed because GitHub Pages serves static files and the game must work without a backend.

Files

gomoku_ai.js              # wasm-bindgen JavaScript glue loaded by Workers
gomoku_ai_bg.wasm         # compiled Rust/Wasm engine
gomoku_ai.d.ts            # TypeScript declaration for the JS glue
gomoku_ai_bg.wasm.d.ts    # TypeScript declaration for the Wasm module

What these files do

gomoku_ai_bg.wasm contains the compiled Rust search engine. It includes board parsing, Bitboard win detection, candidate generation, evaluation, NegaMax search, Alpha-Beta pruning, and JSON result encoding.

gomoku_ai.js is generated by wasm-bindgen. It loads the .wasm file, prepares JavaScript-to-Wasm value conversion, and exposes the Rust function search_best_move().

The .d.ts files describe the generated API for editors and TypeScript-aware tools. The browser game does not need TypeScript to run.

Why these files should not be edited by hand

The source of truth is rust-ai/src/. Manual edits to generated Wasm output will be lost the next time the engine is built. If the AI behavior needs to change, edit Rust, rebuild, and commit the regenerated files.

Build command

Run this from rust-ai/:

cargo build --target wasm32-unknown-unknown --release
wasm-bindgen --target web --out-dir ../assets/wasm --out-name gomoku_ai target/wasm32-unknown-unknown/release/gomoku_ai.wasm

Runtime input and output

ai-worker.js imports gomoku_ai.js and calls:

search_best_move(cells, isBlackTurn, thinkTimeMs, legalMoves)

Input:

cells        # Int8Array-compatible board values: 1 black, -1 white, 0 empty
isBlackTurn  # true for black, false for white
thinkTimeMs  # search budget
legalMoves   # optional root shard, encoded as row * 15 + col

Output:

JSON string with r, c, score, depth, nodes, timeMs, nps, and heatmap

How to judge normal behavior

The browser should be able to load assets/wasm/gomoku_ai.js from a Worker. A successful AI move should return a board coordinate and nonzero search telemetry. If the Worker reports that Wasm was not initialized, check that the page is served over HTTP and that both gomoku_ai.js and gomoku_ai_bg.wasm exist.