Simple Monte Carlo functions to determine dead stones on a Go board.
Use npm to install:
$ npm install @sabaki/deadstones
To use this module, require it as follows:
const deadstones = require('@sabaki/deadstones');
Make sure you have the Rust toolchain installed via rustup
. This project uses nightly Rust and the native WASM target which you can acquire with:
$ rustup default nightly
$ rustup target add wasm32-unknown-unknown
This project uses wasm-bindgen
which you can install via Cargo:
$ cargo install wasm-bindgen-cli
To build WASM binaries and to start tests, use the following commands:
$ npm run build
$ npm test
The board arrangement is represented by an array of arrays. Each of those subarrays represent one row, all containing the same number of integers. -1
denotes a white stone, 1
a black stone, and 0
represents an empty vertex
[[ 0, 0, 1, 0, -1, -1, 1, 0, 0],
[ 1, 0, 1, -1, -1, 1, 1, 1, 0],
[ 0, 0, 1, -1, 0, 1, -1, -1, 0],
[ 1, 1, 1, -1, -1, -1, 1, -1, 0],
[ 1, -1, 1, 1, -1, 1, 1, 1, 0],
[-1, -1, -1, -1, -1, 1, 0, 0, 0],
[ 0, -1, -1, 0, -1, 1, 1, 1, 1],
[ 0, 0, 0, 0, 0, -1, -1, -1, 1],
[ 0, 0, 0, 0, 0, 0, 0, -1, 0]]
Board positions are represented by an array of the form [x, y]
where x
and y
are positive integers, zero-based coordinates of the vertex. [0, 0]
denotes the top left position of the board.
This module exposes four functions:
data
- Board dataoptions
<Object>
(optional)-
finished
<boolean>
(optional) - Default:false
If set
true
, deadstones will assume that player areas have been completely surrounded, yielding better results. -
iterations
<integer>
(optional) - Default:100
The number of random playthroughs to make.
-
Returns an array of vertices that Sabaki thinks are dead.
data
- Board dataiterations
<integer>
- The number of random playthroughs to make.
Returns an array of arrays of the same size as data
. Each entry is a number between -1
and 1
and corresponds to a vertex. A number closer to -1
is more likely controlled by white and a number closer to 1
is more likely controlled by black.
data
- Board datasign
-1
|1
- White player corresponds to-1
, black player is represented by1
.
Makes random alternating moves, starting with the player determined by sign, until only eye filling moves can be made. Then all eyes that are left will be filled with the corresponding color. This final board arrangement data will be returned.
data
- Board data
A fast function that returns an array of vertices of stones that are inside enemy territory and do not surround more than one point of territory themselves.