In FreeCell, every card is visible, which makes it a good game for a computer to search for solutions. This article gives a gentle look at how a computer solves FreeCell. For this page, we made a program that runs under the same rules as the FreeCell app and tried it out.

Search: Try a Move and Look Ahead

A computer, like a person, checks “what happens if I make this move?” The difference is how many it checks.

  1. Write out every move you can make on the current board (put a card in a free cell, stack it in the tableau, send it to a home cell, and so on).
  2. Make one of the moves to create a new board.
  3. On that board, write out every move you can make again.
  4. When you find a board with all 52 cards on the home cells, the moves that led there are the answer.

Following boards one after another, branching out as you go, is called search.

Trick 1: Don’t Check the Same Board Twice

In FreeCell, different orders of moves often lead to the same board. Move a card to the right and then back to the left, and you are back at the original board. If you remember the boards you have checked and skip any that come up again, you waste far less effort.

Also, boards that differ only in the order of the columns, or boards that differ only in the arrangement inside the free cells, are solved in the same way. Treating those as the same board cuts down the number you have to check even more.

Trick 2: Check Promising Boards First

Checking every board in order would take far too long. So you give boards scores, such as “many cards on the home cells,” “few cards on top of the next card to send to a home cell,” and “free cells are empty,” and check the promising boards first.

When we had this page’s program solve Windows deal number 1, it found a 110-move solution after checking 843 boards. It would be hard for a person, but it takes a computer an instant. The solution it finds isn’t always the shortest (Move Count and Moves to Clear).

Confirming a Deal Is Unsolvable

If you find a solution, the deal can be solved. So how do you confirm that it can’t be solved?

The answer is to check every board you can reach. If no move leads to a new board anymore, and still none of the boards has all 52 cards built up, you know the deal can’t be solved.

Windows FreeCell deal 11982 is known as an unsolvable deal. In this page’s program too, even after checking every reachable board (about 95,000), including moves back from the home cells, there was no solution to number 11982 (Almost Every FreeCell Deal Can Be Solved).

The Rule for Moving Several Cards Doesn’t Affect Whether a Deal Can Be Solved

In the FreeCell app, you can move up to “the number of empty free cells plus one” cards in one move, and an empty column doesn’t increase that (How Many Cards You Can Move at Once). But a move of several cards can be broken down into one-card moves using the free cells and empty columns. The reachable boards are the same, so the deals that can be solved are the same. Only how moves are counted changes.

Checking the Deals in the FreeCell App

The deals in the FreeCell app are shuffled and dealt at random every time. The author had a computer solve 100,000 random deals, then actually played each solution out to the end with the same game mechanics as the app. All 100,000 deals had a solution.

This is not a proof, though, that “every deal can be solved.” There remains a possibility that a few unsolvable deals are among the ones we didn’t check.

The way of thinking behind solving also helps when people play. Try Strategy and Winning Methods in FreeCell too.