Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docstrings and return a deep copy in get_engine_parameters. #84

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ stockfish.set_depth(15)

### Get the engine's current parameters

Returns a deep copy of the dictionary storing the engine's current parameters.

```python
stockfish.get_engine_parameters()
```
Expand Down
6 changes: 3 additions & 3 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def get_engine_parameters(self) -> dict:
"""Returns the current engine parameters being used.

Returns:
Dictionary of current Stockfish engine's parameters.
A deep copy of the dictionary storing the current engine parameters.
"""
return self._parameters
return copy.deepcopy(self._parameters)

def get_parameters(self) -> dict:
"""Returns the current engine parameters being used. *Deprecated, see `get_engine_parameters()`*."""
Expand All @@ -145,7 +145,7 @@ def update_engine_parameters(self, parameters: Optional[dict]) -> None:
Args:
parameters:
Contains (key, value) pairs which will be used to update
the current Stockfish engine's parameters.
the Stockfish engine's current parameters.

Returns:
`None`
Expand Down
10 changes: 8 additions & 2 deletions tests/stockfish/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_set_fen_position_second_argument(self, stockfish: Stockfish):
stockfish.set_fen_position(
"rnbqk2r/pppp1ppp/3bpn2/4P3/3P4/2N5/PPP2PPP/R1BQKBNR b KQkq - 0 1", False
)
assert stockfish.get_best_move() == "d6e7"
assert stockfish.get_best_move() in ("d6e7", "d6b4")

stockfish.set_fen_position(
"rnbqk2r/pppp1ppp/3bpn2/8/3PP3/2N5/PPP2PPP/R1BQKBNR w KQkq - 0 1", False
Expand Down Expand Up @@ -895,7 +895,7 @@ def test_get_wdl_stats(self, stockfish: Stockfish):
wdl_stats = stockfish.get_wdl_stats()
assert isinstance(wdl_stats, list)
assert wdl_stats[1] > wdl_stats[0] * 7
assert abs(wdl_stats[0] - wdl_stats[2]) / wdl_stats[0] < 0.1
assert abs(wdl_stats[0] - wdl_stats[2]) / wdl_stats[0] < 0.15

stockfish.set_fen_position(
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
Expand Down Expand Up @@ -1238,3 +1238,9 @@ def test_pick(self, stockfish: Stockfish):
assert stockfish._pick(line, "depth") == "10"
assert stockfish._pick(line, "multipv") == "1"
assert stockfish._pick(line, "wdl", 3) == "1000"

def test_get_engine_parameters(self, stockfish: Stockfish):
params = stockfish.get_engine_parameters()
params.update({"Skill Level": 10})
assert params["Skill Level"] == 10
assert stockfish._parameters["Skill Level"] == 20
Loading