glassfrog.model
Class Deck

java.lang.Object
  extended by glassfrog.model.Deck
All Implemented Interfaces:
java.io.Serializable

public class Deck
extends java.lang.Object
implements java.io.Serializable

A Class given to represent a standard 52 card, 4 suit deck of playing cards.

Author:
jdavidso
See Also:
Serialized Form

Field Summary
private  java.util.ArrayList<Card> deck
           
private static int DECK_SHUFFLE
           
private static int NUM_RANKS
           
private static int NUM_SUITS
           
private  int numUsedCards
           
private static java.lang.Integer[] ranks
           
private  java.util.Random rng
           
private static java.lang.String[] suits
           
private  int usedIndex
           
 
Constructor Summary
Deck(int seed)
          Construtor specifying a seed to set our RNG with.
 
Method Summary
 Hand dealHand(int numPlayers, int numRounds, int[] numPrivateCards, int[] numPublicCards)
          Deals a new hand from the deck.
 Card getCard(int cardIndex)
          Return a card at a given index in the deck
 Card getNextCard()
          Get the next unused Card in the deck.
 void shuffle()
          Shuffles the top N cards where N is the amount of cards that are needed in order to draw a hand based on the information specified by the dealer.
 java.lang.String toString()
          Returns the deck, in array indexed order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DECK_SHUFFLE

private static final int DECK_SHUFFLE
See Also:
Constant Field Values

NUM_SUITS

private static final int NUM_SUITS
See Also:
Constant Field Values

NUM_RANKS

private static final int NUM_RANKS
See Also:
Constant Field Values

suits

private static final java.lang.String[] suits

ranks

private static final java.lang.Integer[] ranks

rng

private java.util.Random rng

numUsedCards

private int numUsedCards

usedIndex

private int usedIndex

deck

private java.util.ArrayList<Card> deck
Constructor Detail

Deck

public Deck(int seed)
Construtor specifying a seed to set our RNG with. The deck is then sonstructed as an array of 52 cards in order of suit/rank

Parameters:
seed - An int used to seed the deck to create repeatable deals
Method Detail

getCard

public Card getCard(int cardIndex)
Return a card at a given index in the deck

Parameters:
cardIndex - The index from which to draw the card
Returns:
The Card in the current deck

getNextCard

public Card getNextCard()
Get the next unused Card in the deck. Incrementing the used index by 1. Used for the deal function

Returns:
The next card in the deck

shuffle

public void shuffle()
Shuffles the top N cards where N is the amount of cards that are needed in order to draw a hand based on the information specified by the dealer. Reset the usedIndex to 0 for drawing off the top.


toString

public java.lang.String toString()
Returns the deck, in array indexed order.

Overrides:
toString in class java.lang.Object
Returns:
A string representing the cards in the deck, newline delimited.

dealHand

public Hand dealHand(int numPlayers,
                     int numRounds,
                     int[] numPrivateCards,
                     int[] numPublicCards)
Deals a new hand from the deck. This method takes in the parameters needed to create a new hand from a shuffled deck. It deals the cards using the following algorithm: calculate number of cards needed to shuffle shuffle For each round: For each player: add to privateCards[player][round] number of private cards for this round add to publicCards[round] number of public cards for this round Essentially for each round, deal each player the cards they need then deal the board cards

Parameters:
numPlayers - An integer representing the number of players
numRounds - An integer representing the number of rounds
numPrivateCards - An array of integers where the index is the round and the value is the number of private cards for each player for that round
numPublicCards - An array of integers where the index is the round and the value is the number of public cards for that round
Returns:
A Hand object representing all of the card information to play a hand of poker