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

weiqi

v1.0.0

Published

An implementation of the ancient Chinese board board Go (Chinese: wéiqí, Korean: baduk, Japanese: igo)

Downloads

18

Readme

weiqi.js Build Status

weiqi.js is an implementation of the board game Go. It provides mechanisms for representing a board with black and white stones, as well as the logic to actually play a game. The objects used in weiqi.js are persistent--methods often return entirely new instances instead of mutating internal state.

Persistence and structural sharing offer a memory-efficient way to represent multiple states of the board simutaneously, a desirable trait for applications where you'd like to explore the history of the game (such as for review) or to explore possible future responses (such as for AI decision-making).

The library is available as an npm package, and can be used in the browser with tools like browserify. If you don't want to use browserify, there is a pre-built file in the dist-browser directory that you can include in your browser-targeted projects right away. Access Weiqi with the global Weiqi variable in this case.

Usage

Creating a game

var Weiqi = require('weiqi');
var game = Weiqi.createGame(9);  // creates a game on a 9 x 9 board
game = Weiqi.createGame(13);  // creates a game on a 13 x 13 board
game = Weiqi.createGame(19);  // creates a game on a 19 x 19 board

Playing a game

var Weiqi = require('weiqi');
var game = Weiqi.createGame(9);
game = Weiqi.play(game, 'black', [2,2]);
game = Weiqi.play(game, 'white', [6,7]);
game = Weiqi.pass(game, 'black'); // black passes
game = Weiqi.pass(game, 'white'); // white passes

Weiqi.play and Weiqi.pass each take a player identifier ('black' or 'white'). Weiqi.play takes an additional zero-indexed array of size two that indicates the position to place a stone. Weiqi.play will raise exceptions for the following situations:

  • the game is already over (there have already been two consecutive passes)
  • it is not currently the turn of the player who is attempting to play
  • the move violates positional superko (at the end of any turn, the board cannot be in a state in which it has been previously).

Querying the game

get('currentPlayer') returns either 'black' or 'white'.

> var Weiqi = require('weiqi');
> var game = Weiqi.play(Weiqi.createGame(9), 'black', [2,2]);
> game.get('currentPlayer');
"o"

isOver returns true iff there have been two consecutive passes.

> var Weiqi = require('weiqi');
> var game = Weiqi.play(Weiqi.createGame(9), 'black', [2,2]);
> Weiqi.isOver(game);
false
> game = Weiqi.pass(game, 'white');
> Weiqi.isOver(game);
false
> game = Weiqi.pass(game, 'black');
> Weiqi.isOver(game);
true

To compute the score of the game (using area score) pass a value of komi to areaScore(). All stones are considered alive.

Weiqi.areaScore(game, 7.5);  // compute area score given 7.5 komi