From 19cdbec4e18ab338cc2b01746026726627968a42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <jmm@yavook.de>
Date: Wed, 30 Aug 2023 01:19:05 +0000
Subject: [PATCH] solve() shuffle parameter

---
 pigeon_magnet_solver/main.py   | 1 +
 pigeon_magnet_solver/solver.py | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

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)