Recent

Author Topic: Anti "churning" in solitaire card games  (Read 328 times)

TBMan

  • Sr. Member
  • ****
  • Posts: 346
Anti "churning" in solitaire card games
« on: January 20, 2026, 07:39:56 pm »
I have a 2 deck solitaire game I'm finishing up (German Solitaire). For my "check for lost game" procedure I implemented a simple anti churning device, that isn't all that elegant, but it works. (I will do a full A.I. game completion procedure that will replace this, but for now the solution was simple.)  So we have a deck of 104 cards. When the deck is first created, the card record type, in addition to suit and rank, has a card index integer. Each card is given a unique identification number which is in the 1 to 104 range. When during the game, the deck has been fully cycled (two cycles per game) and the discard stack has all of the deck cards other than what is on the table (deck count = 0 and deck cycle = 0) then the code tracks what moves are made. If a card is moved from one card to another, it tracks it by what the card above it was and counts how many times the card was removed from below it.
Code: Pascal  [Select][+][-]
  1. var
  2.   checklist:array[1..104] of byte;
  3.  
  4. // and then in the code
  5.  
  6. inc(checklist[cardabove.cardindex]);
  7.  
  8.  

Then, if the move count exceeds a given amount (I used 3) for a topcard/bottomcard pairing, then if there weren't any other valid moves the game is over. There are other things that have to be done to ensure that the check for loss only happens after a card is moved though. You don't want the check for loss procedure called in every game loop.  I just used a move made boolean that gets set as true when a move is made and in the check for loss procedure, if move made is true then move made is set to false, and then it does its thing.

The check for loss procedure in a solitaire game really has to be a full blown auto complete of the game.  If it fails, the game is over.
Barry

Newest game (clone),
Missile Commander:
https://www.youtube.com/watch?v=tgKz0cxog-k

andersonscinfo

  • Full Member
  • ***
  • Posts: 156
Re: Anti "churning" in solitaire card games
« Reply #1 on: January 20, 2026, 08:37:14 pm »
Quote
The check for loss procedure in a solitaire game really has to be a full blown auto complete of the game. If it fails, the game is over.

TBMan, your anti-churning approach is quite clever for detecting repetitive moves in German Solitaire! The idea of tracking card movements using checklist[cardabove.cardindex] to detect when the same card pairings repeat more than 3 times is a practical heuristic that prevents infinite loops.

However, you're absolutely right that a complete solution requires a full AI auto-complete algorithm. Your current approach works well as an interim solution, but here are some suggestions to refine it:

Code: Pascal  [Select][+][-]
  1. // Enhanced version with move tracking
  2. var
  3.   checklist: array[1..104] of byte;
  4.   previousGameStateHash: cardinal; // To detect broader state repetition
  5.   moveHistory: array[1..10] of record // Track last 10 moves
  6.     cardMoved, destination: integer;
  7.   end;
  8.   moveCount: integer;
  9.  

For the full AI solution you mentioned, consider implementing a breadth-first search that explores all possible moves from the current position. If the search exhausts all possibilities without reaching a winning state, then the game is truly lost.

Your approach of only checking after moves (moveMade boolean) is smart - it prevents unnecessary computation during idle game loops. The key insight is that you're essentially creating a finite state machine that detects when the game enters a repetitive cycle without progress.

For German Solitaire specifically, you might also want to track tableau pile states to detect broader positional repetitions, not just individual card movements.

TBMan

  • Sr. Member
  • ****
  • Posts: 346
Re: Anti "churning" in solitaire card games
« Reply #2 on: January 21, 2026, 04:30:05 pm »
Thanks Andersonscinfo!  I'm working on Applegate solitaire at the moment (tough game to win). I will revisit German Solitaire and see what I can do with the auto completion.
Barry

Newest game (clone),
Missile Commander:
https://www.youtube.com/watch?v=tgKz0cxog-k

 

TinyPortal © 2005-2018