### CSC 221: Computer Programming I Fall 2005 HW6: Object-Oriented Design and Skip-3 Solitaire

For this assignment, you are to define a Java class named Skip3 that enables the user to play 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. Thus, your class should utilize an ArrayList of Cards to store the tops of the piles.

Your class should provde the following functionality:

• It should start with shuffled deck and empty row of cards (utilizing the Card and DeckOfCards classes).
• Methods should be defined so that the user can deal a card (placing it at the end of the row) or move a card (replacing the card one or three spots to the left).
• If the user attempts an illegal deal (the deck has been exhausted or there are moves that can be made), then an error message should be displayed and the deal attempt ignored.
• If the user attempts an illegal move (the cards don't match or the distance is not 1 or 3 spots), then an error message should be displayed and the move attempt ignored.
• The row of cards should be displayed after each deal or move.
• Methods should also be defined to allow the user to access the length of the row and the number of cards remaining in the deck.