ExChess.Fen (ExChess v0.1.0)
View SourceThe functions in this module are used to parse game state to and from Forsyth-Edwards Notation.
Summary
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
@type t() :: binary()
The FEN string.
Functions
@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"
@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"
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}}
@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"