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:
| Phase | Meaning |
|---|---|
'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
- Two passes in a row move the game to
'scoring'. From then ongame.scoreholds the count, assuming every group is alive. - 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. - 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:
| Field | What it is |
|---|---|
result | As SGF writes it: 'B+3.5', 'W+0.5', '0' for a draw, or 'B+R' / 'W+R' after a resignation |
black, white | Points for each side, with komi included for White. null after a resignation. |
territory | The points each side's territory covers |
dame | Empty points counted for neither side |
groups | Every 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 resignedChange 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.