CSC 221: Introduction to Programming
Fall 2011

HW6: Classes and Skip-3 Solitaire

Note: this assignment must be completed individually (with no student collaboration), and late submissions will not be accepted.

For this assignment, you are to complete a Python project for playing Skip-3 Solitaire. In Skip-3 Solitaire, cards are dealt one at a time from a standard deck and placed in a row. If the rank or suit of a card matches the rank or suit either one or three cards to its left, then that card (and any cards in the pile beneath it) can be moved on top of the matching card. For example, suppose the three of clubs, five of hearts, nine of spades, and jack of hearts are initially dealt. They would be placed in a row, in left-to-right order, as shown below.

3C 5H 9S JH

If the next card dealt is the five of spades, then that card is placed to the right and is found to match the five of hearts three spots to its left. Thus, the player can move the five of spades on top of the five of hearts, shortening the row of cards. The consolidation of these piles then allows the nine of spades to match with the five of spades that is immediately to its left. Thus, the player can move the pile topped by the nine of spades on top of the five of spades, shortening the row even further. Pictorially, the consolidation steps are:

3C 5H 9S JH 5S 3C 5S 9S JH 3C 9S JH

Note that the addition of a single card can start a chain reaction in which many piles of cards, both to the left and right, are moved. The goal of the game is to end with as few piles of cards as possible. Theoretically, the game could end with a single pile of 52 cards, although that outcome is extremely unlikely. Also, note that only the top card in a pile needs to be stored, since the cards below it are never seen again.

  1. Download the cards.pytxt module and save it as This file contains the DeckOfCards class described in class, as well as the framework for the RowOfCards class. The RowOfCards class is intended to model the behavior of a row of cards, allowing the user to add to the row or to move a card on top of a matching one. Implement the methods of the RowOfCards class, noting that illegal moves (e.g., attempting to move off the end of the row or attempting to move onto a non-matching card) should result in a warning message and no change in the row. Test your code thoroughly before proceeding on to the Skip-3 solitaire game.
  2. Download the skip3.pytxt module and save it as This file contains the skip3 function, which allows the user to play a very basic, interactive game of Skip-3 solitaire (using DeckOfCards and RowOfCards objects). Once you have tested this basic version of the game, make the following improvements. Your game should be forgiving with respect to capitalization and should produce readable output, similar to the game transcript in skip3out.txt.
  3. For extra credit, you may add other features to the game that improve its functionality and/or appearance.