solve() shuffle parameter
This commit is contained in:
parent
1b18b19c85
commit
19cdbec4e1
2 changed files with 8 additions and 1 deletions
|
@ -8,6 +8,7 @@ def main() -> None:
|
||||||
solution = solve(
|
solution = solve(
|
||||||
Board.default_puzzle,
|
Board.default_puzzle,
|
||||||
lambda state: state.solution_class == (3, 1, 2),
|
lambda state: state.solution_class == (3, 1, 2),
|
||||||
|
# shuffle=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if solution is None:
|
if solution is None:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import random
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from .board import Board
|
from .board import Board
|
||||||
|
@ -8,6 +9,7 @@ def solve(
|
||||||
is_solved: Callable[[Board], bool],
|
is_solved: Callable[[Board], bool],
|
||||||
*,
|
*,
|
||||||
history: list[tuple[int, Board]] | None = None,
|
history: list[tuple[int, Board]] | None = None,
|
||||||
|
shuffle: bool = False,
|
||||||
) -> list[tuple[int, Board]] | None:
|
) -> list[tuple[int, Board]] | None:
|
||||||
|
|
||||||
if history is None:
|
if history is None:
|
||||||
|
@ -17,7 +19,11 @@ def solve(
|
||||||
if is_solved(state):
|
if is_solved(state):
|
||||||
return history
|
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
|
# try to click all buttons
|
||||||
next = state.click(button)
|
next = state.click(button)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue