npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sabaki/deadstones

v2.1.2

Published

Simple Monte Carlo functions to determine dead stones on a Go board.

Downloads

68

Readme

@sabaki/deadstones Build Status

Simple Monte Carlo algorithm to determine dead stones on a Go board.

Installation

Use npm to install:

$ npm install @sabaki/deadstones

To use this module, require it as follows:

const deadstones = require('@sabaki/deadstones')

This module supports fetching the WASM file via fetch on the web if no node environment is found. Use a bundler like webpack and call the following method right after import or require:

deadstones.useFetch('./path/to/deadstones_bg.wasm')

Building

Make sure you have the Rust toolchain installed via rustup. This project uses the native WASM target which you can acquire with:

$ rustup target add wasm32-unknown-unknown

Make sure you have wasm-pack, Node.js 8 or higher, and npm installed. Clone this repository and install its dependencies with npm:

$ git clone https://github.com/SabakiHQ/deadstones
$ cd deadstones
$ npm install

To build WASM binaries and to start tests, use the following commands:

$ npm run build
$ npm test

API

Board Data

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

Example

[[ 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]]

Vertex

Board positions are represented by an array of the form [x, y] where x and y are non-negative integers, zero-based coordinates of the vertex. [0, 0] denotes the top left position of the board.

This module exposes four functions:

async deadstones.guess(data[, options])

  • data - Board data
  • options <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.

async deadstones.getProbabilityMap(data, iterations)

  • data - Board data
  • iterations <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.

async deadstones.playTillEnd(data, sign)

  • data - Board data
  • sign -1 | 1 - White player corresponds to -1, black player is represented by 1.

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.

async deadstones.getFloatingStones(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.