From a624a06f82e7c679af1c3e20b3a189b68e372497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6lfer?= Date: Wed, 12 Feb 2020 01:49:16 +0100 Subject: [PATCH] Windows fixes --- shenzhen_solitaire/clicker/main.py | 1 + shenzhen_solitaire/solver/board_possibilities.py | 2 +- shenzhen_solitaire/solver/solver.py | 2 +- tools/assistant.py | 14 +++++++------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/shenzhen_solitaire/clicker/main.py b/shenzhen_solitaire/clicker/main.py index 9fe0009..9089c27 100644 --- a/shenzhen_solitaire/clicker/main.py +++ b/shenzhen_solitaire/clicker/main.py @@ -114,6 +114,7 @@ def handle_actions( ) -> None: automatic_count = 0 for action in actions: + print(action) if automatic(action): automatic_count += 1 else: diff --git a/shenzhen_solitaire/solver/board_possibilities.py b/shenzhen_solitaire/solver/board_possibilities.py index 73c8231..d6259c0 100644 --- a/shenzhen_solitaire/solver/board_possibilities.py +++ b/shenzhen_solitaire/solver/board_possibilities.py @@ -130,7 +130,7 @@ def possible_goal_move_actions( if not (card.number == search_board.getGoal(card.suit) + 1): continue obvious = all( - search_board.getGoal(other_suit) >= search_board.getGoal(card.suit) + search_board.getGoal(other_suit) >= card.number - 1 for other_suit in set(board.NumberCard.Suit) - {card.suit} ) yield board_actions.GoalAction( diff --git a/shenzhen_solitaire/solver/solver.py b/shenzhen_solitaire/solver/solver.py index aaa7e33..83caabe 100644 --- a/shenzhen_solitaire/solver/solver.py +++ b/shenzhen_solitaire/solver/solver.py @@ -87,7 +87,7 @@ def solve( count = 0 print(f"{time.time() - iter_start} {len(stack)} {board.goal}") if timeout is not None and time.time() - iter_start > timeout: - raise StopIteration + return # _limit_stack_size(80) diff --git a/tools/assistant.py b/tools/assistant.py index 971816a..1b310a4 100644 --- a/tools/assistant.py +++ b/tools/assistant.py @@ -18,6 +18,7 @@ NEW_BUTTON = (1900, 1100) def solve() -> None: with tempfile.TemporaryDirectory() as screenshot_dir: + print("Taking screenshot") screenshot_file = Path(screenshot_dir) / "screenshot.png" screenshot = pyautogui.screenshot(region=(*OFFSET, *SIZE)) screenshot.save(screenshot_file) @@ -27,18 +28,17 @@ def solve() -> None: conf = configuration.load("test_config.zip") board = parse_board(image, conf) assert board.check_correct() - try: - solution = list(next(solver.solve(board, timeout=10))) - except StopIteration: + solution_iterator = next(solver.solve(board, timeout=10), None) + if solution_iterator is None: clicker.click(NEW_BUTTON, OFFSET) time.sleep(10) return + solution=list(solution_iterator) print(f"Solved in {len(solution)} steps") - for step in solution: - print(step) - clicker.handle_action(step, OFFSET, conf) + clicker.handle_actions(solution, OFFSET, conf) + time.sleep(2) clicker.click(NEW_BUTTON, OFFSET) - time.sleep(10) + time.sleep(7) def main() -> None: