if (scalar @pvs == 0 || !defined($pvs[0])) {
return ();
}
+
+ my @nb = @$board;
my $pv = shift @pvs;
my $from_col = ord(substr($pv, 0, 1)) - ord('a');
# white short castling
if ($pv eq 'e1g1' && $piece eq 'K') {
- my @nb = @$board;
-
# king
substr($nb[7], 4, 1, '-');
substr($nb[7], 6, 1, $piece);
# white long castling
if ($pv eq 'e1c1' && $piece eq 'K') {
- my @nb = @$board;
-
# king
substr($nb[7], 4, 1, '-');
substr($nb[7], 2, 1, $piece);
# black short castling
if ($pv eq 'e8g8' && $piece eq 'k') {
- my @nb = @$board;
-
# king
substr($nb[0], 4, 1, '-');
substr($nb[0], 6, 1, $piece);
# black long castling
if ($pv eq 'e8c8' && $piece eq 'k') {
- my @nb = @$board;
-
# king
substr($nb[0], 4, 1, '-');
substr($nb[0], 2, 1, $piece);
# check if the from-piece is a pawn
if (lc($piece) eq 'p') {
# attack?
- if (substr($board->[$to_row], $to_col, 1) ne '-') {
+ if ($from_col != $to_col) {
$pretty = substr($pv, 0, 1) . 'x' . substr($pv, 2, 2);
+
+ # en passant?
+ if (substr($board->[$to_row], $to_col, 1) eq '-') {
+ if ($piece eq 'p') {
+ substr($nb[$to_row + 1], $to_col, 1, '-');
+ } else {
+ substr($nb[$to_row - 1], $to_col, 1, '-');
+ }
+ }
} else {
$pretty = substr($pv, 2, 2);
}
# update the board
- my @nb = @$board;
substr($nb[$from_row], $from_col, 1, '-');
substr($nb[$to_row], $to_col, 1, $piece);