NAME

Chess - Manipulate and validate a chessboard in Perl

SYNOPSIS

use Chess;

my $board = new Chess::Board;
my $pawn = $board->square(validate_location('e2'));
$pawn->move('e4', TRUE);

DESCRIPTION

This module provides object oriented methods to move pieces around on a chessboard, and optionally validate the resulting positions (eg. is_check()). Currently, it knows about all the rules of chess, and supports validation of en passant captures and all castling rules. This module is in early development, so it doesn't do anything particulary useful yet. Here is a run-down on the more useful routines:

Chess::Board::new()

Creates a new chessboard with all of the pieces in their correct location

Chess::Board::square($x, $y)

Returns the Chess::Piece at location (0-based) ($x, $y), or undef if the square is empty.

Chess::Piece::move($loc, $validate)

Attempts to move the piece to location $loc on the board, validating the legality of the move if $validate is TRUE. If the move results in a capture, the captured piece can be retrieved with Chess::Board::capture.

Chess::Board::rollback

Rolls back the last move that was made on the chessboard

Chess::Board::movelist($colour)

Returns all moves made by $colour

Chess::Board::moveno($colour)

Returns the current move number for $colour

Chess::Validator::line_isopen($loc1, $loc2)

Returns true if the line defined between $loc1 and $loc2 is completely clear

Chess::Validator::is_check($board)

Returns the king which is currently in check on $board, or undef if no one is in check

Chess::Validator::validate_location($algebraic)

Returns ($rank, $file) of the square in $algebraic notation, or undef if the square is not a valid board location

EXPORT

None by default.

Chess::Validator allows the export of line_isopen, is_check and validate_location.

AUTHOR

Brian Richardson <brian@cubik.ca>

SEE ALSO

Meta::Chess, Chess::PGN.