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


NB. playingcards.ijs
NB. Defines a Rosetta Code playing cards class
NB. Multiple decks may be used, one for each instance of this class.
 
coclass 'rcpc'    NB. Rosetta Code playing cards class
 
NB. Class objects
Ranks=: _2 ]\ ' A 2 3 4 5 6 7 8 910 J Q K'
Suits=: ucp '♦♣♥♠'
DeckPrototype=: (] #: i.@:*/)Ranks ,&# Suits
 
NB. Class methods
create=: monad define
 1: TheDeck=: DeckPrototype
)
 
destroy=: codestroy
 
sayCards=: ({&Ranks@{. , {&Suits@{:)"1
 
shuffle=: monad define
 1: TheDeck=: ({~ ?~@#) TheDeck
)
 
NB.*dealCards v Deals y cards [to x players]
NB. x is: optional number of players, defaults to one
NB. Used monadically, the player-axis is omitted from output.
dealCards=: verb define
 {. 1 dealCards y
:
 'Too few cards in deck' assert (# TheDeck) >: ToBeDealt=. x*y
 CardsOffTop=. ToBeDealt {. TheDeck
 TheDeck    =: ToBeDealt }. TheDeck
 (x,y)$ CardsOffTop
)
 
NB.*pcc v "Print" current contents of the deck.
pcc=: monad define
 sayCards TheDeck
)
 
newDeck_z_=: conew&'rcpc'