13 my $fen = $cgi->param('fen');
14 my $pos = Position->from_fen($fen);
15 my $hex = unpack('H*', $pos->bitpacked_fen);
16 open my $fh, "-|", "../binlookup", "../open.mtbl", "40", $hex
17 or die "../binlookup: $!";
24 my ($move, $white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo) = split;
30 white_avg_elo => $white_avg_elo * 1,
31 black_avg_elo => $black_avg_elo * 1,
32 num_elo => $num_elo * 1
34 $opening = $openings{$opening_num} // 'A00: Start position';
38 @moves = sort { num($b) <=> num($a) } @moves;
40 print $cgi->header(-type=>'application/json');
41 print JSON::XS::encode_json({ moves => \@moves, opening => $opening });
45 return $x->{'white'} + $x->{'draw'} + $x->{'black'};
49 open my $fh, "../openings.txt"
50 or die "../openings.txt: $!";
51 for my $line (<$fh>) {
53 my ($hash, $eco, $opening, $variation, $subvariation) = split /\t/, $line;
54 if ($variation eq '') {
55 $openings{$hash} = $eco . ": " . $opening;
57 $openings{$hash} = $eco . ": " . $opening . ": " . $variation;