NAME

Chess::Rep::Coverage - Expose chess ply potential energy

VERSION

version 0.1103

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');
$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, possible movements, and their attack or protection status.

METHODS

new

Return a new Chess::Coverage object.

coverage

$c = $g->coverage;

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

move_probability

@piece_moves = move_probability(%arguments);

Compute the "likelihood" of moving to a protected or threatened position.

SEE ALSO

The code in this distribution examples/ and t/ directories.

Chess::Rep

http://en.wikipedia.org/wiki/Forsyth-Edwards_Notation

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.