Skip to content

Commit

Permalink
Add tuple as an optional return type to get_wdl_stats function
Browse files Browse the repository at this point in the history
  • Loading branch information
evanjhoward11 committed Mar 13, 2024
1 parent f2cb530 commit 77d966d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,16 @@ def is_move_correct(self, move_value: str) -> bool:
self.info = old_self_info
return is_move_correct

def get_wdl_stats(self) -> Optional[List[int]]:
def get_wdl_stats(self, get_as_tuple: bool = False) -> Union[List[int], Tuple[int, int, int], None]:
"""Returns Stockfish's win/draw/loss stats for the side to move.
Args:
get_as_tuple:
Option to return the wdl stats as a tuple instead of a list
`Boolean`. Default is `False`.
Returns:
A list of three integers, unless the game is over (in which case
A list or tuple of three integers, unless the game is over (in which case
`None` is returned).
"""

Expand All @@ -730,6 +735,9 @@ def get_wdl_stats(self) -> Optional[List[int]]:
return None
split_line = [line.split(" ") for line in lines if " multipv 1 " in line][-1]
wdl_index = split_line.index("wdl")

if get_as_tuple:
return tuple([int(split_line[i]) for i in range(wdl_index + 1, wdl_index + 4)])
return [int(split_line[i]) for i in range(wdl_index + 1, wdl_index + 4)]

def does_current_engine_version_have_wdl_option(self) -> bool:
Expand Down

0 comments on commit 77d966d

Please sign in to comment.