JOIN
 Problem Statement
Contest: Marathon Match 40
Problem: Klondike

Problem Statement

Klondike, more commonly known simply as solitaire, is a simple one-player card game. It is played with a standard single deck of cards. The rules of the game can be found at Wikipedia and an online version can be found (among other places) at World of Solitaire (it also ships with all Windows computers).

Your task in this problem is simple: write a program to play the game. For each game that you complete successfully, you will get one point, and 0 otherwise.

Each of the cards will be represented by two characters. The first will be a digit from 2-9, a 'T', 'J', 'Q', 'K' or 'A', representing the digit cards and tens, jacks, queens, kings, and aces. The second will be 'C', 'D', 'H', or 'S' for the four suits: clubs, diamonds, hearts and spades. The input to your method will define the stacks of cards in the playing area, the completed stacks, and the cards that are left to flip though. In addition, part of the input will be the current position in the cards that you flip through. A String[], stacks will contain 7 elements, each formatted as "DOWN CARD1 CARD2 CARD3...", where DOWN is an integer representing the number of face down cards in the stack CARD1 is the highest rank up card, CARD2 is on top of CARD1, and so on. A String[], deck, will give the cards left in the deck, where the first element is the top card of the deck. An int, position, will give the current position in the deck (the card that you could play out of the deck). Finally, a int[], completed will give the number of cards of each of the four suits that have been placed in the finished piles, in the order clubs, diamonds, hearts, spades.

For instance, the game depicted below would be represented by the input: stacks = {"0 TD", "0 KS", "1 QC", "2 4S", "3 4C 3D", "5 QS", "6 TS 9D 8C 7H"}

deck = {"AC", "5D", "6S", "TC", "QD", "7S", "KH", "5H", "JD", "6D", "2C", "8D", "4H", "JH", "3S", "5S", "5C", "AH", "9H", "9S", "4D", "6H"}

done = {0,0,0,2}

position = 5

There are two basic sorts of moves that you can make. The first is to advance the position in the deck. Typically this advances the position by three cards. The exception is when the end of the deck is reached, in which case the position is advanced to the last card. If the position is already at the last card, then it restarts at the third card. The second sort of move is to move one card or group of cards from one location to another. You can move one card from the deck to one of the stacks, or to one of the completed piles. You can move one card from one of the stacks to one of the completed piles. You can move one or more cards from one stack to another. Finally, you can move one card from a completed pile to a stack. If a face down card is ever on top of one of the stacks, it will be automatically turned over.

Your move method should return "ADVANCE" to advance the deck position (as described above). To move a card or group of cards from one location to another, you should return a String formatted as "SOURCE DESTINATION". SOURCE is the source location of the cards and should be either DECK, S1-S7 for the seven stacks, or C1-C4 for the four completed piles (in the order clubs, diamonds, hearts, spades). DESTINATION should be formatted the same way. Note that no more information is needed -- once the source and destination are selected, there is never more than one legal move. If you give up, you can return "DONE", indicating that you wish to make no more moves. You need not return "DONE" if you win the game.

A visualization tool is provided.

Definition

 Class: Klondike Method: move Parameters: String[], String[], int[], int Returns: String Method signature: String move(String[] stacks, String[] deck, int[] completed, int position) (be sure your method is public)

Notes

-If you remove card 0, the position will be automatically advanced to position 2.
-The example images depict the initial states of each of the games.
-When the deck is empty, position will be -1.

Constraints

-You have 20 seconds per game.
-The memory limit is 1024M.

Examples

0)

`seed = 1`
1)

`seed = 2`
2)

`seed = 3`
3)

`seed = 4`
4)

`seed = 5`
5)

`seed = 6`
6)

`seed = 7`
7)

`seed = 8`
8)

`seed = 9`
9)

`seed = 10`

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.