According to John Dvorak of PC Magazine, 23, 6, p. 51:
People talk about changing platforms. They promote Mac and Linux as vaguely better than Windows ... In fact when I analyze the list [of reasons to switch] carefully, only games stand above the rest -- giving Windows a genuine edge.

You and a group of friends have recognized this phenomena and formed a (garage-based) company devoted to bringing computer games, primarily RPGs, to the Linux platform. You expect to be on the leading edge of a breakthrough of the Linux platform on the desktop, and hope to establish a dominant position in the market.

Recently, your company has been approached by several Linux distributors who have learned of your plans. They would like you to form a small team to develop several simple games that they would bundle with the retail CD version of their distributions. Although you will get only a nominal sum per CD sale, the cash flow to your company would be substantial. Your company is anxious for the cash flow until the sales of the RPGs can begin. Because of your software design skills, you have been chosen to lead this development.

As a demo, you are to first develop a version of the card game Freecell.


The game requires a standard deck of 52 unique cards. Both suits and ranks are important. Ace is low only.

There are three groups of piles. The cards in all piles are face-up. These piles are:

A game begins with all cards being dealt randomly to the 8 tableau piles from left to right, bottom to top. The leftmost 4 tableau piles should have 7 cards; the rightmost 4 piles should have 6 cards.

The objective of the game is to move all the cards from the tableau piles to the homecell piles, using the freecell piles as scratch space.

Game Rules

Moving a card from one pile to another is viewed as a single, atomic action. However, for the purposes of stating the rules, it is viewed as taking a card from pile A, subject to the taking rule for A, and putting the card onto pile B, subject to the putting rule for B. Note that in the game of Freecell, piles behave like stacks, so taking is a pop and putting is a push.

The game terminates when either all cards have been successfully moved to the homecell piles (a win) or the player quits (a loss).

Dealing the Cards

You must deal the cards so that you get the same deals I do, thus simplifying grading. For this purpose a deck class is provided for dealing the cards, although you may have to modify the parameters to the Card constructor. Other modifications are permitted so long as you do not modify the sequence in which cards are returned.

Here is a deal of the cards with the top tableau card on the left.

nj> java Freecell 876

Freecell 0:
Freecell 1:
Freecell 2:
Freecell 3:

Homecell 0:
Homecell 1:
Homecell 2:
Homecell 3:

Tableau 0: AD  QH  2C  KD  KC  9D  JH
Tableau 1: 5D  JS  6D  8H  QS  3D  2H
Tableau 2: 6H  8C  QC  4S  10H  2D  3H
Tableau 3: 8S  4C  8D  4H  KH  7C  10D
Tableau 4: KS  QD  3C  AS  10C  10S
Tableau 5: 7D  4D  AH  JC  5S  5H
Tableau 6: 9H  AC  9C  2S  6C  7S
Tableau 7: 9S  5C  3S  7H  JD  6S


A set of card images is provided as a zip archive, which should be installed in your project directory and unzipped. This will create a subdirectory named cards/ which contains the card images. Leave that structure intact so that you do not have to turn in card images with your project.

You will not be allowed to submit and use your own deck of cards. If you want cards/images added, you must email them to me and I will add them to everyone's deck.

How To



The game is invoked by:
java  Freecell  [ seed ]
where seed is an optional initial random number seed used to initialize Deck. Hint: that allows us to test your programs using the same card game.

GUI References

Freecell References

Robert Noonan
Mar 6, 2007