Skip to content
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ e2e4
Returns True if the passed in move is legal in the current position.

```python
stockfish.is_move_correct('a2a3')
stockfish.is_move_legal('a2a3')
```

```text
Expand Down
6 changes: 3 additions & 3 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,13 @@ def is_fen_valid(self, fen: str) -> bool:
# The __del__ function should generally be called implicitly by python when this
# temp_sf object goes out of scope, but calling it explicitly guarantees this will happen.

def is_move_correct(self, move_value: str) -> bool:
def is_move_legal(self, move_value: str) -> bool:
"""Returns if the passed in move is legal.

`move_value`: new move value in pure algebraic coordinate notation.

Example:
>>> is_correct = stockfish.is_move_correct("f4f5")
>>> is_correct = stockfish.is_move_legal("f4f5")
"""
return move_value in self.get_perft(1)[1]

Expand Down Expand Up @@ -1048,7 +1048,7 @@ def will_move_be_a_capture(self, move_value: str) -> Capture:
Example:
>>> capture = stockfish.will_move_be_a_capture("e2e4")
"""
if not self.is_move_correct(move_value):
if not self.is_move_legal(move_value):
raise ValueError("The proposed move is not valid in the current position.")
starting_square_piece: Stockfish.Piece | None = self.get_what_is_on_square(
move_value[:2]
Expand Down
22 changes: 11 additions & 11 deletions tests/stockfish/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ def test_set_fen_position(self, stockfish: Stockfish):
stockfish.set_fen_position(
"7r/1pr1kppb/2n1p2p/2NpP2P/5PP1/1P6/P6K/R1R2B2 w - - 1 27"
)
assert stockfish.is_move_correct("f4f5") is True
assert stockfish.is_move_correct("a1c1") is False
assert stockfish.is_move_legal("f4f5") is True
assert stockfish.is_move_legal("a1c1") is False

def test_castling(self, stockfish: Stockfish):
assert stockfish.is_move_correct("e1g1") is False
assert stockfish.is_move_legal("e1g1") is False
stockfish.set_fen_position(
"rnbqkbnr/ppp3pp/3ppp2/8/4P3/5N2/PPPPBPPP/RNBQK2R w KQkq - 0 4"
)
assert stockfish.is_move_correct("e1g1") is True
assert stockfish.is_move_legal("e1g1") is True

def test_set_fen_position_mate(self, stockfish: Stockfish):
stockfish.set_fen_position("8/8/8/6pp/8/4k1PP/8/r3K3 w - - 12 53")
Expand Down Expand Up @@ -188,14 +188,14 @@ def test_set_fen_position_second_argument(self, stockfish: Stockfish):
)
assert stockfish.get_best_move() == "e4e5"

def test_is_move_correct_first_move(self, stockfish: Stockfish):
assert stockfish.is_move_correct("e2e1") is False
assert stockfish.is_move_correct("a2a3") is True
def test_is_move_legal_first_move(self, stockfish: Stockfish):
assert stockfish.is_move_legal("e2e1") is False
assert stockfish.is_move_legal("a2a3") is True

def test_is_move_correct_not_first_move(self, stockfish: Stockfish):
def test_is_move_legal_not_first_move(self, stockfish: Stockfish):
stockfish.make_moves_from_start(["e2e4", "e7e6"])
assert stockfish.is_move_correct("e2e1") is False
assert stockfish.is_move_correct("a2a3") is True
assert stockfish.is_move_legal("e2e1") is False
assert stockfish.is_move_legal("a2a3") is True

# fmt: off
@pytest.mark.parametrize(
Expand Down Expand Up @@ -379,7 +379,7 @@ def test_chess960_position(self, stockfish: Stockfish):
stockfish.set_turn_perspective()
assert stockfish.get_evaluation() == {"type": "mate", "value": 2}
with pytest.raises(RuntimeError):
stockfish.is_move_correct("f1g1")
stockfish.is_move_legal("f1g1")
with pytest.raises(RuntimeError):
stockfish.get_perft(1)

Expand Down
Loading