
Chess::Piece::King - an object representation of a king in a game of chess

$king = Chess::Piece::King->new("e1", "white", "White King");
$true = $king->can_reach("d1");
$true = $king->can_reach("f1");
$true = $king->can_reach("d2");
$true = $king->can_reach("e2");
$true = $king->can_reach("f2");
$true = $king->can_reach("g1"); # O-O
$king->set_moved(1);
$false = $king->can_reach("g1");
$false = $king->can_reach("d4");
$king->set_captured(1); # dies with message
$king->set_checkmated(1); # use this instead
if ($king->checkmated()) {
# game over...
}

The Chess module provides a framework for writing chess programs with Perl. This class forms part of that framework, representing a bishop in a Chess::Game.

Constructs a new Chess::Piece::King. Requires two scalar parameters containing the initial square and color of the piece. Optionally takes a third parameter containing a description of the piece.
There are no class methods for this class.
Overrides base class version. Returns a list of squares that this pawn can reach from its current position. See "reachable_squares()" in Chess::Piece for more details on this method.
Takes no parameters. Returns true if the checkmated flag has been set for this king (as determined by "set_checkmated()".
Takes a single scalar parameter containing a boolean value. Sets the checkmated property of this king to that value.

The program contains a call to Chess::Piece::King::set_captured. This method has been overridden to croak, as the rules don't allow for capturing the king. See "set_checkmated()".
The program contains a reference to a Chess::Piece::King that was not obtained through "new()" or "clone()" in Chess::Piece. Ensure that the program obtains the reference correctly, and that it does not refer to an undefined value.

Please report any 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.