Go v0.4.3 Go.Game View Source

Documentation for Go.Game

This is the main entity since version 0.2.0

It manages the count (komi, captures) and history of turns. It manages superko rule

It delegates rest of play to a current_board

June 2017-2018, hf

Examples

iex> alias Go.Game
iex> game = Game.new
iex> {:ok, game} = game |> Game.add_move({{3, 3}, :black})
iex> {:ok, game} = game |> Game.add_move({{16, 3}, :white})
iex> {:ok, game} = game |> Game.add_move({{3, 16}, :black}) 
iex> {:ok, game} = game |> Game.add_move({{16, 16}, :white})
iex> current_board = game.current_board 
iex> current_board.coordinates[{3, 3}]
:black
iex> current_board.coordinates[{16, 16}]
:white

Link to this section Summary

Functions

Add move to a game.

Imports a game from sgf, does not persists nodes, just moves from main branch! and thus... does not save root node info

Returns a new Game structure from an optional map or struct.

Pass move.

Place one stone on the game.

Remove the stone at the given location.

Reset the game, but keep size and komi

Resign the game, status will change to is_over

Returns the tally of the game

Generate an ascii from current board game.

Returns list from current board game.

Exports a game to sgf, just returns moves played, no properties, comments!

Like pass move, but does not change history state. Useful when parsing faulty variations in KJD.

Link to this section Types

Specs

t() :: %Go.Game{
  black_captures: integer(),
  consecutive_passes: integer(),
  current_board: Go.Board.t(),
  is_over: boolean(),
  komi: float(),
  placements: list(),
  size: integer(),
  turns: [Go.Turn.t()],
  white_captures: integer(),
  winner: Go.Board.color() | :none
}

Link to this section Functions

Specs

add_move(t(), {Go.Board.coordinate(), Go.Board.color()}) ::
  {:ok, t()} | {:error, String.t()}

Add move to a game.

Link to this function

apply_action(state, action)

View Source

Specs

from_sgf(String.t()) :: {:ok, t()} | {:error, term()}

Imports a game from sgf, does not persists nodes, just moves from main branch! and thus... does not save root node info

Returns a new Game structure from an optional map or struct.

Specs

new(nil | map()) :: t()

Specs

pass(t(), Go.Board.color()) :: {:ok, t()} | {:error, String.t()}

Pass move.

Link to this function

place_stone(game, coordinate, color)

View Source

Place one stone on the game.

Link to this function

place_stone(game, coordinate, color, force \\ false)

View Source

Specs

place_stone(t(), Go.Board.coordinate(), Go.Board.color(), boolean()) ::
  {:ok, t()} | {:error, String.t()}
Link to this function

place_stones(game, list, color)

View Source

Specs

place_stones(t(), Go.Board.list_of_coordinates(), Go.Board.color()) ::
  {:ok, t()} | {:error, String.t()}
Link to this function

remove_stone(game, coordinate)

View Source

Specs

remove_stone(t(), Go.Board.coordinate()) :: {:ok, t()}

Remove the stone at the given location.

Link to this function

remove_stones(game, arg2)

View Source

Specs

remove_stones(t(), Go.Board.list_of_coordinates()) :: {:ok, t()}

Specs

reset(t()) :: {:ok, t()}

Reset the game, but keep size and komi

Specs

resign(t(), Go.Board.color()) :: {:ok, t()}

Resign the game, status will change to is_over

Specs

tally(t()) :: map()

Returns the tally of the game

Specs

to_ascii(t()) :: String.t()

Generate an ascii from current board game.

Specs

to_list(t()) :: list()

Returns list from current board game.

Specs

to_sgf(t()) :: String.t()

Exports a game to sgf, just returns moves played, no properties, comments!

Specs

toggle_turn(t()) :: {:ok, t()}

Like pass move, but does not change history state. Useful when parsing faulty variations in KJD.