NAME
Chess::Rep::Coverage - Expose chess ply potential energy
SYNOPSIS
use Chess::Rep::Coverage;
my $g = Chess::Rep::Coverage->new();
print $g->board();
$g->set_from_fen('8/8/8/3pr3/4P3/8/8/8 w ---- - 0 1');
$c = $g->coverage(); # Recalculate board status
print $g->board();
DESCRIPTION
This module exposes the "potential energy" of a chess ply by returning a hash reference of the board positions, pieces and their "attack or protection status."
METHODS
new()
Return a new Chess::Coverage
object.
coverage()
$c = $gcoverage();
Set the cover
attribute and return a data structure, keyed on board position, showing
occupant => Human readable piece name
color => Color number of the occupant
index => The C<Chess::Rep/Position> board position index
move => List of positions that are legal moves by this piece
protects => List of positions that are protected by this piece
threatens => List of positions that are threatened by this piece
is_protected_by => List of positions that protect this piece
is_threatened_by => List of positions that threaten this piece
white_can_move_here => List of white piece positions that can move to this position
black_can_move_here => List of black piece positions that can move to this position
board()
print $self->board();
Return an ASCII board layout with threats, protections and move statuses.
Protection and threat is indicated by p/t
. White and black movement is indicated by w:b
.
For example, the FEN 8/8/8/3pr3/4P3/8/8/8 w ---- - 0 1
is rendered as:
A B C D E F G H
+-----+-----+-----+-----+-----+-----+-----+-----+
1 | | | | | | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
2 | | | | | | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
3 | | | | | | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
4 | | | | 0:1 | 0/2 | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
5 | | | | 1/1 | 0/0 | 0:1 | 0:1 | 0:1 |
+-----+-----+-----+-----+-----+-----+-----+-----+
6 | | | | | 0:1 | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
7 | | | | | 0:1 | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
8 | | | | | 0:1 | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+
This means that, 1) the black pawn at D5 can move to D4 and can capture the white pawn at E4; 2) the white pawn at E4 can capture the pawn at D5 but cannot move; 3) the black rook at E5 protects the black pawn at D5, can capture the white pawn at E4 and can move to F5 through H5 or E6 through E8.
SEE ALSO
* The code in the t/
directory.