The boards module

The gomill.boards module contains Gomill’s Go board representation.

Everything in this module works with boards of arbitrarily large sizes.

The implementation is not designed for speed (even as Python code goes), and is certainly not appropriate for implementing a playing engine.

The module contains a single class:

class gomill.boards.Board(side)[source]

A Board object represents a legal position on a Go board.

Instantiate with the board size, as an int >= 1. Only square boards are supported. The board is initially empty.

Board objects do not maintain any history information.

Board objects have the following attributes (which should be treated as read-only):

side

The board size.

board_points

A list of points, giving all points on the board.

The principal Board methods are get() and play(). Their row and col parameters should be ints representing coordinates in the system used for a point.

The behaviour of Board methods is unspecified if they are passed out-of-range coordinates.

Board.get(row, col)[source]
Return type:colour or None

Returns the contents of the specified point.

Board.play(row, col, colour)[source]
Return type:move

Places a stone of the specified colour on the specified point.

Raises ValueError if the point isn’t empty.

Carries out any captures which follow from the placement, including self-captures.

This method doesn’t enforce any ko rule.

The return value indicates whether, immediately following this move, any point would be forbidden by the simple ko rule. If so, that point is returned; otherwise the return value is None.

The other Board methods are:

Board.is_empty()[source]
Return type:bool

Returns True if all points on the board are empty.

Board.list_occupied_points()[source]
Return type:list of pairs (colour, point)

Returns a list of all nonempty points, in unspecified order.

Board.area_score()[source]
Return type:int

Calculates the area score of a position, assuming that all stones are alive. The result is the number of points controlled (occupied or surrounded) by Black minus the number of points controlled by White.

Doesn’t take any komi into account.

Board.copy()[source]
Return type:Board

Returns an independent copy of the board.

Board.apply_setup(black_points, white_points, empty_points)[source]
Return type:bool

Adds and/or removes stones on arbitrary points. This is intended to support behaviour like SGF AB/AW/AE properties.

Each parameter is an iterable of points.

This method applies all the specified additions and removals, then removes any groups with no liberties (so the resulting position is always legal).

If the same point is specified in more than one list, the order in which the instructions are applied is undefined.

Returns True if the position was legal as specified.