A Go board
for any web page.
Play games, review them, and open and save SGF files. No dependencies, no build step, rules checked against proofs in Lean.
Play games, review them, and open and save SGF files. No dependencies, no build step, rules checked against proofs in Lean.
Every button below drives the real library on the board. What the library hands back shows up underneath it.
Click to play. Turns, captures and ko are handled for you.
Every move returns a new game, so undo and history come free.
Photographed wood in Canvas 2D, or a path-traced room.
Two passes start the count. Click a group to mark it dead.
A move tree, marks and comments, saved back as SGF.
Proved in Lean and model-checked in TLA+.
One import. No framework, no build step.
The same rules in Node, workers and servers.
No browser and no DOM: the same rules the board uses, checking moves on a server.
// server.mjs
import { newGame, play, saveSgf } from '@kiranpg/goban';
let game = newGame({ size: 9 });
for (const point of [{ x: 2, y: 2 }, { x: 6, y: 6 }, { x: 2, y: 6 }]) {
game = play(game, point).game;
}
const again = play(game, { x: 2, y: 2 });
console.log(again.error.code); // why the move was refused
console.log(saveSgf(game)); // store it, send it, open it laterThe claim: however a game goes, the board never shows a group of stones with no empty point next to it. A group like that has been captured, so it must come off.
How it’s checked: not by trying games. The proof shows it’s true on an empty board and that every legal move keeps it true, so it holds for every game on every board size.
-- Any board you can reach by playing
-- has no group without an empty neighbour.
theorem reachable_all_have_liberties {size : Nat} {b : Board}
(h : Reachable size b) : AllHaveLiberties b.size b.cells := by
induction h with
| start => … -- true on the empty board
| @step b b' a _ ha ih => -- and each legal move keeps it true:
cases a with
| pass => … -- a pass moves no stones
| play p => exact accepted_all_have_liberties b b' p ha ihThe claim: keeping an old copy of a game and playing on from it never breaks anything. Every move you had is still there, and every move ID still points to the same move.
How it’s checked: a model checker tries every order of moves, passes and jumps back by two players sharing games on a small board, checking the claim after each step.
\* At every step, each player holding a game either took
\* another player's copy, or has a game that starts with
\* everything their old one had.
ValuesKeepMoves ==
[][\A h \in Holders :
ForkedTo(h) \/
/\ Len(val'[h].record) >= Len(val[h].record)
/\ SubSeq(val'[h].record, 1, Len(val[h].record))
= val[h].record]_vars// Pick an action on the left, or click the board.