Skip to content

Commit

Permalink
Remove the _is_ready function and put its code directly in the `_pu…
Browse files Browse the repository at this point in the history
…t` function (since it is only used there).
  • Loading branch information
johndoknjas committed Aug 26, 2024
1 parent 19ba2c4 commit 4123b43
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ def _prepare_for_new_position(self) -> None:
self.info = ""

def _put(self, command: str) -> None:
"""Sends a command to the Stockfish engine. Note that if there's any existing output still
in stdout, it will be cleared."""
"""Sends a command to the Stockfish engine. Note that this function shouldn't be called if
there's any existing output in stdout that's still needed."""
if not self._stockfish.stdin:
raise BrokenPipeError()
if self._stockfish.poll() is None and not self._has_quit_command_been_sent:
if command != "isready":
self._is_ready()
self._put("isready")
while self._read_line() != "readyok":
pass
if self._debug_view:
print(f">>> {command}\n")
self._stockfish.stdin.write(f"{command}\n")
Expand Down Expand Up @@ -273,11 +275,6 @@ def _validate_param_val(self, name: str, value: Any) -> None:
if maximum is not None and type(value) is int and value > maximum:
raise ValueError(f"{value} is over {name}'s maximum value of {maximum}")

def _is_ready(self) -> None:
self._put("isready")
while self._read_line() != "readyok":
pass

def _go(self) -> None:
self._put(f"go depth {self._depth}")

Expand Down

0 comments on commit 4123b43

Please sign in to comment.