Skip to content

Commit

Permalink
Remove deprecated chess.engine.Wdl tuple behavior (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 9, 2024
1 parent f2b0452 commit b2657eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
45 changes: 1 addition & 44 deletions chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,11 @@ def __str__(self) -> str:
MateGiven = MateGivenType()


@dataclasses.dataclass
class PovWdl:
"""
Relative :class:`win/draw/loss statistics <chess.engine.Wdl>` and the point
of view.
.. deprecated:: 1.2
Behaves like a tuple
``(wdl.relative.wins, wdl.relative.draws, wdl.relative.losses)``
for backwards compatibility. But it is recommended to use the provided
fields and methods instead.
"""

relative: Wdl
Expand All @@ -738,10 +733,6 @@ class PovWdl:
turn: Color
"""The point of view (``chess.WHITE`` or ``chess.BLACK``)."""

def __init__(self, relative: Wdl, turn: Color) -> None:
self.relative = relative
self.turn = turn

def white(self) -> Wdl:
"""Gets the :class:`~chess.engine.Wdl` from White's point of view."""
return self.pov(chess.WHITE)
Expand All @@ -763,30 +754,6 @@ def __bool__(self) -> bool:
def __repr__(self) -> str:
return "PovWdl({!r}, {})".format(self.relative, "WHITE" if self.turn else "BLACK")

# Unfortunately in python-chess v1.1.0, info["wdl"] was a simple tuple
# of the relative permille values, so we have to support __iter__,
# __len__, __getitem__, and equality comparisons with other tuples.
# Never mind the ordering, because that's not a sensible operation, anyway.

def __iter__(self) -> Iterator[int]:
yield self.relative.wins
yield self.relative.draws
yield self.relative.losses

def __len__(self) -> int:
return 3

def __getitem__(self, idx: int) -> int:
return (self.relative.wins, self.relative.draws, self.relative.losses)[idx]

def __eq__(self, other: object) -> bool:
if isinstance(other, PovWdl):
return self.white() == other.white()
elif isinstance(other, tuple):
return (self.relative.wins, self.relative.draws, self.relative.losses) == other
else:
return NotImplemented


@dataclasses.dataclass
class Wdl:
Expand Down Expand Up @@ -830,16 +797,6 @@ def expectation(self) -> float:
def __bool__(self) -> bool:
return bool(self.total())

def __iter__(self) -> Iterator[int]:
yield self.wins
yield self.draws
yield self.losses

def __reversed__(self) -> Iterator[int]:
yield self.losses
yield self.draws
yield self.wins

def __pos__(self) -> Wdl:
return self

Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3540,7 +3540,7 @@ def test_uci_info(self):

# WDL (activated with UCI_ShowWDL).
info = chess.engine._parse_uci_info("depth 1 seldepth 2 time 16 nodes 1 score cp 72 wdl 249 747 4 hashfull 0 nps 400 tbhits 0 multipv 1", board)
self.assertEqual(info["wdl"], (249, 747, 4))
self.assertEqual(info["wdl"].white(), chess.engine.Wdl(249, 747, 4))

def test_uci_result(self):
async def main():
Expand Down

0 comments on commit b2657eb

Please sign in to comment.