ExChess.Fen (ExChess v0.1.0)

View Source

The functions in this module are used to parse game state to and from Forsyth-Edwards Notation.

Summary

Types

t()

The FEN string.

Functions

Returns a parsed FEN representation of the board.

Returns a parsed FEN representation of the entire game state, except for repetition history which is not captured in FEN.

Returns a ExChess.Board parsed from the board_fen string.

Returns a ExChess.Game struct parsed from the fen string.

Types

t()

@type t() :: binary()

The FEN string.

Functions

from_board(board)

@spec from_board(ExChess.Board.t()) :: binary()

Returns a parsed FEN representation of the board.

Examples

iex> ExChess.Board.new()
...> |> ExChess.Fen.from_board()
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"

from_game(game)

@spec from_game(ExChess.Game.t()) :: t()

Returns a parsed FEN representation of the entire game state, except for repetition history which is not captured in FEN.

Examples

iex> ExChess.start_game()
...> |> ExChess.Fen.from_game()
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"

to_board(board_fen)

Returns a ExChess.Board parsed from the board_fen string.

Examples

iex> ExChess.Fen.to_board("k7/8/8/8/8/8/8/K7")
%{%ExChess.Square{file: 0, rank: 0} => %ExChess.Piece{type: :k, color: :white}, %ExChess.Square{file: 0, rank: 7} => %ExChess.Piece{type: :k, color: :black}}

to_game(fen)

@spec to_game(t()) :: ExChess.Game.t()

Returns a ExChess.Game struct parsed from the fen string.

Examples

iex> ExChess.Fen.to_game("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
...> |> ExChess.Visualization.game()
"STATUS: * | FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"