# Root position. Basically ignore everything except the opening (and later some root game stuff).
my $fen = $cgi->param('fen') // 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
+my $prevfen = $cgi->param('prevfen') // '';
my $includetransp = $cgi->param('includetransp') // 1;
my $pos = Position->from_fen($fen);
-my ($json_root_pos, $root_aux_data) = get_json_move($pos, undef, $chld_in, $chld_out); # TODO: include previous hash if $includetransp == 0
-my $opening = $openings{$json_root_pos->{'opening_num'}} // 'A00: Start position';
+my ($json_root_pos, $root_aux_data);
+if ($includetransp) {
+ ($json_root_pos, $root_aux_data) = get_json_move($pos, undef, $chld_in, $chld_out);
+} else {
+ my $prev_pos_hash = 0;
+ if ($prevfen ne '') {
+ my $prevpos = Position->from_fen($prevfen);
+ my (undef, $prev_aux_data) = get_json_move($prevpos, undef, $chld_in, $chld_out);
+ $prev_pos_hash = $prev_aux_data->{'pos_hash'};
+ }
+ ($json_root_pos, $root_aux_data) = get_json_move($pos, $prev_pos_hash, $chld_in, $chld_out);
+}
+my $opening = $openings{$json_root_pos->{'opening_num'}} // 'A00: Start position';
my @json_moves = ($json_root_pos);
my $root_game;
sub get_json_move {
my ($pos, $filter_prev_pos_hash, $chld_in, $chld_out) = @_;
- my $hex = unpack('H*', $pos->bitpacked_fen);
+ my $bpfen_hex = unpack('H*', $pos->bitpacked_fen);
+ my $prev_pos_hash_hex = '';
if (defined($filter_prev_pos_hash)) {
- $hex .= unpack('H*', pack('S', $filter_prev_pos_hash));
+ $prev_pos_hash_hex .= unpack('H*', pack('S', $filter_prev_pos_hash));
}
- print $chld_in $hex, "\n";
+ print $chld_in $bpfen_hex, "\n", $prev_pos_hash_hex, "\n";
# Read the hash of this position.
chomp (my $pos_hash = <$chld_out>);
chomp (my $line = <$chld_out>);
if ($line eq '-') {
+ warn "Missing pos '" . $pos->fen . "' " . $filter_prev_pos_hash;
return ({}, {});
}