//
//  deck.java
//  cribbage
//
//
import java.util.Random;
public class Deck {

	static final int numCards = 52;

	private Card[] deck;
	private int top;
	
	// Constructor
	public Deck() {
		deck = new Card[numCards];
		for (int suit = 0; suit < 4; suit++)
			for (int rank = 1; rank < 14; rank++)
				deck[13*suit+(rank-1)] = new Card(suit,rank);
		top = 51;
	}
	
    public void shuffle() {
		// Put all the used cards back into the deck, and shuffle it into a random order.
        for ( int i = 51; i > 0; i-- ) {
            int rand = (int)(Math.random()*(i+1));
            Card temp = deck[i];
            deck[i] = deck[rand];
            deck[rand] = temp;
        }
        top = 51;
    }
	
	public Card getCard() {
		// "Deals" one card from the deck. Card is not removed from the deck
		return deck[top--];
	}
	
	public Card cut() {
		// "Cuts" the deck and sets a new top card
		top = (int)(Math.random()*(top+1));
		System.out.print("\n The "+deck[top].display());
		System.out.println(" was cut from the deck.\n");
		return deck[top];
	}


}
