Board class representations

This commit is contained in:
Jörn-Michael Miehe 2023-08-18 18:41:58 +00:00
parent cfe02d65f7
commit f2dac56953
3 changed files with 47 additions and 1 deletions

View file

@ -43,5 +43,34 @@ class Board:
for button in self.buttons
), "Invalid buttons!"
def __str__(self) -> str:
result = "\n".join(self.rows)
result = result\
.replace("0", "⚪️")\
.replace("1", "🟢️")\
.replace("x", "⚫️")
return result
@property
def columns(self) -> tuple[str, ...]:
return tuple(
"".join(row[x] for row in self.rows)
for x in range(self.width)
)
@property
def binary_repr(self) -> tuple[int, ...]:
return tuple(
int(column.replace("x", "0")[::-1], base=2)
for column in self.columns
)
@property
def solution_class(self) -> tuple[int, ...]:
return tuple(
column.count("1")
for column in self.columns
)
def click(self, index: int) -> None:
pass

13
pigeon_magnet_solver/main.py Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/python3
from .board import Board
def main() -> None:
board = Board.default_puzzle
print(board)
if __name__ == "__main__":
main()

View file

@ -4,5 +4,9 @@ from pigeon_magnet_solver.board import Board
def test_default():
board = Board.default_puzzle
assert board.width == 3, "Wrong width"
assert board.height == 4, "Wrong height"
assert board.width == 3, "Wrong width"
assert board.columns == ("001x", "1101", "110x"), "Wrong columns"
assert board.binary_repr == (4, 11, 3), "Wrong binary repr"
assert board.solution_class == (1, 3, 2), "Wrong solution class"