diff --git a/pigeon_magnet_solver/board.py b/pigeon_magnet_solver/board.py index 6835516..7d46c9a 100644 --- a/pigeon_magnet_solver/board.py +++ b/pigeon_magnet_solver/board.py @@ -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 diff --git a/pigeon_magnet_solver/main.py b/pigeon_magnet_solver/main.py new file mode 100755 index 0000000..cf20f81 --- /dev/null +++ b/pigeon_magnet_solver/main.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 + +from .board import Board + + +def main() -> None: + board = Board.default_puzzle + + print(board) + + +if __name__ == "__main__": + main() diff --git a/tests/test_board.py b/tests/test_board.py index 55fcf14..9b3c5fd 100644 --- a/tests/test_board.py +++ b/tests/test_board.py @@ -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"