]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Fix so the prettyprinter understands en passant.
[remoteglot] / remoteglot.pl
index eecad8f215d54efbac8d2a6e6aac4a63991566a0..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');
@@ -264,10 +266,12 @@ sub prettyprint_pv {
        my $pretty;
        my $piece = substr($board->[$from_row], $from_col, 1);
 
+       if ($piece eq '-') {
+               die "Invalid move";
+       }
+
        # 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);
@@ -281,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);
@@ -296,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);
@@ -311,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);
@@ -327,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);
 
@@ -390,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);
 
@@ -406,7 +412,28 @@ sub prettyprint_pv {
 sub output_screen {
        #return;
 
-       print  "\ecAnalysis:\n";
+       #
+       # Check the PVs first. if they're invalid, just wait, as our data
+       # is most likely out of sync. This isn't a very good solution, as
+       # it can frequently miss stuff, but it's good enough for most users.
+       #
+       eval {
+               my $dummy;
+               if (exists($uciinfo{'pv'})) {
+                       $dummy = prettyprint_pv($ficsinfo{'board'}, @{$uciinfo{'pv'}});
+               }
+       
+               my $mpv = 1;
+               while (exists($uciinfo{'pv' . $mpv})) {
+                       $dummy = prettyprint_pv($ficsinfo{'board'}, @{$uciinfo{'pv' . $mpv}});
+                       ++$mpv;
+               }
+       };
+       if ($@) {
+               return;
+       }
+
+       print  "\e[H\e[2JAnalysis:\n\n";
 
        return unless (exists($ficsinfo{'board'}));