return if ($engine->{'stopping'} && $line !~ /^bestmove/);
$engine->{'stopping'} = 0;
- if ($line =~ /^info/) {
+ if ($line =~ /^info/ && $line !~ / cluster /) {
my (@infos) = split / /, $line;
shift @infos;
delete $info->{'score_cp' . $mpv};
delete $info->{'score_mate' . $mpv};
+ delete $info->{'splicepos' . $mpv};
while ($x[0] eq 'cp' || $x[0] eq 'mate') {
if ($x[0] eq 'cp') {
my @pv = @{$info->{'pv' . $mpv}};
my $key = $pos->fen() . " " . join('', @pv);
my @moves = ();
+ my $splicepos;
if (exists($tbprobe_cache{$key})) {
- @moves = @{$tbprobe_cache{$key}};
+ my $c = $tbprobe_cache{$key};
+ @moves = @{$c->{'moves'}};
+ $splicepos = $c->{'splicepos'};
} else {
if ($mpv ne '') {
# Force doing at least one move of the PV.
return if ($pos->num_pieces() > 7);
my $fen = $pos->fen();
- my $pgn_text = `fathom --path=/srv/syzygy "$fen"`;
+ my $pgn_text = `$remoteglotconf::fathom_cmdline "$fen"`;
my $pgn = Chess::PGN::Parse->new(undef, $pgn_text);
return if (!defined($pgn) || !$pgn->read_game() || ($pgn->result ne '0-1' && $pgn->result ne '1-0'));
$pgn->quick_parse_game;
- $info->{'pv' . $mpv} = \@moves;
# Splice the PV from the tablebase onto what we have so far.
+ $splicepos = scalar @moves;
for my $move (@{$pgn->moves}) {
last if $move eq '#';
last if $move eq '1-0';
push @moves, $uci_move;
}
- $tbprobe_cache{$key} = \@moves;
+ $tbprobe_cache{$key} = {
+ moves => \@moves,
+ splicepos => $splicepos
+ };
}
$info->{'pv' . $mpv} = \@moves;
} else {
$info->{'score_mate' . $mpv} = $matelen;
}
+ $info->{'splicepos' . $mpv} = $splicepos;
}
sub output {
#
my $fen = $pos_calculating->fen();
if (exists($tb_cache{$fen})) {
- for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits)) {
+ for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits splicepos)) {
delete $info->{$key . '1'};
delete $info->{$key};
}
# specified.
#
if (exists($info->{'pv1'}) && !exists($info->{'pv2'})) {
- for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits)) {
+ for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits splicepos)) {
if (exists($info->{$key . '1'})) {
$info->{$key} = $info->{$key . '1'};
} else {
$text .= "\n\n";
}
- #$text .= book_info($pos_calculating->fen(), $pos_calculating->{'board'}, $pos_calculating->{'toplay'});
-
my @refutation_lines = ();
if (defined($engine2)) {
for (my $mpv = 1; $mpv < 500; ++$mpv) {
move => $pretty_move,
pv => \@pretty_pv,
};
+ if (exists($info->{'splicepos' . $mpv})) {
+ $refutation_lines{$pretty_move}->{'splicepos'} = $info->{'splicepos' . $mpv};
+ }
};
}
}
}
if (exists($pos_calculating->{'history'}) &&
- defined($remoteglotconf::json_history_dir)) {
+ defined($remoteglotconf::json_history_dir) && defined($json->{'engine'}{name})) {
my $id = id_for_pos($pos_calculating);
my $filename = $remoteglotconf::json_history_dir . "/" . $id . ".json";
if ($pos->{'toplay'} eq 'B') {
$mate = -$mate;
}
- return ['m', $mate];
+ if (exists($info->{'splicepos' . $mpv})) {
+ my $sp = $info->{'splicepos' . $mpv};
+ if ($mate > 0) {
+ return ['T', $sp];
+ } else {
+ return ['t', $sp];
+ }
+ } else {
+ if ($mate > 0) {
+ return ['M', $mate];
+ } elsif ($mate < 0) {
+ return ['m', -$mate];
+ } elsif ($pos->{'toplay'} eq 'B') {
+ return ['M', 0];
+ } else {
+ return ['m', 0];
+ }
+ }
} else {
if (exists($info->{'score_cp' . $mpv})) {
my $score = $info->{'score_cp' . $mpv};
if ($pos->{'toplay'} eq 'B') {
$mate = -$mate;
}
- if ($mate > 0) {
- return sprintf "White mates in %u", $mate;
+ if (exists($info->{'splicepos' . $mpv})) {
+ my $sp = $info->{'splicepos' . $mpv};
+ if ($mate > 0) {
+ return sprintf "White wins in %u", int(($sp + 1) * 0.5);
+ } else {
+ return sprintf "Black wins in %u", int(($sp + 1) * 0.5);
+ }
} else {
- return sprintf "Black mates in %u", -$mate;
+ if ($mate > 0) {
+ return sprintf "White mates in %u", $mate;
+ } else {
+ return sprintf "Black mates in %u", -$mate;
+ }
}
} else {
if (exists($info->{'score_cp' . $mpv})) {
return undef;
}
-my %book_cache = ();
-sub book_info {
- my ($fen, $board, $toplay) = @_;
-
- if (exists($book_cache{$fen})) {
- return $book_cache{$fen};
- }
-
- my $ret = `./booklook $fen`;
- return "" if ($ret =~ /Not found/ || $ret eq '');
-
- my @moves = ();
-
- for my $m (split /\n/, $ret) {
- my ($move, $annotation, $win, $draw, $lose, $rating, $rating_div) = split /,/, $m;
-
- my $pmove;
- if ($move eq '') {
- $pmove = '(current)';
- } else {
- ($pmove) = prettyprint_pv_no_cache($board, $move);
- $pmove .= $annotation;
- }
-
- my $score;
- if ($toplay eq 'W') {
- $score = 1.0 * $win + 0.5 * $draw + 0.0 * $lose;
- } else {
- $score = 0.0 * $win + 0.5 * $draw + 1.0 * $lose;
- }
- my $n = $win + $draw + $lose;
-
- my $percent;
- if ($n == 0) {
- $percent = " ";
- } else {
- $percent = sprintf "%4u%%", int(100.0 * $score / $n + 0.5);
- }
-
- push @moves, [ $pmove, $n, $percent, $rating ];
- }
-
- @moves[1..$#moves] = sort { $b->[2] cmp $a->[2] } @moves[1..$#moves];
-
- my $text = "Book moves:\n\n Perf. N Rating\n\n";
- for my $m (@moves) {
- $text .= sprintf " %-10s %s %6u %4s\n", $m->[0], $m->[2], $m->[1], $m->[3]
- }
-
- return $text;
-}
-
sub extract_clock {
my ($pgn, $pos) = @_;