47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass(kw_only=True, slots=True)
|
|
class Board:
|
|
rows: list[str]
|
|
buttons: tuple[int, ...]
|
|
|
|
@classmethod
|
|
@property
|
|
def default_puzzle(cls) -> "Board":
|
|
return cls(
|
|
rows=["011", "011", "100", "x1x"],
|
|
buttons=(3, 4, 5, 7),
|
|
)
|
|
|
|
@property
|
|
def height(self) -> int:
|
|
return len(self.rows)
|
|
|
|
@property
|
|
def width(self) -> int:
|
|
if not self.rows:
|
|
return 0
|
|
else:
|
|
return len(self.rows[0])
|
|
|
|
def __post_init__(self) -> None:
|
|
# check char set
|
|
chars = {c for c in "".join(self.rows)}
|
|
assert chars.issubset({"0", "1", "x"}), "Invalid char set!"
|
|
|
|
# check defined width
|
|
assert all(
|
|
len(row) == self.width
|
|
for row in self.rows
|
|
), "Inconsistent width!"
|
|
|
|
# check buttons
|
|
length = self.height * self.width
|
|
assert all(
|
|
button >= 0 and button < length
|
|
for button in self.buttons
|
|
), "Invalid buttons!"
|
|
|
|
def click(self, index: int) -> None:
|
|
pass
|