1.3.0 • Published 9 years ago

go-sim v1.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

go-sim npm version

Simulate the game Go in JavaScript.

Installation

npm i go-sim -S

Usage

const goSim = require('go-sim')

// make a new game
// defaults board size to 9x9
const game = goSim()

// make a custom sized game
const largeGame = goSim(50)

// get current game phase ('play', 'mark', or 'end')
game.phase

// get current turn ('black' or 'white')
game.turn

// get current board state
game.board

// get board size
game.board.size

// 1D array of board cells
game.board.cells

// get cell at (row, col)
const cell = game.board.at(2, 3)

// current cell value ('empty', 'black', or 'white')
cell.value

// check if cell has certain value (true or false)
cell.is('empty')

// serialize game into vanilla JavaScript object
const state = game.serialize()

// load the state into the current instance
game.load(state)

// or load a new game from serialized state
const newGame = goSim(state)

// see what the previous play was
// will have type of 'play' or 'pass'
// if 'play', will also have position last played as [row, col]
game.previousPlay

There are many more undocumented functions, but they will probably be less useful for creating a UI around the simulation.

Phases

Go is played in a series of phases. A new game starts in the Play phase. While in each phase, certain functions will be available.

Play

// play at the designated (row, col)
// the turn automatically advances to the next player
// any invalid move is ignored
game.play(2, 3)

// pass the current turn to the next player
// game advances to the Mark phase on consecutive passes
game.pass()

Mark

// mark the cluster of pieces attached to (row, col) as dead
game.mark(2, 3)

// propose the marked clusters to the next player
// next player may mark/unmark clusters and counter propose
game.propose()

// reject the proposal and return to the Play phase to resolve disputes
game.reject()

// accept the proposal and advance to the End phase
game.accept()

End

// retrieve the final calculated score
// komi is included at 6.5
game.score
1.3.0

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.3

9 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.6.0

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago