< previous page page_1103 next page >

Page 1103
PlayGame (In: numberOfShuffles; Out: won)
deck.Shuffle(numberOfShuffles)
WHILE more cards in deck
  // Turn up a card
  deck.RemoveTop(tempCard)
  onTable.InsertTop(tempCard)
  // Try to remove it
  TryRemove()
Set won = (onTable.Length() equals 0)
deck.Recreate(onTable, discardPile)

TryRemove ()
To remove cards, we first need to check the first and fourth cards. If these do not match, we can't move any cards. If they do match, we check to see how many can be moved. This process continues until there are fewer than four cards face up on the table, or until no move can be made.
Set moveMade = TRUE
WHILE onTable.Length() >= 4 AND moveMade
 IF suit of onTable.CardAt(1) matches suit of onTable.CardAt(4)
    IF suit of on Table.CardAt(1) matches suit of onTable.CardAt(2) AND
            suit of onTable.CardAt(1) matches suit of onTable.CardAt(3)
       Move four cards from onTable to discardPile
    ELSE
       Move two cardsthe second and thirdfrom onTable to discardPile
 ELSE
   Set moveMade = FALSE

 
< previous page page_1103 next page >