glassfrog.handevaluator
Class EvaluateCard

java.lang.Object
  extended by glassfrog.handevaluator.EvaluateCard

public class EvaluateCard
extends java.lang.Object

Represents a playing card from a set of cards {0..51} which map to cards having a suit {0..3} <==> {CLUBS,DIAMONDS,HEARTS,SPADES} and a face value {0..12} <==> {2..ACE}

Author:
Aaron Davidson

Field Summary
static int ACE
           
static int BAD_CARD
           
static int CLUBS
           
static int DIAMONDS
           
static int EIGHT
           
static int FIVE
           
static int FOUR
           
private  int gIndex
           
static int HEARTS
           
static int JACK
           
static int KING
           
static int NINE
           
static int NUM_CARDS
           
static int NUM_RANKS
           
static int NUM_SUITS
           
static int QUEEN
           
static int SEVEN
           
static int SIX
           
static int SPADES
           
static int TEN
           
static int THREE
           
static int TWO
           
 
Constructor Summary
EvaluateCard()
          Constructor -- makes an empty card.
EvaluateCard(char rank, char suit)
          Constructor.
EvaluateCard(int index)
          Constructor.
EvaluateCard(int rank, int suit)
          Constructor.
EvaluateCard(java.lang.String s)
           
 
Method Summary
private  int chars2index(char rank, char suit)
           
 int getIndex()
          Return the integer index for this card.
 int getRank()
          Obtain the rank of this card
static int getRank(int i)
          Obtain the rank of this card
static char getRankChar(int r)
           
 int getSuit()
          Obtain the suit of this card
static int getSuit(int i)
          Obtain the suit of this card
 void setCard(int rank, int suit)
          Change this card to another.
 void setIndex(int index)
          Change the index of the card.
static int toIndex(int rank, int suit)
          convert a rank and a suit to an index
 java.lang.String toString()
          Obtain a String representation of this Card
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLUBS

public static final int CLUBS
See Also:
Constant Field Values

DIAMONDS

public static final int DIAMONDS
See Also:
Constant Field Values

HEARTS

public static final int HEARTS
See Also:
Constant Field Values

SPADES

public static final int SPADES
See Also:
Constant Field Values

BAD_CARD

public static final int BAD_CARD
See Also:
Constant Field Values

TWO

public static final int TWO
See Also:
Constant Field Values

THREE

public static final int THREE
See Also:
Constant Field Values

FOUR

public static final int FOUR
See Also:
Constant Field Values

FIVE

public static final int FIVE
See Also:
Constant Field Values

SIX

public static final int SIX
See Also:
Constant Field Values

SEVEN

public static final int SEVEN
See Also:
Constant Field Values

EIGHT

public static final int EIGHT
See Also:
Constant Field Values

NINE

public static final int NINE
See Also:
Constant Field Values

TEN

public static final int TEN
See Also:
Constant Field Values

JACK

public static final int JACK
See Also:
Constant Field Values

QUEEN

public static final int QUEEN
See Also:
Constant Field Values

KING

public static final int KING
See Also:
Constant Field Values

ACE

public static final int ACE
See Also:
Constant Field Values

NUM_SUITS

public static final int NUM_SUITS
See Also:
Constant Field Values

NUM_RANKS

public static final int NUM_RANKS
See Also:
Constant Field Values

NUM_CARDS

public static final int NUM_CARDS
See Also:
Constant Field Values

gIndex

private int gIndex
Constructor Detail

EvaluateCard

public EvaluateCard()
Constructor -- makes an empty card.


EvaluateCard

public EvaluateCard(int rank,
                    int suit)
Constructor.

Parameters:
rank - face value of the card
suit - suit of the card

EvaluateCard

public EvaluateCard(int index)
Constructor. Creates a Card from an integer index {0..51}

Parameters:
index - integer index of card between 0 and 51

EvaluateCard

public EvaluateCard(java.lang.String s)

EvaluateCard

public EvaluateCard(char rank,
                    char suit)
Constructor. Creates a card from its character based representation.

Parameters:
rank - the character representing the card's rank
suit - the character representing the card's suit
Method Detail

chars2index

private int chars2index(char rank,
                        char suit)

getIndex

public int getIndex()
Return the integer index for this card.

Returns:
the card's index value

setIndex

public void setIndex(int index)
Change the index of the card.

Parameters:
index - the new index of the card

toIndex

public static int toIndex(int rank,
                          int suit)
convert a rank and a suit to an index

Parameters:
rank - the rank to convert
suit - the suit to convert
Returns:
the index calculated from the rank and suit

setCard

public void setCard(int rank,
                    int suit)
Change this card to another. This is more practical than creating a new object for optimization reasons.

Parameters:
rank - face value of the card
suit - suit of the card

getRank

public int getRank()
Obtain the rank of this card

Returns:
rank

getRank

public static int getRank(int i)
Obtain the rank of this card

Returns:
rank

getSuit

public int getSuit()
Obtain the suit of this card

Returns:
suit

getSuit

public static final int getSuit(int i)
Obtain the suit of this card

Returns:
suit

toString

public java.lang.String toString()
Obtain a String representation of this Card

Overrides:
toString in class java.lang.Object
Returns:
A string for this card

getRankChar

public static char getRankChar(int r)