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


Chess documentation  | view source Contained in the Chess distribution.

Index


NAME

Top

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

SYNOPSIS

Top

    $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...
    }

DESCRIPTION

Top

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.

METHODS

Top

Construction

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.

Class methods

There are no class methods for this class.

Object methods

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.

DIAGNOSTICS

Top

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.

BUGS

Top

Please report any bugs to the author.

AUTHOR

Top

Brian Richardson <bjr@cpan.org>

COPYRIGHT

Top


Chess documentation  | view source Contained in the Chess distribution.