21 lines
490 B
Python
21 lines
490 B
Python
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}")
|