# en passant?
if ($board->[$to_row][$to_col] eq '-') {
if ($piece eq 'p') {
- $nb->[$to_row + 1][$to_col] = '-';
- } else {
$nb->[$to_row - 1][$to_col] = '-';
- }
- }
- } else {
- if (defined($promo) && $promo ne '') {
- if ($piece eq 'p') {
- $piece = $promo;
} else {
- $piece = uc($promo);
+ $nb->[$to_row + 1][$to_col] = '-';
}
}
}
+ if (defined($promo) && $promo ne '') {
+ if ($piece eq 'p') {
+ $piece = lc($promo);
+ } else {
+ $piece = uc($promo);
+ }
+ }
}
# update the board
next if (defined($from_col) && $from_col != $col);
next if ($board->[$row][$col] ne $piece);
next if (!$board->can_reach($piece, $row, $col, $to_row, $to_col));
+
+ # See if doing this move would put us in check
+ # (yes, there are clients that expect us to do this).
+ my $check = $board->make_move($row, $col, $to_row, $to_col, $promo)->in_check();
+ next if ($check eq 'both' ||
+ ($toplay eq 'W' && $check eq 'white') ||
+ ($toplay eq 'B' && $check eq 'black'));
+
push @squares, [ $row, $col ];
}
}
can_reach($board, 'B', $from_row, $from_col, $to_row, $to_col));
}
- # TODO: en passant
if ($piece eq 'p') {
# black pawn
if ($to_col == $from_col && $to_row == $from_row + 1) {
return ($dest_piece eq '-' && $middle_piece eq '-');
}
if (abs($to_col - $from_col) == 1 && $to_row == $from_row + 1) {
- return ($dest_piece ne '-');
+ if ($dest_piece eq '-') {
+ # En passant. TODO: check that the last move was indeed an EP move
+ return ($to_row == 5 && $board->[4][$to_col] eq 'P');
+ } else {
+ return 1;
+ }
}
return 0;
}
return ($dest_piece eq '-' && $middle_piece eq '-');
}
if (abs($to_col - $from_col) == 1 && $to_row == $from_row - 1) {
- return ($dest_piece ne '-');
+ if ($dest_piece eq '-') {
+ # En passant. TODO: check that the last move was indeed an EP move
+ return ($to_row == 2 && $board->[3][$to_col] eq 'p');
+ } else {
+ return 1;
+ }
}
return 0;
}