feat(sides): Side enum with opposite/from_str
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Side(str, Enum):
|
||||
WHITE = "white"
|
||||
BLACK = "black"
|
||||
|
||||
def opposite(self) -> Side:
|
||||
return Side.BLACK if self is Side.WHITE else Side.WHITE
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, value: str) -> Side:
|
||||
v = value.strip().lower()
|
||||
if v in ("w", "white"):
|
||||
return cls.WHITE
|
||||
if v in ("b", "black"):
|
||||
return cls.BLACK
|
||||
raise ValueError(f"unknown side: {value!r}")
|
||||
Reference in New Issue
Block a user