import java.util.Random;

/**
 * A basic class to handle dealing and shuffling cards from one or more decks of cards
 * 
 * @author dave
 */
public class CardDealerBoolean{
	private static final int NUM_CARDS = 52;  // the number of cards in the deck
	
	private boolean[] cards;  //all of the cards available.  If it's true, it hasn't been dealt yet.

	public static void main(String[] args){
		CardDealerBoolean dealer = new CardDealerBoolean(1);
				
		for( int i = 0; i < 100; i++ ){
			System.out.println(dealer.next());
		}
	}
	
	/**
	 * Creates a new card dealer with numDecks decks in the deck
	 * 
	 * @param numDecks the number of card decks to use
	 */
	public CardDealerBoolean(int numDecks){
		cards = new boolean[numDecks*NUM_CARDS];
		setAllTrue();
	}
	
	private void setAllTrue(){
		for( int i = 0; i < cards.length; i++ ){
			cards[i] = true;
		}
	}
	
	/** 
	 * Returns true if there are cards left in the deck, false otherwise
	 */
	public boolean hasNext(){
		boolean available = false;
		
		for( int i = 0; i < cards.length && !available; i++ ){
			if( cards[i] ){
				available = true;
			}
		}
		
		return available;
	}
	
	/**
	 * Returns the next card randomly if there are cards left in the deck and returns -1 otherwise
	 */
	public int next(){
		if( hasNext() ){
			Random rand = new Random();
		
			int nextPosition;
		
			do{
				nextPosition = rand.nextInt(cards.length);
			}while( !cards[nextPosition] );
			
			// need to translate the card position into an actual card
			return nextPosition % NUM_CARDS;
		}else{
			// we're out of cards, we could throw an error, or we'll just return -1 for now
			return -1;
		}
	}
	
	/** 
	 * Resets the cards
	 */
	public void shuffle(){
		setAllTrue();
	}
}