Task

Create a data structure and the associated methods to define and manipulate a deck of   playing cards.

The deck should contain 52 unique cards.

The methods must include the ability to:

   make a new deck
   shuffle (randomize) the deck
   deal from the deck
   print the current contents of a deck 
Each card must have a pip value and a suit value which constitute the unique value of the card.

Related tasks:

 Card shuffles
 Deal cards_for_FreeCell
 War Card_Game
 Poker hand_analyser
 Go Fish


      DIM Deck{ncards%, card&(51)}, Suit$(3), Rank$(12)
      Suit$() = "Clubs", "Diamonds", "Hearts", "Spades"
      Rank$() = "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", \
      \         "Eight", "Nine", "Ten", "Jack", "Queen", "King"
 
      PRINT "Creating a new deck..."
      PROCnewdeck(deck1{})
      PRINT "Shuffling the deck..."
      PROCshuffle(deck1{})
      PRINT "The first few cards are:"
      FOR card% = 1 TO 8
        PRINT FNcardname(deck1.card&(card%))
      NEXT
      PRINT "Dealing three cards from the deck:"
      FOR card% = 1 TO 3
        PRINT FNcardname(FNdeal(deck1{}))
      NEXT
      PRINT "Number of cards remaining in the deck = " ; deck1.ncards%
      END
 
      REM Make a new deck:
      DEF PROCnewdeck(RETURN deck{})
      LOCAL N%
      DIM deck{} = Deck{}
      FOR N% = 0 TO 51
        deck.card&(N%) = N%
        deck.ncards% += 1
      NEXT
      ENDPROC
 
      REM Shuffle a deck:
      DEF PROCshuffle(deck{})
      LOCAL N%
      FOR N% = 52 TO 2 STEP -1
        SWAP deck.card&(N%-1), deck.card&(RND(N%)-1)
      NEXT
      ENDPROC
 
      REM Deal from the 'bottom' of the deck:
      DEF FNdeal(deck{})
      IF deck.ncards% = 0 THEN ERROR 100, "Deck is empty"
      deck.ncards% -= 1
      = deck.card&(deck.ncards%)
 
      REM Return the name of a card:
      DEF FNcardname(card&)
      = Rank$(card& >> 2) + " of " + Suit$(card& AND 3)