Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions solitaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -248,3 +248,4 @@ def interactive_mode():

# Uncomment to enable interactive mode
# interactive_mode()