NAME
Board - Chess board class
SYNOPSIS
The below is just a small sample, and far from extensive.
For more elaborate examples, see the prototypes directory in the Git repo.
use Board;
my $board = Board->fromFen($fen);
print $board->ascii();
my $move = $board->parse_move_san('e4');
$board->push_move($move);
$board->pop_move();
DESCRIPTION
Board provides Board objects, with features including
Construction from FEN
FEN output
Generate legal moves
SAN input / output
Making moves to update the board, and going back again ('unmaking' the moves).
Mirror the board vertically.
Other kinds of mirrors and rotation may be added in later versions.
Get other properties of the board position
METHODS
- fromFen($fen)
-
Constructor. Create a Board from a FEN string (Forsyth–Edwards Notation). If the input $fen is empty, use the conventional start position.
- empty()
-
Constructor. Create an empty Board.
- copyOf($board)
-
Copy constructor. Create a Board as a copy of the input Board.
- fen()
-
Get the FEN for this board position.
- errors()
-
Return undef if position is valid. Otherwise, a string describing the error.
- ascii()
-
Write the board as ASCII.
- legal_moves_iter()
-
Get an iterator over the legal moves from this position.
- legal_moves()
-
Get legal moves from this position.
- to_move()
-
Return the side to move.
- parse_san($san)
-
Parse a SAN string with this board as the context. Return the legal move specified by the SAN string, if such a move can be uniquely determined. Croak if no such unique legal move can be determined.
- push_move($move)
-
Update with the given *move* and push it to the move Moves are not checked for legality. It is the caller's responsibility to ensure that the move is at least pseudo-legal or a null move. Null moves just increment the move counters, switch turns and forfeit en passant capturing.
- push_move_san($san)
-
Assuming the input is a valid move in SAN notation, will push the move. Croak if not a valid move. See push_move($move).
- push_move_uci($uci)
-
Assuming the input is a valid move in UCI notation, will push the move. See push_move($move).
- pop_move()
-
Restore previous position and return last move from stack. If move stack is empty, no-op and return undef.
- piece_at($square)
-
Get the piece at given square.
- remove_piece_at($square)
-
Remove the piece at given square. If square is empty, does nothing.
- set_piece_at($square, $piece)
-
Put given piece/pawn on given square. Any existing piece/pawn on that square is removed.
- kingside_castling_right($side)
-
Is kingside castling allowed for the given side?
$side = 'w' or 'b'
- queenside_castling_right($side)
-
Is queenside castling allowed for the given side?
$side = 'w' or 'b'
- ep_square()
-
En passant capture square, or undef if N/A
- fullmove_number()
-
Counts move pairs. Starts at 1, increments after every Black move.
- halfmove_clock()
-
Number of ply since last capture or pawn move.
- apply_mirror()
-
Mirror this board vertically.
- san($move)
-
Get the Standard Algebraic Notation of the given move in the context of this position.
- ply()
-
Get number of half-moves since start of game.
AUTHOR
Ejner Borgbjerg
LICENSE
Perl Artistic License, GPL