-
- if ($piece eq 'p') {
- # black pawn
- if ($to_col == $from_col && $to_row == $from_row + 1) {
- return ($dest_piece eq '-');
- }
- if ($to_col == $from_col && $from_row == 1 && $to_row == 3) {
- my $middle_piece = $board->[2][$to_col];
- return ($dest_piece eq '-' && $middle_piece eq '-');
- }
- if (abs($to_col - $from_col) == 1 && $to_row == $from_row + 1) {
- 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;
- }
- if ($piece eq 'P') {
- # white pawn
- if ($to_col == $from_col && $to_row == $from_row - 1) {
- return ($dest_piece eq '-');
- }
- if ($to_col == $from_col && $from_row == 6 && $to_row == 4) {
- my $middle_piece = $board->[5][$to_col];
- return ($dest_piece eq '-' && $middle_piece eq '-');
- }
- if (abs($to_col - $from_col) == 1 && $to_row == $from_row - 1) {
- 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;