From: Steinar H. Gunderson Date: Sat, 30 Jun 2007 15:33:39 +0000 (+0200) Subject: Fix so the prettyprinter understands en passant. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=78c65f48f5141bf44b473cf3fb793671c8415539 Fix so the prettyprinter understands en passant. --- diff --git a/remoteglot.pl b/remoteglot.pl index 1bdfea0..9aaa43d 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -254,6 +254,8 @@ sub prettyprint_pv { 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'); @@ -270,8 +272,6 @@ sub prettyprint_pv { # 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); @@ -285,8 +285,6 @@ sub prettyprint_pv { # 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); @@ -300,8 +298,6 @@ sub prettyprint_pv { # 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); @@ -315,8 +311,6 @@ sub prettyprint_pv { # 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); @@ -331,8 +325,17 @@ sub prettyprint_pv { # 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); @@ -394,7 +397,6 @@ sub prettyprint_pv { } # update the board - my @nb = @$board; substr($nb[$from_row], $from_col, 1, '-'); substr($nb[$to_row], $to_col, 1, $piece);