+
+sub get_json_move {
+ my ($pos, $filter_prev_pos_hash, $chld_in, $chld_out) = @_;
+ my $hex = unpack('H*', $pos->bitpacked_fen);
+ if (defined($filter_prev_pos_hash)) {
+ $hex .= unpack('H*', pack('S', $filter_prev_pos_hash));
+ }
+ print $chld_in $hex, "\n";
+
+ # Read the hash of this position.
+ chomp (my $pos_hash = <$chld_out>);
+
+ chomp (my $line = <$chld_out>);
+ if ($line eq '-') {
+ return ({}, {});
+ }
+
+ my ($white, $draw, $black, $opening_num, $white_sum_elo, $black_sum_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line;
+ my $json_pos = {
+ white => $white,
+ draw => $draw,
+ black => $black,
+ white_avg_elo => $num_elo == 0 ? undef : $white_sum_elo / $num_elo,
+ black_avg_elo => $num_elo == 0 ? undef : $black_sum_elo / $num_elo,
+ num_elo => $num_elo,
+ opening_num => $opening_num,
+ };
+ my $aux_data = { # Only relevant for the root.
+ pos_hash => $pos_hash * 1,
+ moves => \@moves,
+ pgn_file_number => $pgn_file_number,
+ pgn_start_position => $pgn_start_position,
+ };
+ return ($json_pos, $aux_data);
+}