- my $fen = style12_to_fen($line);
- uciprint("stop");
- uciprint("position fen $fen");
- uciprint("go infinite");
+ my $pos = style12_to_fen($line);
+
+ # if this is already in the queue, ignore it
+ next if (defined($pos_waiting) && $pos->{'fen'} eq $pos_waiting->{'fen'});
+
+ # if we're already chewing on this and there's nothing else in the queue,
+ # also ignore it
+ next if (!defined($pos_waiting) && defined($pos_calculating) &&
+ $pos->{'fen'} eq $pos_calculating->{'fen'});
+
+ # if we're already thinking on something, stop and wait for the engine
+ # to approve
+ if (defined($pos_calculating)) {
+ if (!defined($pos_waiting)) {
+ uciprint("stop");
+ }
+ if ($uci_assume_full_compliance) {
+ $pos_waiting = $pos;
+ } else {
+ uciprint("position fen " . $pos->{'fen'});
+ uciprint("go infinite");
+ $pos_calculating = $pos;
+ }
+ } else {
+ # it's wrong just to give the FEN (the move history is useful,
+ # and per the UCI spec, we should really have sent "ucinewgame"),
+ # but it's easier
+ uciprint("position fen " . $pos->{'fen'});
+ uciprint("go infinite");
+ $pos_calculating = $pos;
+ }