Board class

Represents a Go board state and operations.

The board is stored as a 2D list state[y][x] where null means empty, and Stone.black/Stone.white represent stones.

Note:

  • The constructor does not defensively copy the provided state. If the caller mutates it afterwards, this Board will observe the change.
  • set and clear mutate this instance. makeMove returns a cloned board with the move applied and does not mutate this instance.

Constructors

Board(List<List<Stone?>> state, {Map<Stone, int>? captures, KoInfo? koInfo})
Creates a board from an existing state.
Board.fromDimension(int width, [int? height])
Creates an empty board of size width×height (square if height omitted).

Properties

hashCode int
The hash code for this object.
no setterinherited
height int
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state List<List<Stone?>>
Two-dimensional board state state[y][x]. null represents an empty point.
getter/setter pair
width int
no setter

Methods

clear() → void
Resets the board to an empty state (keeps dimensions).
clone() Board
Returns a deep copy of this board.
copyWith({List<List<Stone?>>? state, Map<Stone, int>? captures, KoInfo? koInfo}) Board
Returns a new Board with optionally replaced state, captures, or koInfo.
diff(Board board) List<Vertex>?
Returns the list of coordinates that differ from board, or null if sizes differ.
get(Vertex vertex) Stone?
Returns the stone at vertex, or null if empty or out of board.
getCaptures(Stone player) int
Returns the number of stones captured by player.
getChain(Vertex vertex) List<Vertex>
Returns the connected component (chain) of same-colored stones containing vertex. If vertex is empty or out of board, returns an empty list.
getConnectedComponent(Vertex vertex, bool predicate(Vertex vertex), [List<Vertex>? result]) List<Vertex>
Collects a connected component via predicate starting at vertex. Returns an empty list if vertex is out of board.
getDistance(Vertex v1, Vertex v2) int
Manhattan distance between v1 and v2.
getHandicapPlacement(int count, {bool tygem = false}) List<Vertex>
Returns candidate handicap placements.
getLiberties(Vertex vertex) List<Vertex>
Returns the unique liberties (adjacent empty points) of the chain at vertex. Returns an empty list for out-of-board or empty vertex.
getNeighbors(Vertex vertex) List<Vertex>
Returns orthogonal neighbors (up, down, left, right) on the board. Returns an empty list if vertex is out of board.
getRelatedChains(Vertex vertex) List<Vertex>
Returns all stones of the same color as vertex that are reachable through paths consisting of same-colored stones and empty points. Returns an empty list for out-of-board or empty vertex.
has(Vertex vertex) bool
Returns whether vertex lies on the board (0 ≤ x < width and 0 ≤ y < height).
hasLiberties(Vertex vertex, [Map<Vertex, bool>? visited]) bool
Returns whether the chain at vertex has at least one liberty. Returns false for out-of-board or empty vertex.
isEmpty() bool
isSquare() bool
isValid() bool
Returns true if every chain on the board has at least one liberty.
makeMove(Vertex vertex, Stone stone, {bool preventOutOfBoard = false, bool preventSuicide = false, bool preventOverwrite = false, bool preventKo = false}) Board
Returns a new Board with stone played at vertex.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseVertex(String coord) Vertex?
Parses a Go coordinate string like "D16" to a Vertex. Returns null if invalid or out of board.
set(Vertex vertex, Stone? stone) Board
Sets stone at vertex. Use null to clear a point.
setCaptures(Stone stone, int value) Board
Sets the capture count for stone to value. Returns this for chaining.
stringifyVertex(Vertex vertex) String
Converts vertex to a Go coordinate string like "D16". Returns an empty string if vertex is out of board.
toString() String
Returns a human-readable textual representation of the board.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

alpha → const String
Column labels used by string conversions (letter I is skipped).