/**
 * A class that represents standard decks of cards.
 * @author Derek Bridge 666 d.bridge@cs.ucc.ie
 */
public class Deck
{
/* =======================================================================
       CONSTRUCTORS
   =======================================================================
*/
    /**
     * Allocates a new, standard deck of 52 cards.
     */
    public Deck()
    {   cards = new Card[DENOMINATIONS.length * SUITS.length];
        int cardPosn = 0;
        for (int i = 0; i < DENOMINATIONS.length; i++)
        {   for (int j = 0; j < SUITS.length; j++)
            {   cards[cardPosn] = new Card(
                    DENOMINATIONS[i], SUITS[j], VALUES[i]);
                cardPosn++;
            }
        }
    }

/* =======================================================================
       PUBLIC INTERFACE
   =======================================================================
*/

/* --Getters----------------------------------------------------------- */

    /**
     * Deals a number of cards to a player from the deck.
     * @param theNumOfCards the number of cards to deal.
     * It is left to client code to make sure that this is a positive
     * number and not too big.
     * @param thePlayer the player to whom we are dealing.
     */
    public void dealNCards(int theNumOfCards, Player thePlayer)
    {   for (int i = 0; i < theNumOfCards; i++)
        {   thePlayer.receive(cards[howFarThrough]);
            howFarThrough++;
        }
    }

/* --Setters----------------------------------------------------------- */

    /**
     * Shuffles the deck.
     */
    public void shuffle()
    {   for (int i = 0; i < cards.length; i++)
        {   int j = (int) (Math.random() * cards.length);
            Card temp = cards[j];
            cards[j] = cards[i];
            cards[i]= temp;
        }
        howFarThrough = 0;
    }

/* =======================================================================
       INSTANCE VARIABLES & CLASS VARIABLES
   =======================================================================
*/
    /**
     * The cards in the deck.
     */
    private Card[] cards;

    /**
     * An index that points to a position within the pack.
     * It is incremented whenever a card is dealt from the deck.
     * So this is like a pointer to the card that is on the top 
     * of the deck on the assumption that all cards prior to this 
     * position have been dealt.
     */
    private int howFarThrough;

    /**
     * The permissible card denominations.
     */
    private static final String[] DENOMINATIONS =
        {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", 
         "Eight", "Nine", "Ten", "Jack", "Queen", "King"};

    /**
     * The permissible card suits.
     */
    private static final String[] SUITS =
        {"Clubs", "Diamonds", "Hearts", "Spades"};

    /**
     * The values of the cards of different denominations.
     */
    private static final int[] VALUES =
        {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
}
