The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

    $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

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

Construction

new()

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

can_reach()

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.

checkmated()

Takes no parameters. Returns true if the checkmated flag has been set for this king (as determined by "set_checkmated()".

set_checkmated()

Takes a single scalar parameter containing a boolean value. Sets the checkmated property of this king to that value.

DIAGNOSTICS

"King cannot be captured. Use set_checkmated() instead"

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()".

"Invalid Chess::Piece::King reference"

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

Please report any bugs to the author.

AUTHOR

Brian Richardson <bjr@cpan.org>

COPYRIGHT

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.

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 33:

'=item' outside of any '=over'

Around line 39:

You forgot a '=back' before '=head2'

Around line 45:

'=item' outside of any '=over'

Around line 61:

You forgot a '=back' before '=head1'

Around line 63:

'=item' outside of any '=over'

Around line 76:

You forgot a '=back' before '=head1'