University of Calgary

canfield solitaire

Canfield Solitaire
source: Katrin Becker, 2001
The course directory /home/233/Solitaire contains a number of files that may be of some help or use:
StackStuff.cc
StackStuff.h
canfield_test.cc
canfield_test.h
canfield_moves.cc
canfield_moves.h
 
makefile
 
test.code
 
sample_run.txt
 
canfield
 
This program is probably the biggest and most complicated most of you have attempted to date. START EARLY. The keys to the successful completion of this assignment are:
Understanding the Problem: The assignment page contains, among other things, a link to a website that allows you to play the game of Canfield Solitaire. It differs from our version in 2 ways: first our version will deal 3 cards at a time while theirs only deals 1, and second, their version keeps score differently. Because it is so much easier to get an understanding of the game from one with reasonable graphics (ours will be very crude by comparisson), it is strongly recommended that you take some time to familiarize yourself with the game (it's not often you will be assigned to play solitaire as homework!!). Once you have learned how the game is played, try running the sample solution (./canfield) in the course directory. The "display" is harder to follow so knowing how the game is played beforehand will help.
 
Outlining the Solution: This program is complicated enough that it will be necessary to break it up into smaller, fairly self-contained tasks (such as "doing the display", "initializing a game", "doing one move", etc.). You must use stacks for the piles of cards, and with the exception of the routine(s) to do the display you are restricted to using only the pre-defined allowable stack operations. There are a number of modules that can be used by your program.
StackStuff.cc and StackStuff.h contain the stack operations as discussed in class.
 
canfield_moves.cc and canfield_moves.h contain one major routine that processes a request to move one card from one of the piles to another.
move ( char source, char dest, int sn, int dn );
- it uses a number of GLOBAL variables (the stacks primarily)
- source will be a character identifying the pile we want to move a card FROM and dest is a character identifying the pile we want to move the card TO. Tableaus and Foundations are implemented as arrays of stacks so if they are the source/dest, then a number is required (sn, dn, in the range 0-3) to identify which tableau or destination.
- you are not required to use this routine; you are free to use it only as a guide or ignore it altogether.
These files also contain a few minor routines that check the values of some arguments in the move request. Again you are free to use these if you wish but it not required.
 
canfield_test.cc and canfield_test.h: Usually the deck is to be shuffled randomly at the beginning of every game. This causes several problems in testing. One of them is that it becomes difficult to test the various parts of your program. The other is that you may end up playing for a long time before you find a hand that will win. To get around these problems a function has been provided that you can use to initialize the hand instead of using a random hand. It is the one shown in sample_run.txt. It tests just about everything and will run to completion. The one thing it doesn't test is the wrap-around feature for the foundations. You will have to do this yourself. This "feature" MUST be a part of your program. In the sample solution you may request the test hand by typing t . Notice that t is not one of the game options. It is a "hidden feature" known only to us and used for testing purposes. Realize that most hands of Solitaire are non-deterministic, meaning there's almost always more than one way to get from the beginning to an end. Not all ways result in a win. This function also exists as a simple function (test.code) that can be placed inside your main module.
 
Lastly, the course directory contains the makefile used by the instructor in her sample solution. You may use it as you see fit.
 
Except for the stack functions, this program may consist of just one module.
 
Implementing the Solution Piecemeal:
As you outline the tasks (functions) you will need, decide on the bare minimum to get a running program (for example, maybe just the display, and main) as each task is solved
compile and test it. That way the amount of untested code in your program will remain at a minimum.



Updated: August 9, 2005 05:43 PM