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


char    Deck(52);               \card structure (low 2 bits = suit)
def     Players = 4;            \number of players to deal to
char    Hand(Players, 52);      \each player's hand
int     Card, N, I, J, T;
char    Suit, Royal;
[for Card:= 0 to 52-1 do        \make a new deck
        Deck(Card):= Card;
for N:= 0 to 10000 do           \shuffle the deck
        [I:= Ran(52);  J:= Ran(52);
        T:= Deck(I);  Deck(I):= Deck(J);  Deck(J):= T;
        ];
for N:= 0 to 52-1 do            \deal from the deck
        [Card:= Deck(N);
        I:= N/Players;
        J:= rem(0);
        Hand(J, I):= Card;
        ];
Suit:= "HDCS ";                 \print each player's hand
Royal:= "JQK ";                 \ (= contents of the deck)
for J:= 0 to Players-1 do       \e.g: 2D 3C 10C AS KD
    [for I:= 0 to 52/Players -1 do
        [Card:= Hand(J, I);
        N:= Card>>2 + 1;        \pip value
        if N = 1 then ChOut(0, ^A)
        else if N >= 11 then ChOut(0, Royal(N-11))
        else IntOut(0, N);
        ChOut(0, Suit(Card&3));
        ChOut(0, ^ );
        ];
    CrLf(0);
    ];
]