diff --git a/pigeon_magnet_solver/main.py b/pigeon_magnet_solver/main.py index 6bc55db..5497784 100755 --- a/pigeon_magnet_solver/main.py +++ b/pigeon_magnet_solver/main.py @@ -8,6 +8,7 @@ def main() -> None: solution = solve( Board.default_puzzle, lambda state: state.solution_class == (3, 1, 2), + # shuffle=True, ) if solution is None: diff --git a/pigeon_magnet_solver/solver.py b/pigeon_magnet_solver/solver.py index aba9f95..45f9c3e 100644 --- a/pigeon_magnet_solver/solver.py +++ b/pigeon_magnet_solver/solver.py @@ -1,3 +1,4 @@ +import random from typing import Callable from .board import Board @@ -8,6 +9,7 @@ def solve( is_solved: Callable[[Board], bool], *, history: list[tuple[int, Board]] | None = None, + shuffle: bool = False, ) -> list[tuple[int, Board]] | None: if history is None: @@ -17,7 +19,11 @@ def solve( if is_solved(state): return history - for button in state.buttons: + buttons = state.buttons + if shuffle: + buttons = random.sample(buttons, len(buttons)) + + for button in buttons: # try to click all buttons next = state.click(button)