de.kosi.model.game
Class Playing

java.lang.Object
  |
  +--de.kosi.model.game.Playing
All Implemented Interfaces:
GamePhase

public class Playing
extends java.lang.Object
implements GamePhase

This class implements the playing of the cards in game of Bridge.

ChangeLog:

 
 $Log: Playing.java,v $
 Revision 1.8  2001/06/27 11:53:21  betacarotine
 Worked on the Rubber and added comments.

 Revision 1.7  2001/06/15 12:32:15  betacarotine
 hopefully removed two bugs

 Revision 1.6  2001/06/15 11:35:07  betacarotine
 added serialization support to the Trick

 Revision 1.5  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.4  2001/06/01 13:22:58  jiriki
 GameView working again.

 Revision 1.3  2001/05/30 10:25:51  jiriki
 Refactored Client.

 Revision 1.2  2001/05/30 10:19:18  pizarro
 Updated Documentation.

 Revision 1.1  2001/05/23 13:00:39  betacarotine
 Restructured the implementation of the game interface.

 

Version:
$Revision: 1.8 $ ($Date: 2001/06/27 11:53:21 $)
Author:
PG KoSI, Uni Oldenburg

Field Summary
static int MAX_TRICKS
          Maximum number of tricks in a game of Bridge.
 
Constructor Summary
Playing(Board board, SuitContract contract)
          Creates a new Playing instance.
 
Method Summary
 void addCard(Card card)
          Adds a card to the list of played cards.
 boolean dummyCardsAvailable()
          Checks if the dummy cards may be published.
 boolean dummyCardsHaveToBePublishedNow()
          Checks if the dummy cards have to be published now.
 int getActivePlayer()
          Returns the active player.
 java.util.List getCards(int direction)
          Returns the cards that are in the hand of the player at the given direction.
 SuitContract getContract()
          Returns the contract of the game.
 java.util.List getDummyCards()
          Returns the cards of the dummy player.
 int getDummyDirection()
          Returns the direction of the dummy player.
 Trick getLatestTrick()
          Returns the trick currently played.
 int getState()
          Returns the state of the game.
 int getSuitToFollow()
          Returns the suit to follow.
 int getTrickCounter()
          Returns the number of tricks the declarer made.
 java.util.List getTricks()
          Returns a list of all played tricks so far.
 int getWinnerOfLatestTrick()
          Returns the winner of the latest trick according to the rules of bridge
 boolean isFinished()
          Checks if the playing phase is finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_TRICKS

public static final int MAX_TRICKS
Maximum number of tricks in a game of Bridge.
Constructor Detail

Playing

public Playing(Board board,
               SuitContract contract)
Creates a new Playing instance.
Parameters:
board - The board of the game.
contract - The contract of the game.
Method Detail

getContract

public SuitContract getContract()
Returns the contract of the game.
Returns:
the contract of the game

getState

public int getState()
Returns the state of the game. The state is always PLAYING here.
Specified by:
getState in interface GamePhase
Returns:
the PLAYING constant

getLatestTrick

public Trick getLatestTrick()
                     throws FirstTrickException
Returns the trick currently played. Before the opening lead of the first trick this method returns an empty vector, after that the vector always contains 1 to 4 elements.
Returns:
The current trick.

getCards

public java.util.List getCards(int direction)
Returns the cards that are in the hand of the player at the given direction.
Specified by:
getCards in interface GamePhase
Parameters:
direction - The direction of the player whose cards are to be returned.
Returns:
A list of cards.
Throws:
ArrayIndexOutOfBoundsException - If the direction was invalid.

getDummyCards

public java.util.List getDummyCards()
Returns the cards of the dummy player.
Returns:
the dummy cards

getDummyDirection

public int getDummyDirection()
Returns the direction of the dummy player.
Returns:
the direction of the dummy player

getWinnerOfLatestTrick

public int getWinnerOfLatestTrick()
                           throws IncompleteTrickException
Returns the winner of the latest trick according to the rules of bridge
Returns:
direction of the winner of the latest trick
Throws:
IncompleteTrickException - If the trick is not completed yet and no winner can be determined.

getActivePlayer

public int getActivePlayer()
Returns the active player.
Specified by:
getActivePlayer in interface GamePhase
Returns:
The active player.

dummyCardsAvailable

public boolean dummyCardsAvailable()
Checks if the dummy cards may be published.
Returns:
true if the dummy cards may be published, false else

dummyCardsHaveToBePublishedNow

public boolean dummyCardsHaveToBePublishedNow()
Checks if the dummy cards have to be published now.
Returns:
true if the dummy cards have to be published now, false else

isFinished

public boolean isFinished()
Checks if the playing phase is finished.
Returns:
true if the playing phase is finished, false else

addCard

public void addCard(Card card)
             throws InvalidCardException
Adds a card to the list of played cards. Checks the rules of bridge. If the rules are violated an exception is thrown and the card is refused. If the trick gets finished the winner is determined and if it is the declarer or the dummy, the trick counter gets increased by one.
Parameters:
card - the card to play
Throws:
InvalidCardException - If the active player doesn't have the card to be played or if the rule of following suit is violated.

getTrickCounter

public int getTrickCounter()
Returns the number of tricks the declarer made.
Returns:
the number of tricks the declarer made

getSuitToFollow

public int getSuitToFollow()
Returns the suit to follow. If the active player is currently the first in a trick, -1 will be returned.
Returns:
the suit to follow or -1 when the active player is currently the first in a trick.

getTricks

public java.util.List getTricks()
Returns a list of all played tricks so far.
Returns:
a list of all played tricks so far.