de.kosi.model.game
Class Card

java.lang.Object
  |
  +--de.kosi.model.game.Card
All Implemented Interfaces:
java.io.Serializable

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

This class represents a card. Each card has a suit and a value. Suits can be spades, hearts, diamonds and clubs, values range from 2 over 10, jack, queen and king to ace. Since we need exactly one instance of every card this class provides an array constant CARDS of all 52 needed card instances. Constants for the suits and values are also provided.

ChangeLog:

 $Log: Card.java,v $
 Revision 1.2  2001/06/15 09:33:27  betacarotine
 Changed the Game-interface. Instead of
 	int getLatestLeader()   and
 	List getLatestTrick()
 we now have
 	Trick getLatestTrick()

 The internal representation and storage of the tricks is reimplemented too
 based on the new Trick-class.

 Revision 1.1.1.1  2001/04/29 18:05:18  jiriki
 Imported sources from zola.

 Revision 1.13  2001/03/30 09:33:04  wombat
 Removed Bug in Sorting order of card comparator.

 Revision 1.12  2001/03/23 10:48:52  wombat
 - Table now restarts game
 - began GuestUser implementation

 Revision 1.11  2001/03/21 20:14:32  login
 updated docs

 Revision 1.10  2001/03/21 19:18:16  login
 updated docs and removed one bug from getComparator

 Revision 1.9  2001/03/21 13:26:36  wombat
 - Removed bugs in Table
 - began implementation of stree client
 - updated documentation

 Revision 1.8  2001/03/21 09:14:12  login
 Added the method getCardComparator

 Revision 1.7  2001/03/18 17:32:03  wombat
 Changed database concept

 Revision 1.6  2001/03/15 19:19:48  login
 Worked on GameImpl to make it possible that the declarer plays the dummy's cards
 and prohibit that the dummy does anything.

 Revision 1.5  2001/02/26 15:21:37  wombat
 worked on GamImpl and Board

 Revision 1.4  2001/02/09 19:26:32  login
 Doc-Update

 Revision 1.3  2001/02/07 10:28:52  login
 Updated documentation!!!!

 Revision 1.2  2001/02/06 14:37:08  login
 Updated docs


 

Version:
$Revision: 1.2 $ ($Date: 2001/06/15 09:33:27 $)
Author:
Timo, Niklas, Ole
See Also:
Serialized Form

Field Summary
static char[] CARD_CHARS
          Char representation of the cards.
static Card[] CARDS
          This array constant contains one instance of every card.
static int NUM_CARDS
          There is for every combination of suit and value exactly one card, so it is easy to calculate the total number of cards.
static int NUM_CARDS_PER_PLAYER
          Number of cards each player has.
static int NUM_SUITS
          Number of suits.
static int NUM_VALUES
          Number of values. 2 over 10, jack, queen, king to ace sum up to 13 values.
static char[] SUIT_CHARS
          Char representation of the four suits.
static int SUIT_CLUBS
          This constant refers to the clubs suit.
static int SUIT_DIAMONDS
          This constant refers to the diamonds suit.
static int SUIT_HEARTS
          This constant refers to the hearts suit.
static int SUIT_SPADES
          This constant refers to the spades suit.
static int VALUE_10
          This constant refers to the 10 value.
static int VALUE_2
          This constant refers to the 2 value.
static int VALUE_3
          This constant refers to the 3 value.
static int VALUE_4
          This constant refers to the 4 value.
static int VALUE_5
          This constant refers to the 5 value.
static int VALUE_6
          This constant refers to the 6 value.
static int VALUE_7
          This constant refers to the 7 value.
static int VALUE_8
          This constant refers to the 8 value.
static int VALUE_9
          This constant refers to the 9 value.
static int VALUE_ACE
          This constant refers to the ace value.
static int VALUE_JACK
          This constant refers to the jack value.
static int VALUE_KING
          This constant refers to the king value.
static int VALUE_QUEEN
          This constant refers to the queen value.
 
Constructor Summary
protected Card()
          This constructor creates a card with an invalid value.
 
Method Summary
 java.lang.Object clone()
          Returns this card instance since every card exists exactly one time.
 boolean equals(java.lang.Object obj)
          Checks whether this card instance is equal to the given argument.
static Card getCard(int card)
          Returns the card stored in the CARDS array constant at the specified index.
static Card getCard(int suit, int value)
          Returns the card with the specified suit and value.
static java.util.Comparator getComparator(int trumpSuit, int suitToFollow, boolean ascending)
          Returns a comparator for cards.
 int getSuit()
          Returns the suit of this card instance.
 int getValue()
          Returns the value of this card instance.
 int hashCode()
          Returns the hash code of this card instance.
 java.lang.String toString()
          Returns a String representation of this card.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUIT_CHARS

public static final char[] SUIT_CHARS
Char representation of the four suits.

CARD_CHARS

public static final char[] CARD_CHARS
Char representation of the cards.

NUM_SUITS

public static final int NUM_SUITS
Number of suits. Spades, hearts, diamonds and clubs sum up to four suits.

NUM_VALUES

public static final int NUM_VALUES
Number of values. 2 over 10, jack, queen, king to ace sum up to 13 values.

NUM_CARDS

public static final int NUM_CARDS
There is for every combination of suit and value exactly one card, so it is easy to calculate the total number of cards.

NUM_CARDS_PER_PLAYER

public static final int NUM_CARDS_PER_PLAYER
Number of cards each player has.

CARDS

public static final Card[] CARDS
This array constant contains one instance of every card.

SUIT_SPADES

public static final int SUIT_SPADES
This constant refers to the spades suit.

SUIT_HEARTS

public static final int SUIT_HEARTS
This constant refers to the hearts suit.

SUIT_DIAMONDS

public static final int SUIT_DIAMONDS
This constant refers to the diamonds suit.

SUIT_CLUBS

public static final int SUIT_CLUBS
This constant refers to the clubs suit.

VALUE_ACE

public static final int VALUE_ACE
This constant refers to the ace value.

VALUE_KING

public static final int VALUE_KING
This constant refers to the king value.

VALUE_QUEEN

public static final int VALUE_QUEEN
This constant refers to the queen value.

VALUE_JACK

public static final int VALUE_JACK
This constant refers to the jack value.

VALUE_10

public static final int VALUE_10
This constant refers to the 10 value.

VALUE_9

public static final int VALUE_9
This constant refers to the 9 value.

VALUE_8

public static final int VALUE_8
This constant refers to the 8 value.

VALUE_7

public static final int VALUE_7
This constant refers to the 7 value.

VALUE_6

public static final int VALUE_6
This constant refers to the 6 value.

VALUE_5

public static final int VALUE_5
This constant refers to the 5 value.

VALUE_4

public static final int VALUE_4
This constant refers to the 4 value.

VALUE_3

public static final int VALUE_3
This constant refers to the 3 value.

VALUE_2

public static final int VALUE_2
This constant refers to the 2 value.
Constructor Detail

Card

protected Card()
This constructor creates a card with an invalid value. Needed for serialization.
Method Detail

getCard

public static Card getCard(int card)
Returns the card stored in the CARDS array constant at the specified index. This index should be equal to the value of the card's value attribute.
Parameters:
card - The index to the desired card in the CARDS array constant.
Returns:
The desired card.
Throws:
ArrayIndexOutOfBoundsException - If the given index was invalid.

getCard

public static Card getCard(int suit,
                           int value)
Returns the card with the specified suit and value.
Parameters:
suit - The suit of the card to get. Must be one of the constants SUIT_SPADES ... SUIT_CLUBS.
value - The value of the card to get. Must be one of the constants VALUE_2 ... VALUE_ACE.
Returns:
The card with the specified suit and value.
Throws:
java.lang.IllegalArgumentException - If the suit or value were illegal.

getSuit

public int getSuit()
Returns the suit of this card instance. The result will be one of the constants SUIT_SPADES ... SUIT_CLUBS.
Returns:
The suit of this card instance.

getValue

public int getValue()
Returns the value of this card instance. The result will be one of the constants VALUE_2 ... VALUE_ACE.
Returns:
The value of this card instance.

equals

public boolean equals(java.lang.Object obj)
Checks whether this card instance is equal to the given argument.
Overrides:
equals in class java.lang.Object
Parameters:
obj - This argument will be compared to this card instance.
Returns:
true if the argument and this instance are equal, otherwise false.

hashCode

public int hashCode()
Returns the hash code of this card instance.
Overrides:
hashCode in class java.lang.Object
Returns:
The hash code of this card instance.

clone

public java.lang.Object clone()
Returns this card instance since every card exists exactly one time.
Overrides:
clone in class java.lang.Object
Returns:
This card instance.

toString

public java.lang.String toString()
Returns a String representation of this card.
Overrides:
toString in class java.lang.Object
Returns:
String representation.

getComparator

public static java.util.Comparator getComparator(int trumpSuit,
                                                 int suitToFollow,
                                                 boolean ascending)
Returns a comparator for cards. The comparator takes into account which suit is being trump, which suit is to follow and whether the order should be ascending or not. Even if two different compared cards have the "same" value acording to the rules of bridge (e.g. with NT and spades to follow, all cards of hearts, diamonds and clubs would be of equal value), they will get ordered with respect to their suits (spades > hearts > diamonds > clubs) and with equal suit to their values (ace > king > queen > jack > 10 > ... > 2).
Parameters:
trumpSuit - The suit which is trump.
suitToFollow - The suit which is to be followed; that is the suit of the first card in a trick.
ascending - true, if you want the cards in ascending order, otherwise false.
Returns:
The desired comparator.
Throws:
java.lang.IllegalArgumentException - If trumpSuit or suitToFollow were no legal suits (trumpSuit may also be SuitBid.SUIT_NO_TRUMPS).