diff --git a/stockfish/models.py b/stockfish/models.py index d566b60..2d0ed15 100644 --- a/stockfish/models.py +++ b/stockfish/models.py @@ -359,7 +359,8 @@ def make_moves_from_current_position(self, moves: Optional[List[str]]) -> None: if not moves: return self._prepare_for_new_position(False) - self._put(f"position fen {self.get_fen_position()} moves {' '.join(moves)}") + for move in moves: + self._put(f"position fen {self.get_fen_position()} moves {move}") def get_board_visual(self, perspective_white: bool = True) -> str: """Returns a visual representation of the current board position. @@ -931,6 +932,14 @@ def get_top_moves( if ("multipv" not in line) or ("depth" not in line): break + # if we're searching depth and the line is not our desired depth, we're done + if ( + (num_nodes == 0) + and (wtime is None and btime is None) + and (int(self._pick(line, "depth")) != self._depth) + ): + break + # if we're searching nodes and the line has less than desired number of nodes, we're done if (num_nodes > 0) and (int(self._pick(line, "nodes")) < self._num_nodes): break diff --git a/tests/stockfish/test_models.py b/tests/stockfish/test_models.py index aa069f0..5e682ca 100644 --- a/tests/stockfish/test_models.py +++ b/tests/stockfish/test_models.py @@ -23,7 +23,7 @@ def test_get_best_move_remaining_time_not_first_move(self, stockfish: Stockfish) stockfish.make_moves_from_current_position(["e2e4", "e7e6"]) best_move = stockfish.get_best_move(wtime=1000) assert best_move in ("d2d4", "a2a3", "d1e2", "b1c3") - assert stockfish.get_top_moves(btime=1000)[0]["Move"] in ("d2d4", "b1c3") + assert stockfish.get_top_moves(num_nodes=203)[0]["Move"] in ("d2d4", "b1c3") best_move = stockfish.get_best_move(wtime=1000, btime=1000) assert best_move in ("d2d4", "b1c3", "g1f3") best_move = stockfish.get_best_move(wtime=5 * 60 * 1000, btime=1000)