Chess::Piece::Pawn - a class representing a pawn in a chess game


Chess documentation  | view source Contained in the Chess distribution.

Index


NAME

Top

Chess::Piece::Pawn - a class representing a pawn in a chess game

SYNOPSIS

Top

    $pawn = Chess::Piece::Pawn->new("e2", "White King's pawn");
    $true = $pawn->can_reach("e4");
    $true = $pawn->can_reach("e3");
    $true = $pawn->can_reach("f3");
    $false = $pawn->can_reach("e5");
    $queen = $pawn->promote("queen");

DESCRIPTION

Top

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

METHODS

Top

Construction

new()

Constructs a new Chess::Piece::Pawn. Requires a two scalar parameters containing the square on which the pawn is to be constucted and its color, Optionally takes a third parameter containing a text description of the pawn.

    $pawn = Chess::Piece::Pawn->new("d2", "white");
    $pawn = Chess::Piece::Pawn->new("e2", "white", 
                                    "White King's pawn");

Class methods

There are no class methods for this class.

Object methods

reachable_squares()

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.

promote()

Takes a parameter containing the type of piece to promote to. Returns itself blessed as that type of piece. Returns undef and produces a warning (see "DIAGNOSTICS" if the piece is not one of 'bishop', 'knight', 'queen' or 'rook'.

DIAGNOSTICS

Top

Can't promote a pawn to a 'king'

You may only promote a pawn to a 'bishop', 'knight', 'queen' or 'rook'.

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.