Skip to content

Commit

Permalink
Make chess.engine.Protocol.options an abstract property
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 13, 2024
1 parent e204169 commit c42749d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,6 @@ def get_returncode(self) -> Optional[int]:
class Protocol(asyncio.SubprocessProtocol, metaclass=abc.ABCMeta):
"""Protocol for communicating with a chess engine process."""

options: MutableMapping[str, Option]
"""Dictionary of available options."""

id: Dict[str, str]
"""
Dictionary of information about the engine. Common keys are ``name``
Expand Down Expand Up @@ -981,6 +978,11 @@ def __repr__(self) -> str:
pid = self.transport.get_pid() if self.transport is not None else "?"
return f"<{type(self).__name__} (pid={pid})>"

@property
@abc.abstractmethod
def options(self) -> MutableMapping[str, Option]:
"""Dictionary of available options."""

@abc.abstractmethod
async def initialize(self) -> None:
"""Initializes the engine."""
Expand Down Expand Up @@ -1281,7 +1283,7 @@ class UciProtocol(Protocol):

def __init__(self) -> None:
super().__init__()
self.options: UciOptionMap[Option] = UciOptionMap()
self._options: UciOptionMap[Option] = UciOptionMap()
self.config: UciOptionMap[ConfigValue] = UciOptionMap()
self.target_config: UciOptionMap[ConfigValue] = UciOptionMap()
self.id = {}
Expand All @@ -1291,6 +1293,11 @@ def __init__(self) -> None:
self.may_ponderhit: Optional[chess.Board] = None
self.ponderhit = False

@property
@override
def options(self) -> UciOptionMap[Option]:
return self._options

async def initialize(self) -> None:
class UciInitializeCommand(BaseCommand[None]):
def __init__(self, engine: UciProtocol):
Expand Down Expand Up @@ -1939,7 +1946,7 @@ def __init__(self) -> None:
super().__init__()
self.features: Dict[str, Union[int, str]] = {}
self.id = {}
self.options = {
self._options = {
"random": Option("random", "check", False, None, None, None),
"computer": Option("computer", "check", False, None, None, None),
"name": Option("name", "string", "", None, None, None),
Expand All @@ -1953,6 +1960,11 @@ def __init__(self) -> None:
self.clock_id: object = None
self.first_game = True

@property
@override
def options(self) -> Dict[str, Option]:
return self._options

async def initialize(self) -> None:
class XBoardInitializeCommand(BaseCommand[None]):
def __init__(self, engine: XBoardProtocol):
Expand Down

0 comments on commit c42749d

Please sign in to comment.