Accordion Solitaire

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




Problem Description

Write a program which allows users and the program to search for solutions to the game of Accordion Solitaire.

Background & Techniques

Accordion Solitaire is a solitaire card game

 for those who believe that the journey is more important than the destination. Winning is very difficult, probably less than 1 in 100 unless some strategy is applied.  Using the "Sweeper" strategy and examining all possible end-games for the last 12 moves, the program can win 10% to 20% of the time. 

Here are the rules:

Cards are dealt out one in a row, from left to right. Whenever a card matches its immediate neighbor to the left, or matches the third card to the left, it may be moved onto that card. Cards match if they are of the same suit or same rank. Game play continues until the deck runs out and the game is won if you can reduce the entire played deck to a single pile. Since no moves are mandatory, there's no disadvantage (and may be an advantage) to deal all the cards first and then make moves.

This program allows manual play and automates several strategies for program play. Manual (user) play is an option implemented by clicking on a source pile and then a valid destination pile.

For "program play", the program searches for a solution, Options are:

bullet... "Random" randomly selects one of the available valid moves for the currently available visible cards.
bullet... "Highest first" selects the move using the rightmost valid move source card.
bullet... "Sweepers" uses a strategy described on web page where a particular card rank that appears near the end of the displayed cards is selected as the "sweeper" value and the 4 cards with that value are moved whenever possible and are not overlaid until the end game.
bullet... "Sweepers with Heuristics" applies additional rules to improve the sweeper strategy. Currently there is only a single rule; to reduce end game time, the search is aborted when there is no matching suit or rank for any remaining card.

The "end game"requires some thought or the ability try lots of moves very fast. Computers are poor thinkers but can try things very rapidly, so this program uses an "exhaustive search" (try all possible moves) technique for the end game. It works for the last 15 or fewer moves. If more than 15 piles remain, then trying all possible moves would require minutes, hours, days, years, or centuries depending on the number of piles remaining.

For computational speed, the "auto-play" options do not display card images but use textual card identifiers (1-S for Ace of Spades, etc.)

Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.

Programmer's Notes:

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Additional heuristic rules. 
Additional options for selecting "sweeper" rank. 


Original:  mmmm dd, yyyy

Modified:  May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.