CPE 103 Individual Programming Project

You are to follow The Software Development Process to complete this project.  Complete the steps on paper where required.  You will be asked to show your work after finishing particular steps in the process.

Clock Solitaire

Clock Solitaire is a simple card game.  The cards are dealt out (face down) in a circle, representing a clock, with a pile in each hour position and an extra pile in the center of the clock. The first card goes face down on one o'clock, the next on two, and so on clockwise from there, with each thirteenth card going to the center of the clock. This results in thirteen piles, with four cards face down in each pile.

clock solitaire layout

The game then starts. The top card of the 'king' pile (the last card dealt) is exposed to become the current card. Each move thereafter consists of placing the current card face up beneath the pile corresponding to its value and exposing the top card of that pile as the new current card. Thus if the current card is an Ace it is placed under the 'one' pile and the top card of that pile becomes the current card. The game ends when the pile indicated by the current card has no face down cards in it. You win if the entire deck is played out, i.e. exposed.  The outcome is entirely up to chance, there is no skill other than placing cards in the correct piles.

Play online version.

You are to write a computer player that will determine the outcome of a Clock Solitaire game given a deck of shuffled cards, and return the results.

Input

The input data will be read from standard input and will contain one or more test cases.  Each test case contains a single line representing a shuffled deck of cards.  The first card is the top card on the deck.  The line consists of 52 2-letter card abbreviations, separated by one blank.  You may assume there are no duplicate cards, and all abbreviations are valid.

Output

For each test case, a single line of output is displayed on standard output.   The line contains two fields separated by a single blank.  The first field is a whole number representing the number of cards played during the game. The second field is a 2-letter card abbreviation of the last card played during the game.


Sample Input

2D 3C KC JS QC 5S KH 2H 3S 2C QH 8C TC QS 6D 5H TS 4H 7H 5D KD 4D AH 8S TH AC 4S 9C TD 3D 6C KS 4C 7C QD 3H 9S 7S AD AS JD 9H JC 8H 8D 7D 5C 6H 6S 9D 2S JH
9D 5D 9C KH QH 6H AH 3S AS 3H 8C 5S 9S 5C JC 9H 3D 7C 4D JD 8S KC JS TC 2S 6C TH TD 8H AD JH 5H 2C 4C TS 7D QD 8D 4S QC AC 2H 4H 6D 6S QS 3C KD KS 7S 2D 7H
2S AS 8H 3H TD 6S JH JC 4S 7D 5C 7C KS 2D AD 5S 4C QH 6H 9S 6C TS QD TH 7S KC 2C AC 3C 3S 9H QC 5H 4D 8C JS 8S 9D KH 2H AH QS 4H TC JD 3D 8D 7H 6D 9C 5D KD

Sample Output

52 KC
44 KC
4 KS

Design Tips

Recommended classes in the design:
Card - Represents a single playing card.
Deck - Represents a deck from which cards are dealt.
Pile - A pile of cards at one position on the "clock".  (Use a stack to represent a pile of cards).
Table - The playing area where the game takes place. It contains the deck and the 13 piles. The game logic is handled here.
ClockSolitaire - ALL the input/output for the application occurs here. Reads the input deck and displays the results computed by the Table.

Note that in your computer simulation of the game, it isn't actually necessary to place the current card face up on the bottom of a pile.  After identifying the target pile, you can simply discard the current card.  To determine end of game, simply check if the target pile is empty.
 
Write JUnit tests for the classes you create or modify, except for ClockSolitaire.

The application class containing the main method should be named ClockSolitaire
Example unix command:
java ClockSolitaire < decks   will produce this output.


Submit your work as described in the syllabus.