From b38708786d85e9c9f33f10a380e5bea5dd5534e4 Mon Sep 17 00:00:00 2001 From: BoxDroppingManApe <38407729+BoxDroppingManApe@users.noreply.github.com> Date: Wed, 14 Jan 2026 11:15:31 -0800 Subject: [PATCH] Update solitaire.py I ran into a problem with the solver where, due to the way the solver removes complete stacks from the board, the slot would get reused in a way that the Molek-Syntez Solitaire game does not allow. I made a small change that fixes the problem. --- solitaire.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/solitaire.py b/solitaire.py index 17ec600..0e6a905 100644 --- a/solitaire.py +++ b/solitaire.py @@ -51,7 +51,7 @@ def remove_complete_stacks(self, board: List[List[int]], verbose: bool = False) if self.is_complete_stack(stack): if verbose: print(f" ✓ Complete stack removed: {[self.CARD_NAMES[c] for c in stack]}") - new_board.append([]) + # new_board.append([]) # this removes the column entirely. Not an ideal solution - I'd prefer it if the stack remained but was not interactable, or if there were an indicator that there was a complete stack in the slot. However, that's beyond my limited python knowledge else: new_board.append(stack[:]) return new_board @@ -79,7 +79,7 @@ def solve_without_cheating(self) -> Optional[List[Tuple[int, int, int]]]: board, moves = queue.popleft() board = self.remove_complete_stacks(board) - if all(len(stack) == 0 for stack in board): + if all(self.is_complete_stack(stack) or len(stack) == 0 for stack in board): # an alternate solution I was exploring. No longer necessary, but doesn't seem to hurt anything, and is a little more robust return moves for from_idx in range(len(board)): @@ -134,7 +134,7 @@ def visualize_solution(self, solution: Optional[List[Tuple[int, int, int]]]): board = self.remove_complete_stacks(board, verbose=True) self.print_board(board, f"After Step {step}") - if all(len(stack) == 0 for stack in board): + if all(self.is_complete_stack(stack) or len(stack) == 0 for stack in board): # see line 82 for explanation print("🎉 PUZZLE SOLVED! All stacks cleared!") else: print("⚠️ Warning: Board not fully cleared") @@ -248,3 +248,4 @@ def interactive_mode(): # Uncomment to enable interactive mode # interactive_mode() +