Skip to content

Scoring ​

A game ends in one of two ways: both players pass and agree on the count, or one player resigns.

The phases ​

game.phase says where a game is:

PhaseMeaning
'playing'Moves are being played.
'scoring'Both players passed in a row. Groups are being marked and moves wait.
'over'The game ended: a score was accepted, a player resigned, or a file recorded a result.

Count a finished game ​

  1. Two passes in a row move the game to 'scoring'. From then on game.score holds the count, assuming every group is alive.
  2. Mark dead groups with markGroup. It sets the status of the whole group at a point to 'alive', 'dead', or 'seki', and the count updates.
  3. Accept with acceptScore. The game is now 'over', and the result is recorded in the SGF.
js
import { acceptScore, markGroup, pass } from '@kiranpg/goban';

let game = pass(pass(board.state).game).game;  // game.phase === 'scoring'

game = markGroup(game, { x: 6, y: 6 }, 'dead').game;
console.log(game.score.result);                // for example 'B+74.5'

game = acceptScore(game).game;                 // game.phase === 'over'

On the board, clicking a group while scoring cycles its status: alive, dead, seki, then alive again. markGroup on an empty point is refused with not-a-group.

Rules ​

  • Japanese rules ('japanese') count territory and prisoners. Komi defaults to 6.5.
  • Chinese rules ('chinese') count area: stones and territory. Komi defaults to 7.5.

Under Japanese rules, empty points next to a seki group count for neither side.

The score ​

game.score is a Score:

FieldWhat it is
resultAs SGF writes it: 'B+3.5', 'W+0.5', '0' for a draw, or 'B+R' / 'W+R' after a resignation
black, whitePoints for each side, with komi included for White. null after a resignation.
territoryThe points each side's territory covers
dameEmpty points counted for neither side
groupsEvery group on the board, with its colour and status

Resign ​

resign ends the game at once. The player to move resigns, so the result goes to the other side:

js
import { resign } from '@kiranpg/goban';

const result = resign(game);  // result.game.score.result === 'W+R' if Black resigned

Change your mind ​

resumePlay steps back:

  • From an accepted score, it returns to 'scoring', so groups can be marked again.
  • From a resignation, it takes the resignation back.
  • While scoring, it returns to 'playing', to play on after both passes.

Ending a game, with acceptScore or resign, works only at the latest move of the main line, in either mode.

Released under the MIT License.