-footer

garrettsmith.playingcards
Class CardContainer

java.lang.Object
  extended by garrettsmith.playingcards.CardContainer

public class CardContainer
extends java.lang.Object

Represents a collection of cards, typically comprised of one or more decks.

Since:
Blackjack v1.0
Version:
Blackjack v1.0
Author:
Garrett Smith, gsmith at northwestern dot edu

Constructor Summary
CardContainer(CardList cards)
          Creates an unshuffled container with its cards equal to the contents of cards.
CardContainer(Deck deck)
          Creates a shuffled container with its cards set to those of one deck.
CardContainer(Deck deck, int numDecks)
          Creates a shuffled container with cards from numDecks number of decks.
CardContainer(Deck deck, int numDecks, boolean shuffle)
          Creates a container with cards from numDecks number of decks; will be shuffled according to the value of shuffle.
 
Method Summary
 Card getCard()
          Removes and returns a single card from the container.
 boolean hasMoreCards()
          Returns whether this container has any cards left in it.
 boolean isAutoResetOn()
          Returns whether or not auto reset is on.
 boolean isEmpty()
          Returns whether this container is empty.
 int originalSize()
          Returns the original size of this container.
 void reset()
          Resets this container with the original number and distribution of cards; does not re-shuffle (randomly re-order) the container and does not return the cards to their original order.
 void resetShuffle()
          Resets this container with the original number and type distribution of cards and re-shuffles (randomly re-orders) the cards.
 void setAutoReset(double percentage)
           Turns on auto reset, where the container is automatically reset AND reshuffled (radomly re-ordered) whenever the number of undealt cards falls below percentage percent the original number.
 void setAutoReset(int limit)
           Turns on auto reset, where the container is automatically reset AND reshuffled (radomly re-ordered) whenever the number of undealt cards falls below limit.
 void setAutoResetOff()
          Turns off auto reset.
 void shuffle()
           Shuffles (randomly orders) the contents of the container.
 int size()
          Returns the number of undealt cards in the container
 java.lang.String toString()
          Returns a string representation of this container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CardContainer

public CardContainer(Deck deck)
Creates a shuffled container with its cards set to those of one deck.

Parameters:
deck -

CardContainer

public CardContainer(Deck deck,
                     int numDecks)
Creates a shuffled container with cards from numDecks number of decks.


CardContainer

public CardContainer(Deck deck,
                     int numDecks,
                     boolean shuffle)
Creates a container with cards from numDecks number of decks; will be shuffled according to the value of shuffle.


CardContainer

public CardContainer(CardList cards)
Creates an unshuffled container with its cards equal to the contents of cards.

Method Detail

isAutoResetOn

public boolean isAutoResetOn()
Returns whether or not auto reset is on.

Returns:
true if auto reset is on, false if not.

getCard

public Card getCard()
Removes and returns a single card from the container. If both auto reset is on and the reset limit is reached then the container will be reset and shuffled.

Returns:
a card taken from the top of the container.
Throws:
NoMoreCardsException - if there are no more cards in the container and auto reset is not on.

hasMoreCards

public boolean hasMoreCards()
Returns whether this container has any cards left in it.

Returns:
true if the container has at least one card in it, false if not.

isEmpty

public boolean isEmpty()
Returns whether this container is empty.

Returns:
true if the container is empty, false if not.

reset

public void reset()
Resets this container with the original number and distribution of cards; does not re-shuffle (randomly re-order) the container and does not return the cards to their original order.


resetShuffle

public void resetShuffle()
Resets this container with the original number and type distribution of cards and re-shuffles (randomly re-orders) the cards.


originalSize

public int originalSize()
Returns the original size of this container.


size

public int size()
Returns the number of undealt cards in the container

Returns:
the number of undealt cards

setAutoReset

public void setAutoReset(double percentage)

Turns on auto reset, where the container is automatically reset AND reshuffled (radomly re-ordered) whenever the number of undealt cards falls below percentage percent the original number.

If this method is invoked after setAutoReset( int ), auto reset will still be on but will use a percentage threshold rather than threshold based on the absolute number of cards remaining.

Parameters:
percentage - the percent undealt cards left that must be reached before the deck is reset and reshuffled. Must be greater than 0 and less than or equal to 1.0.

setAutoReset

public void setAutoReset(int limit)

Turns on auto reset, where the container is automatically reset AND reshuffled (radomly re-ordered) whenever the number of undealt cards falls below limit.

If this method is invoked after setAutoReset(double), auto reset will still be on but will be triggered by the number of cards limit rather than a percentage limit.

Parameters:
limit - the number of undealt cards that the container that must have less than before the container is reset and reshuffled.

setAutoResetOff

public void setAutoResetOff()
Turns off auto reset.

See Also:
setAutoReset( int ), setAutoReset( double )

shuffle

public void shuffle()

Shuffles (randomly orders) the contents of the container.

This will not reset the container; only the undealt cards will be shuffled. Use resetShuffle() to both reset and shuffle the container.


toString

public java.lang.String toString()
Returns a string representation of this container.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the container.

-footer

Copyright 2001-5 Garrett Smith. Use is subject to license terms.