Simple Solitaire Game: Canfield
source: Katrin Becker, 2001
-
[HELP]
- Write a program that will allow you to play solitaire. Since we are not yet ready to deal with animation or fancy graphics the "display" will be entirely text based and each play will require that the "screen" be re-drawn.
-
- Web-Based Canfield Game(s):
- http://games.demo.ru/Cards/Canfield.exe
-
- Quick Jump to elsewhere on this page....
- Game Description
- Implementation Hints
- The Display
- Testing and Notes on Marking
- Bonuses
-
- Cards may be represented as follows:
-
- C = Clubs; S = Spades; D = Diamonds; H = Hearts
- A = Ace; 2-9 as themselves; T= 10; J = Jack; Q = Queen; K = King
-
- This way every card can be represented in 2 characters. The most straight-forward way to represent a deck internally is using the integers 0-51. Each number can easily be mapped onto a suit { C, S, D, H } and a rank { A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K }. Each Pile of cards is to be implemented as a proper stack.
-
- There is a working version of this Solitaire Game in the course directory (/home/233). You are free to play with it. It is called canfield.
-
- A minimal acceptable solution will NOT check whether requests or requested moves are legal.
-
- The variation of Solitaire you are to implement is a relatively simple one using one deck of cards and in most cases allowing only one card to move at a time.
-
- Our version will look much like this:
- Reserve: D4 SCORE: 1 BASE RANK: K
Waste: DJ 1 2 3 4
-- -- -- --
DK :: FOUNDATIONS
:: TABLEAUS
DQ C8 D3 CT
- Options:
- P: play new game
M: move <s> <s#> <d> <d#>
S: shift cards <s#> <d#>
D: deal
H: help
Q: quit
- Request: t
-
- Canfield
- This game gets its name from a famous gaming house in New York.
Layout - Thirteen cards are counted from the deck, and placed face up in a pile on the left to form the stock. One card is dealt above and to the right of the stock for the first foundation. Four cards are dealt in a row to the right to form the tableau.
Foundations - As they become available, move the other three cards with the same rank as the first foundation to the foundation row. Build up the foundations in suit until each pile contains 13 cards.
Play - Build the tableau cards downward on each other, alternating colors. An entire pile must be moved as a unit. All top cards of the piles are available to be played except into spaces. From the stock, spaces are filled at once. The top card from the stock is available to be played on foundations or built on the tableau piles. Tableau spaces can be filled from the wastepile or the hand after the stock is exhausted. In this case, the tableau spaces may be kept open until you wish to use available cards.
Wastepile - Turn cards up in groups of three from the hand without altering the order. Place these cards face up on a single wastepile. The top card of this wastepile is available to be used on foundations or the tableau.
Redeal - Redealing by sets of three can be done endlessly until the game is won or comes to a standstill.

- Implementation Hints:
- 1. Each 'location' (stack) must be identifiable.
- 2. Need to be able to detect an empty stack.
- 3. Only one card at a time may be moved, unless we are moving an entire stack.
- 4. The Wastepile is also a stack.
- 5. The Hand must be represented internally but need not be displayed - we can't look ahead in the hand pile anyway.
- 6. The Hand can only be used for dealing (always 3 cards at a time).
- 7. The Wastepile can be used both for discarding (3 at a time) and for taking cards to move to the tableau or foundations.
- 8. Tableaus can serve as both sources and destinations.
- 9. The Reserve Pile and the Waste Pile may only be sources.
- 10. Foundations may only be destinations.
-
- Display:
- The display consists of the Reserve Pile, the Waste Pile, 4 stacks in the Foundations, and 4 stacks in the tableau. In all "piles" except the tableaus, only the top card need be visible. In the tableaus all cards should be visible but only the top card is available for play.
-
- User Options:
- Play (i.e. start again); command: p
- Move a card from source to destination; command: m <s> < s#> <d> <d#>
- Shift (move an entire stack from one tableau to another); command: s <s#> <d#>
- Deal (deal the next 3 cards; command: d
- Help (display the rules); command: h
- Quit (end game); command: q
-
- Note: <s> means one of the source piles: Waste Pile, Reserve Pile, Tableaus
- If the source is T, then it must be followed by a number <s#> from 1-4 identifying which tableau
- <d> means one of the destinations: Tableaus, or Foundations, which must also be followed by a number <d#> 1-4 identifying which one you mean.
-
- Testing:
- Run at least one game to completion (including invalid commands and bad arguments to commands). Since this is difficult to do with random deals, add a "hidden feature" to your program called test (user option t). This should not appear in the help menu, but when the user enters t the game should initialize the Hand to a pre-determined order of the cards and set up the game using that instead of a random shuffle.
-
- Notes on Marking:
- We will be looking for the usual good, clean design; documentation, etc. as always.
- In order to pass it must work. (Some marks will be given to all *reasonable* attempts, working or not)
- Specifics we will be looking for when marking:
- - menu-driven (like sample solution; format may be different)
- - external documentation not necessary but must have "Help" option in menu
- - uses pre-determined hand as well as a random one
- - test wrap-around on the Foundations (so King can be placed on Ace as appropriate)
- - uses Stacks for Tableaus, Foundations, Waste, Reserve, and Hand
- - able to move a stack from on Tableau to another
- - detects (and denies) attempt to take a card off an empty stack
- - shuffles deck in a reasonable manner
- - use of global stacks, score, rank of 1st foundation is OK
- - if we are still submitting on paper, make sure the testing is well-annotated
-
- Sample Run: (this goes through an entire game)
-
- BONUSES:
- 1. [3 points] check for and deny requests for invalid moves (invalid source/destination)
- 2. [3 points] check for and deny requests for illegal moves (trying to move from a Foundation, to the Waste Pile, etc. - NOTE: most of the other illegal moves are already checked in canfield_moves)
- 3. [4 points] check for and deny invalid requests (request typed wrong: eg. S T1 T2 when it should be S 1 2)
- 4. [5 points] use classes for stacks, cards, decks
- 5. [4 points] have the game detect a winning state and print out an appropriate message