stockfish.wasm
WebAssembly port of the strong chess engine
Stockfish. See it in action
on https://lichess.org/analysis.
Requirements
Uses the latest WebAssembly threading proposal.
- Available as an Origin Trial in Chrome 70.
- Behind a flag since Chrome 70: chrome://flags/#enable-webassembly-threads
- Behind a flag in Firefox Nightly:
javascript.options.shared_memory
in about:config.
See stockfish.js for a more
portable but single-threaded version.
Feature detection:
typeof WebAssembly === 'object' &&
WebAssembly.validate(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)) &&
typeof SharedArrayBuffer === 'function' &&
new WebAssembly.Memory({shared: true, initial: 8, maximum: 8}).buffer instanceof SharedArrayBuffer
Limitations
- Maximum number of threads determined at compile time (currently 8).
- Maximum size of hashtable determined at compile time (currently 16 MB).
- No Syzygy tablebase support.
- Exposed as a global variable in JavaScript (
window.Module
), only one
instance per site.
Building
Assuming em++ is available:
cd src
make ARCH=wasm build
Usage
Requires stockfish.js
, stockfish.wasm
, stockfish.js.mem
and
pthread-main.js
to be served from the same directory.
<script src="stockfish.js"></script>
<script>
Module.addMessageListener(function (line) {
console.log(line);
});
Module.postMessage('uci');
</script>
License
Thanks to the Stockfish team for sharing the engine under the GPL3.