Chess::Game
Chess::Game - a class to record and validate the moves of a game of chess
use Chess::Game;
$game = Chess::Game->new();
$clone = $game->clone();
$move = $game->make_move("e2", "e4");
$move_c = $clone->make_move("e2", "e4");
$true = ($move->get_piece() ne $move_c->get_piece());
$move = $game->delete_move();
...
while (!defined($result = $game->result())) {
# get a move
$move = $game->make_move($sq1, $sq2);
if (!defined($move)) {
print $game->get_message();
}
}
if ($result == 1) {
print "White wins!\n";
}
elsif ($result == 0) {
print "Draw!\n"
}
else {
print "Black wins!\n";
}
The Chess module provides a framework for writing chess programs with Perl. This class forms part of that framework, providing move validation for all moves recorded using the Chess::Game class. The Game contains a Chess::Board, 32 Chess::Pieces and a Chess::Game::MoveList that contains a series of Chess::Game::MoveListEntrys that record the exact state of the game as it progresses. Moves can be taken back one-at-a-time to allow for simple movelist manipulation.
Takes two optional parameters containing optional names for the players. If none are provided, the player names 'white' and 'black' are used. Creates a new Chess::Board and places 16 Chess::Pieces per player and initializes an empty Chess::Game::MoveList.
There are no class methods for this class.
undef as long as the game is in progress. When
a conclusion has been reached, returns 1 if the first player checkmated the
second player, 0 if either player has been stalemated, or -1 if the second
player checkmated the first player. Is not currently able to determine if the
game was drawn by a three-fold repetition of positions.
Takes one parameters. If the last move was a promotion (as determined by a call to Chess::Game::MoveListEntry/"is_promotion()", then calling this function will change the newly promoted pawn to the piece specified by the provided parameter. Valid values are (case-insensitive) "bishop", "knight", "queen" and "rook".
The framework is not currently able to determine when a game has been drawn by three-fold repetition of position. Please report any other bugs to the author.
Brian Richardson <bjr@cpan.org>
Copyright (c) 2002, 2005 Brian Richardson. All rights reserved. This module is Free Software. It may be modified and redistributed under the same terms as Perl itself.