+
+ # if this is already in the queue, ignore it
+ next if (defined($board_waiting) && $fen eq $board_waiting);
+
+ # if we're already chewing on this and there's nothing else in the queue,
+ # also ignore it
+ next if (!defined($board_waiting) && defined($board_calculating) &&
+ $fen eq $board_calculating);
+
+ # if we're already thinking on something, stop and wait for the engine
+ # to approve
+ if (defined($board_calculating)) {
+ uciprint("stop");
+ $board_waiting = $fen;
+ } 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 $fen");
+ uciprint("go infinite");
+ }