X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=52eae900e98dc52aa070d4b5eac3fa8c7436b79e;hp=e021c664894e4fb0a077f82ec81d79abff6fc61b;hb=4166f694604b0ee8e7fb47156c6623d036b35457;hpb=48c786c43fab6dfe37c0fe70aa474431f33d2b27 diff --git a/remoteglot.pl b/remoteglot.pl index e021c66..52eae90 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -536,6 +536,8 @@ sub prettyprint_pv { } } +my %tbprobe_cache = (); + sub complete_using_tbprobe { my ($pos, $info, $mpv) = @_; @@ -553,11 +555,18 @@ sub complete_using_tbprobe { # Run through the PV until we are at a 6-man position. # TODO: We could in theory only have 5-man data. my @pv = @{$info->{'pv' . $mpv}}; - my $key = join('', @pv); + my $key = $pos->fen() . " " . join('', @pv); my @moves = (); - if (exists($pos->{'tbprobe_cache'}{$key})) { - @moves = $pos->{'tbprobe_cache'}{$key}; + if (exists($tbprobe_cache{$key})) { + @moves = @{$tbprobe_cache{$key}}; } else { + if ($mpv ne '') { + # Force doing at least one move of the PV. + my $move = shift @pv; + push @moves, $move; + $pos = $pos->make_move(parse_uci_move($move)); + } + while ($pos->num_pieces() > 6 && $#pv > -1) { my $move = shift @pv; push @moves, $move; @@ -579,6 +588,8 @@ sub complete_using_tbprobe { ($pos, $uci_move) = $pos->make_pretty_move($move); push @moves, $uci_move; } + + $tbprobe_cache{$key} = \@moves; } $info->{'pv' . $mpv} = \@moves; @@ -1079,7 +1090,7 @@ sub score_digest { if ($score == 0 && $info->{'tablebase'}) { return ['d', undef]; } else { - return ['cp', $score]; + return ['cp', int($score)]; } } }