Skip to content

Add Go (7x7) with ko, suicide rule, and area scoring#16

Merged
cweill merged 1 commit into
mainfrom
feature/go
May 26, 2026
Merged

Add Go (7x7) with ko, suicide rule, and area scoring#16
cweill merged 1 commit into
mainfrom
feature/go

Conversation

@cweill

@cweill cweill commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Go — the project's namesake and most involved game — to the game-agnostic pipeline. 7x7 by default, with a pass action, captures, suicide prohibition, ko, two-pass termination, and Tromp-Taylor area scoring.

Motivation

Go stresses the Game interface in ways no prior game did: a non-spatial pass action (action_size = size² + 1) and history-dependent legality (ko). Implementing it on the same interface — with no changes to MCTS, the network, or training — is the strongest evidence the pipeline is genuinely game-agnostic.

Rule choices (documented in the module)

  • Captures/suicide: place, remove opponent groups with no liberties, then reject the move if the mover's own group has no liberties (suicide illegal).
  • Ko: simple single-point ko, not full positional superko. Full superko needs the whole position history in every state, which would bloat/slow every MCTS node; simple ko keeps GoState small and hashable and covers the common case.
  • End/scoring: two consecutive passes end the game; Tromp-Taylor area scoring with a half-integer komi (default 7.5) so results are always decisive (no draws).
  • Board size and komi are constructor args (default 7x7).

Testing

  • Full suite: 141 passed.
  • tests/test_go.py (12 cases): captures, plain suicide (illegal) vs capturing-suicide (legal), the ko ban + its clearing on a pass, two-pass termination, empty-board komi result, and territory attribution in area scoring.
  • Integration smoke: game_from_name("go")AlphaZeroNet → MCTS yields a valid 50-action policy (including pass).

Review focus

  • The simple-ko vs positional-superko trade-off.
  • Default board size (7x7) and komi (7.5) — reasonable, or prefer different defaults?
  • legal_moves does a place+flood-fill suicide check per empty point (O(points²)); fine at 7x7, a known hot spot if scaled up.

Closes alphago-xdh.

New game module implementing the Game interface for Go: a pass action
(action_size = size^2 + 1), flood-fill captures, a no-suicide legality
rule, simple single-point ko, two-pass termination, and Tromp-Taylor
area scoring with a half-integer komi (so results are always decisive).
Board size and komi are configurable (default 7x7, komi 7.5). Registered
via the central registry.

Simple single-point ko is used instead of full positional superko to keep
GoState small and hashable for MCTS; documented in the module. Tests cover
captures, plain suicide vs capturing-suicide, the ko ban and its clearing,
two-pass termination, and area scoring with komi and territory attribution.

alphago-xdh
@cweill cweill merged commit 08838ca into main May 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant