]> git.sesse.net Git - remoteglot/commitdiff
Fix so the prettyprinter understands en passant.
authorSteinar H. Gunderson <sesse@debian.org>
Sat, 30 Jun 2007 15:33:39 +0000 (17:33 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sat, 30 Jun 2007 15:33:39 +0000 (17:33 +0200)
remoteglot.pl

index 1bdfea08b8fa9f7169a9be157fad25f945341a0d..9aaa43d654574c8e134f4f597d18ae7cd598aa65 100755 (executable)
@@ -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);