poker
Class Deck

java.lang.Object
  extended by poker.Deck

public class Deck
extends java.lang.Object

A Deck of 52 Cards which can be dealt and shuffled Some functions could be made much faster with some extra memory. I invite anyone to do so ;-)

Version:
1.0.5
Author:
Aaron Davidson

Field Summary
static int NUM_CARDS
           
 
Constructor Summary
Deck()
          Constructor.
Deck(long seed)
          Constructor w/ shuffle seed.
 
Method Summary
 int cardsLeft()
          Obtain the number of cards left in the deck
 void copy(Deck d)
           
 Card deal()
          Obtain the next card in the deck.
 Card dealCard()
          Obtain a random card from the deck.
 void extractCard(Card c)
          Remove a card from within the deck.
 void extractCard(int c_index)
          Remove a card from within the deck.
 void extractHand(Hand h)
          Remove all cards in the given hand from the Deck.
 Card extractRandomCard()
          Remove and return a randomly selected card from within the deck.
 int findCard(Card c)
          Find position of Card in Deck.
 int findCard(int c_index)
          Find position of Card in Deck.
 int findDiscard(Card c)
           
 Card getCard(int i)
          Obtain the card at a specific index in the deck.
 Card getTopCard()
          Get the first card in the deck
 int getTopCardIndex()
          Obtain the position of the top card.
 boolean inDeck(Card c)
          See if a card is in the deck, or if it has been dealt.
 Card pickRandomCard()
          Return a randomly selected card from within the deck without removing it.
 void replaceCard(Card c)
          Place a card back into the deck.
 void reset()
          Places all cards back into the deck.
 void setSeed(long seed)
          Sets the random seed for the deck if the seed is non-zero.
 void shuffle()
          Places all cards back into the deck and then shuffles the deck.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUM_CARDS

public static final int NUM_CARDS
See Also:
Constant Field Values
Constructor Detail

Deck

public Deck()
Constructor.


Deck

public Deck(long seed)
Constructor w/ shuffle seed. If the seed passed in is zero it is ignored and this would be equivalent to just calling the no parameter deck constructor. If the seed passed in is non-zero the deck is constructed as it would be with the no parameter constructor and then the deck's shuffle seed is set.

Parameters:
seed - the seed to use in randomly shuffling the deck.
Method Detail

copy

public void copy(Deck d)

setSeed

public void setSeed(long seed)
Sets the random seed for the deck if the seed is non-zero. If the seed is zero, it is ignored and the random seed remains unchanged

Parameters:
seed - seed the seed to use in randomly shuffling the deck.

reset

public void reset()
Places all cards back into the deck. Note: Does not sort the deck.


shuffle

public void shuffle()
Places all cards back into the deck and then shuffles the deck.


deal

public Card deal()
Obtain the next card in the deck. If no cards remain, a null card is returned

Returns:
the card dealt

dealCard

public Card dealCard()
Obtain a random card from the deck. If no cards remain, a null card is returned

Returns:
the card dealt

findCard

public int findCard(Card c)
Find position of Card in Deck.


findCard

public int findCard(int c_index)
Find position of Card in Deck.

Parameters:
c_index - index value of card

findDiscard

public int findDiscard(Card c)

inDeck

public boolean inDeck(Card c)
See if a card is in the deck, or if it has been dealt.

Parameters:
c - a card
Returns:
true if it is still in the deck

extractHand

public void extractHand(Hand h)
Remove all cards in the given hand from the Deck.


extractCard

public void extractCard(int c_index)
Remove a card from within the deck.

Parameters:
c - the card to remove.

extractCard

public void extractCard(Card c)
Remove a card from within the deck.

Parameters:
c - the card to remove.

extractRandomCard

public Card extractRandomCard()
Remove and return a randomly selected card from within the deck.


pickRandomCard

public Card pickRandomCard()
Return a randomly selected card from within the deck without removing it.


replaceCard

public void replaceCard(Card c)
Place a card back into the deck.

Parameters:
c - the card to insert.

getTopCardIndex

public int getTopCardIndex()
Obtain the position of the top card. (the number of cards dealt from the deck)

Returns:
the top card index

getTopCard

public Card getTopCard()
Get the first card in the deck

Returns:
the first card in the deck (does not remove it).

cardsLeft

public int cardsLeft()
Obtain the number of cards left in the deck


getCard

public final Card getCard(int i)
Obtain the card at a specific index in the deck. Does not matter if card has been dealt or not. If i < topCardIndex it has been dealt.

Parameters:
i - the index into the deck (0..51)
Returns:
the card at position i

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object