|
|
|
|
|
|
|
// Precondition:
// numberOfShuffles is assigned
// Postcondition:
// After deck has been shuffled numberOfShuffles times,
// all cards have been moved one at a time from deck to onTable
// && Cards have (possibly) been moved from onTable to discardPile
// according to the rules of the game
// && won == TRUE, if the game was won
// == FALSE, otherwise
{
CardType tempCard; // Temporary card
deck.Shuffle(numberOfShuffles);
while (deck.Length() > 0)
{
deck.RemoveTop(tempCard);
onTable.InsertTop(tempCard);
TryRemove();
}
won = (onTable.Length() == 0);
deck.Recreate(onTable, discardPile);
}
//******************************************************************
void Player::TryRemove()
// If the first (top) four cards in onTable are the same suit,
// they are moved to discardPile. If the first card and the fourth
// card are the same suit, the second and third cards are moved from
// onTable to discardPile. This process continues until no further
// moves can be made
// Precondition:
// Length of onTable > 0
// Postcondition:
// Cards have (possibly) been moved from onTable to discardPile
// according to the above rules
{
Boolean moveMade = TRUE; // True if a move has been made
while (onTable.Length() >= 4 && moveMade)
if (onTable.CardAt(1).suit == onTable.CardAt(4).suit)
// A move will be made |
|
|
|
|
|