To begin the game, 28 cards are dealt into seven piles. The leftmost pile has one card, the next two cards, and so forth, up to seven cards in the rightmost pile. Only the uppermost card of each of the seven piles is turned face up. The cards are dealt left to right, one card to each pile, dealing to one less pile each time, and turning the first card in each round face up. On the topmost face-up card of each pile you may build in descending sequences red on black or black on red. For example, on the 9 of spades you may place either the 8 of diamonds or the 8 of hearts. All face-up cards on a pile are moved as a unit and may be placed on another pile according to the bottommost face-up card. For example, the 7 of clubs on the 8 of hearts may be moved as a unit onto the 9 of clubs or the 9 of spades.
Whenever a face-down card is uncovered, it is turned face up. If one
pile is removed completely, a face-up king may be moved from a pile (together
with all cards above it) or the top of the waste pile (see below) into
the vacated space. There are four output piles, one for each suit, and
the object of the game is to get as many cards as possible into the output
piles. Each time an ace appears at the top of a pile or the top of the
stack, it is moved into the appropriate output pile. Cards are added to
the output piles in sequence, the suit for each pile being determined by
the ace on the bottom.
From the rest of the deck, called the stock, cards are turned up one
by one and placed face up on a waste pile. You may always play cards off
the top of the waste pile, but only one at a time. Begin by moving a card
from the stock to the top of the waste pile. If there is ever more than
one possible play to be made, the following order must be observed:
(a) Move a card from the top of a playing pile or from the top of the
waste pile to an output pile. If the waste pile becomes empty, move a card
from the stock to the waste pile.
(b) Move a card from the top of the waste pile to the leftmost playing
pile to which it can be moved. If the waste pile becomes empty, move a
card from the stock to the waste pile.
(c) Find the leftmost playing pile that can be moved and place it on
top of the leftmost playing pile to which it can be moved.
(d) Try (a), (b), and (c) in sequence, restarting with (a) whenever
a move is made.
(e) If no move is made via (a) through (d), move a card from the stock
to the waste pile and retry (a).
Only the topmost card of the playing piles or the waste pile may be
played to an output pile. Once played on an output pile, a card may not
be withdrawn to help elsewhere. The game is over when either all the cards
have been played to the output, or the stock pile has been exhausted and
no more cards can be moved.
When played for money, the player pays the house $52 at the beginning
and wins $5 for every card played to the output piles. Write your program
so that it will play several games and determine your net winnings. Use
a random number generator to shuffle the deck. Output a complete record
of two games in easily understood form. Include as output the number of
games played and the net winnings +1 or -l.