Welcome to gogame’s documentation!¶
Enums¶
- class Color(value)[source]¶
Specify the color of a vertice
- Bool(color):
Returns False if color is Empty, True otherwise
- Empty¶
The vertice is Empty
- Black¶
The vertice is owned by Black
- White¶
The vertice is owned by White
- Green¶
The vertice is owned by Green
- Blue¶
The vertice is owned by Blue
- Yellow¶
The vertice is owned by Yellow
- Purple¶
The vertice is owned by Purple
- Wall¶
The vertice is occupied by a Wall
Player¶
- def free_vertices
- def get_board_matrix
- def get_territories
- def get_vertices
- def my_territories
- def my_vertices
- def play
- def playable_moves
- def territories
- class Player(name=None, color=None)[source]¶
Represents a go player. This class has to be overridden to implement the
play()method- Parameters:
- get_board_matrix()[source]¶
Returns the current state of the board (0 for empty, 1 for the player, -1 for the opponent)
- Return type:
- abstract play()[source]¶
This method has to be overridden by subclasses It’s called when the player has to play and must return a 2-tuple (x, y) representing a move, or None for skipping the turn
Board¶
- cls Board.circular
- cls Board.from_grid
- def around
- def clear_players
- def clone
- def display
- def get_territory
- def is_playable
- def join
- def matrix
- def next_player
- def play
- def playable_moves
- def prisoners
- def remove_player
- def run_game
- def score
- def skip
- def territories
- def vertices
- def winner
- class Board(*, size=19, show=False)[source]¶
Represents the goban of a game
Note
Board vertices can be accessed through indices:
>>> b = Board() >>> b[0,0] <Color.Empty: 0>
- Parameters:
- classmethod circular(size=19, show=False)[source]¶
A quick way to generate a circular board using walls
- join(player)[source]¶
Links a player to the board for a game
- Parameters:
player (Player) – The player to link
- Raises:
ValueError – There are already two players linked
- matrix()[source]¶
Returns the current state of the board as a numpy matrix to facilitate move calculation
- Returns:
The matrix representing the board
- Return type:
- next_player(player=None)[source]¶
Returns the player who is next in the rotation of the game
- Parameters:
player (Optional[Player]) – The reference player. Default to the player currently playing.
- Raises:
ValueError – The player you gave is not on the board or there is no player on the board
- Returns:
The next player
- Return type:
- play(x, y, *, color)[source]¶
Play a move manually without using Player object
- Parameters:
- Raises:
ValueError – The move is invalid, or it’s the wrong player
- remove_player(player)[source]¶
Unlinks a player from the board
- Parameters:
player (Player) – The player to unlink
- Raises:
ValueError – This player is not linked to the board
- run_game(max_turn=1000, max_duration=None)[source]¶
Runs a game on this board between two players. The players have to be linked to the board with
join()before- Parameters:
- Raises:
ValueError – Not enough players to start the game
TypeError – A player returns an invalid move type
- Returns:
The player who wins the game
- Return type:
- score(color)[source]¶
Returns the score of a player i.e. the number of vertices belonging to the player + the number of his prisoners
- skip(*, color)[source]¶
Skip a turn manually without using Player object
- Parameters:
color (Color) – The color of the move to play
- Raises:
ValueError – It’s the wrong player
- Returns:
True if the game is over because it’s the second skip in a row, False otherwise
- Return type:
- territories(color=None)[source]¶
Returns territories currently on the board. If a color is specified, only territories of the given color are returned
Territory¶
- cls Territory.merge
- def clone
- def freedom
- def includes
- def is_nearby
- def is_touching
- class Territory(*, x=None, y=None, vertices=None, board)[source]¶
Represents a territory i.e. a list of nearby vertices of the same color
Note
When using the x, y initializer, the territory is built by exploring the board while with vertices it only uses the given vertices without any exploration
- Parameters:
x (Optional[int]) – The x coordinate of the vertice to use to initiate the territory. This cannot be mixed with the vertices parameter
y (Optional[int]) – The y coordinate of the vertice to use to initiate the territory. This cannot be mixed with the vertices parameter
vertices (Optional[list[tuple[int, int]]]) – A list of vertices to initiate the territory. This cannot be mixed with the x and y parameters
board (Board) – The board associated with the territory
- Raises:
TypeError – Parameters are not of the right type
ValueError – Failed to create the territory with the given parameters
- classmethod merge(*territories, with_vertice=None)[source]¶
Merge several connected territories into one
- Parameters:
- Raises:
TypeError – Parameters aren’t of the right type
ValueError – Failed to merge territories
- Returns:
The new territory
- Return type: