< Computer Go

Representing the Board

One of the first problems that all Go programs must solve is how to store the current state of the game. The simplest representation needs to at least implement:

  • a way to determine whether a given point contains a black piece, a white piece, or is empty
  • a way to place a piece, or remove a piece from a given point
  • a way to store which point (if any) is illegal due to the Ko rule[1]

Sample Code

public class Board {
	public Point koPoint;

	private int boardSize;
	private Color[][] board;

	public Color getColor(Point p) {
		board[p.x][p.y];
	}

	public void setColor(Point p, Color color) {
		board[p.x][p.y] = color;
	}
}

Some programs, like GNU Go, use a one-dimensional array instead of a two-dimensional array. This has several advantages:

  • a point on the board can be represented by a single integer
  • one computation is often sufficient for a 1D-coordinate where two would be required for 2D-coordinates

For more information on this strategy, see Representing the board as a one-dimensional array.

Most programs also store additional information that makes it easier to evaluate board positions; we will cover these strategies in a later section.

Next Section: Recognizing Illegal Moves


Footnotes

[1] For simplicity's sake, our program will assume the Tromp-Taylor Rules, ignoring superko, with the additional stipulation that suicide is illegal.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.