]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
More telnet-friendly clearing.
[remoteglot] / remoteglot.pl
index f6a94028ef2d4ac1d65705f20ed08261bd86b46d..1bdfea08b8fa9f7169a9be157fad25f945341a0d 100755 (executable)
@@ -264,6 +264,10 @@ 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;
@@ -406,7 +410,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'}));
 
@@ -542,7 +567,7 @@ sub in_check {
        for my $row (0..7) {
                for my $col (0..7) {
                        my $piece = substr($board->[$row], $col, 1);
-                       next if ($piece eq '-' || lc($piece) eq 'k');
+                       next if ($piece eq '-');
                
                        if (uc($piece) eq $piece) {
                                # white piece