chess_logic v0.1.0 ChessLogic.Game

Documentation for Game.

The main entity,

April 2018, klg

Link to this section Summary

Functions

Set the result to draw

Import pgn into a game

Returns a new game

Play a move. a move looks like “e2e4”

Resign a game

Set result of the game

Export the move list history to pgn string

Link to this section Types

Link to this type error()
error() :: {:error, term()}
Link to this type fen()
fen() :: String.t()
Link to this type move()
move() :: String.t()
Link to this type san()
san() :: String.t()
Link to this type t()
t() :: %ChessLogic.Game{
  current_position: %ChessLogic.Position{fen: term(), position: term()},
  history: [turn()],
  result: String.t(),
  status: atom(),
  winner: String.t()
}
Link to this type turn()
turn() :: %{fen: fen(), move: move(), san: san()}

Link to this section Functions

Link to this function draw(game)
draw(t()) :: {:ok, t()} | error()

Set the result to draw.

Link to this function from_pgn(pgn)
from_pgn(String.t()) :: t()

Import pgn into a game.

Returns a new game.

Examples

iex> alias ChessLogic
iex> game = Game.new()
iex> {:ok, game} = game |> Game.play("e2e4")
iex> {:ok, game} = game |> Game.play("c7c5")
iex> game.current_position.fen
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
Link to this function new(fen)
new(fen()) :: t() | error()
Link to this function play(game, move)
play(t(), move()) :: {:ok, t()} | error()

Play a move. a move looks like “e2e4”.

Link to this function resign(game)
resign(t()) :: {:ok, t()} | error()

Resign a game.

Link to this function set_result(game, result)
set_result(t(), String.t()) :: {:ok, t()} | error()

Set result of the game.

Link to this function to_pgn(game)
to_pgn(t()) :: String.t()

Export the move list history to pgn string.