my $server = "freechess.org";
my $target = "GMCarlsen";
my $engine_cmdline = "'./Deep Rybka 4 SSE42 x64'";
-my $engine2_cmdline = "./stockfish_13111119_x64_modern_sse42";
+my $engine2_cmdline = "./stockfish_13111119_x64_modern_sse42"; # undef for none
my $telltarget = undef; # undef to be silent
my @tell_intervals = (5, 20, 60, 120, 240, 480, 960); # after each move
my $uci_assume_full_compliance = 0; # dangerous :-)
# uciprint($engine, "setoption name MultiPV value 2");
uciprint($engine, "ucinewgame");
-uciprint($engine2, "setoption name UCI_AnalyseMode value true");
-# uciprint($engine2, "setoption name NalimovPath value /srv/tablebase");
-uciprint($engine2, "setoption name NalimovUsage value Rarely");
-uciprint($engine2, "setoption name Hash value 1024");
-uciprint($engine2, "setoption name Threads value 8");
-uciprint($engine2, "setoption name MultiPV value 500");
-uciprint($engine2, "ucinewgame");
+if (defined($engine2)) {
+ uciprint($engine2, "setoption name UCI_AnalyseMode value true");
+ # uciprint($engine2, "setoption name NalimovPath value /srv/tablebase");
+ uciprint($engine2, "setoption name NalimovUsage value Rarely");
+ uciprint($engine2, "setoption name Hash value 1024");
+ uciprint($engine2, "setoption name Threads value 8");
+ uciprint($engine2, "setoption name MultiPV value 500");
+ uciprint($engine2, "ucinewgame");
+}
print "Chess engine ready.\n";
my $rin = '';
my $rout;
vec($rin, fileno($engine->{'read'}), 1) = 1;
- vec($rin, fileno($engine2->{'read'}), 1) = 1;
+ if (defined($engine2)) {
+ vec($rin, fileno($engine2->{'read'}), 1) = 1;
+ }
vec($rin, fileno($t), 1) = 1;
my ($nfound, $timeleft) = select($rout=$rin, undef, undef, 5.0);
$pos_calculating = $pos;
}
- if (defined($pos_calculating_second_engine)) {
- uciprint($engine2, "stop");
- } else {
- uciprint($engine2, "position fen " . $pos->{'fen'});
- uciprint($engine2, "go infinite");
- $pos_calculating_second_engine = $pos;
+ if (defined($engine2)) {
+ if (defined($pos_calculating_second_engine)) {
+ uciprint($engine2, "stop");
+ } else {
+ uciprint($engine2, "position fen " . $pos->{'fen'});
+ uciprint($engine2, "go infinite");
+ $pos_calculating_second_engine = $pos;
+ }
+ $engine2->{'info'} = {};
}
$engine->{'info'} = {};
- $engine2->{'info'} = {};
$last_move = time;
#
output();
}
- if ($nfound > 0 && vec($rout, fileno($engine2->{'read'}), 1) == 1) {
+ if (defined($engine2) && $nfound > 0 && vec($rout, fileno($engine2->{'read'}), 1) == 1) {
my @lines = read_lines($engine2);
for my $line (@lines) {
next if $line =~ /(upper|lower)bound/;
}
if (exists($info->{'tbhits'}) && $info->{'tbhits'} > 0) {
if ($info->{'tbhits'} == 1) {
- $text .= ", one Nalimov hit";
+ $text .= ", one Syzygy hit";
} else {
- $text .= sprintf ", %u Nalimov hits", $info->{'tbhits'};
+ $text .= sprintf ", %u Syzygy hits", $info->{'tbhits'};
}
}
$text .= "\n\n";
#$text .= book_info($pos_calculating->{'fen'}, $pos_calculating->{'board'}, $pos_calculating->{'toplay'});
my @refutation_lines = ();
- for (my $mpv = 1; $mpv < 500; ++$mpv) {
- my $info = $engine2->{'info'};
- last if (!exists($info->{'pv' . $mpv}));
- eval {
- my $pv = $info->{'pv' . $mpv};
-
- my $pretty_move = join('', prettyprint_pv($pos_calculating_second_engine->{'board'}, $pv->[0]));
- my @pretty_pv = prettyprint_pv($pos_calculating_second_engine->{'board'}, @$pv);
- if (scalar @pretty_pv > 5) {
- @pretty_pv = @pretty_pv[0..4];
- push @pretty_pv, "...";
- }
- my $key = $pretty_move;
- my $line = sprintf(" %-6s %6s %3s %s",
- $pretty_move,
- short_score($info, $pos_calculating_second_engine, $mpv, 0),
- "d" . $info->{'depth' . $mpv},
- join(', ', @pretty_pv));
- push @refutation_lines, [ $key, $line ];
- };
+ if (defined($engine2)) {
+ for (my $mpv = 1; $mpv < 500; ++$mpv) {
+ my $info = $engine2->{'info'};
+ last if (!exists($info->{'pv' . $mpv}));
+ eval {
+ my $pv = $info->{'pv' . $mpv};
+
+ my $pretty_move = join('', prettyprint_pv($pos_calculating_second_engine->{'board'}, $pv->[0]));
+ my @pretty_pv = prettyprint_pv($pos_calculating_second_engine->{'board'}, @$pv);
+ if (scalar @pretty_pv > 5) {
+ @pretty_pv = @pretty_pv[0..4];
+ push @pretty_pv, "...";
+ }
+ my $key = $pretty_move;
+ my $line = sprintf(" %-6s %6s %3s %s",
+ $pretty_move,
+ short_score($info, $pos_calculating_second_engine, $mpv, 0),
+ "d" . $info->{'depth' . $mpv},
+ join(', ', @pretty_pv));
+ push @refutation_lines, [ $key, $line ];
+ };
+ }
}
if ($#refutation_lines >= 0) {
my %refutation_lines = ();
my @refutation_lines = ();
- for (my $mpv = 1; $mpv < 500; ++$mpv) {
- my $info = $engine2->{'info'};
- my $pretty_move = "";
- my @pretty_pv = ();
- last if (!exists($info->{'pv' . $mpv}));
-
- eval {
- my $pv = $info->{'pv' . $mpv};
- my $pretty_move = join('', prettyprint_pv($pos_calculating->{'board'}, $pv->[0]));
- my @pretty_pv = prettyprint_pv($pos_calculating->{'board'}, @$pv);
- $refutation_lines{$pv->[0]} = {
- sort_key => $pretty_move,
- depth => $info->{'depth' . $mpv},
- score_sort_key => score_sort_key($info, $pos_calculating, $mpv, 0),
- pretty_score => short_score($info, $pos_calculating, $mpv, 0),
- pretty_move => $pretty_move,
- pv_pretty => \@pretty_pv,
+ if (defined($engine2)) {
+ for (my $mpv = 1; $mpv < 500; ++$mpv) {
+ my $info = $engine2->{'info'};
+ my $pretty_move = "";
+ my @pretty_pv = ();
+ last if (!exists($info->{'pv' . $mpv}));
+
+ eval {
+ my $pv = $info->{'pv' . $mpv};
+ my $pretty_move = join('', prettyprint_pv($pos_calculating->{'board'}, $pv->[0]));
+ my @pretty_pv = prettyprint_pv($pos_calculating->{'board'}, @$pv);
+ $refutation_lines{$pv->[0]} = {
+ sort_key => $pretty_move,
+ depth => $info->{'depth' . $mpv},
+ score_sort_key => score_sort_key($info, $pos_calculating, $mpv, 0),
+ pretty_score => short_score($info, $pos_calculating, $mpv, 0),
+ pretty_move => $pretty_move,
+ pv_pretty => \@pretty_pv,
+ };
+ $refutation_lines{$pv->[0]}->{'pv_uci'} = $pv;
};
- $refutation_lines{$pv->[0]}->{'pv_uci'} = $pv;
- };
+ }
}
$json->{'refutation_lines'} = \%refutation_lines;
- open my $fh, ">analysis.json.tmp"
+ open my $fh, ">/srv/analysis.sesse.net/www/analysis.json.tmp"
or return;
print $fh JSON::XS::encode_json($json);
close $fh;
- rename("analysis.json.tmp", "analysis.json");
+ rename("/srv/analysis.sesse.net/www/analysis.json.tmp", "/srv/analysis.sesse.net/www/analysis.json");
}
sub find_kings {
if (defined($info->{'score_mate' . $mpv})) {
if ($invert) {
- return -(99999 - $info->{'score_mate' . $mpv});
- } else {
return 99999 - $info->{'score_mate' . $mpv};
+ } else {
+ return -(99999 - $info->{'score_mate' . $mpv});
}
} else {
if (exists($info->{'score_cp' . $mpv})) {
} else {
if (exists($info->{'score_cp' . $mpv})) {
my $score = $info->{'score_cp' . $mpv} * 0.01;
+ if ($score == 0) {
+ return "Score: 0.00";
+ }
if ($pos->{'toplay'} eq 'B') {
$score = -$score;
}
sub open_engine {
my ($cmdline, $tag) = @_;
+
+ return undef if (!defined($cmdline));
+
my ($uciread, $uciwrite);
my $pid = IPC::Open2::open2($uciread, $uciwrite, $cmdline);