de.kosi.model.game
Class GameImpl

java.lang.Object
  |
  +--de.kosi.model.game.GameImpl
All Implemented Interfaces:
Game, java.rmi.Remote

public class GameImpl
extends java.lang.Object
implements Game

This class implements a nice game of Bridge.

ChangeLog:

 
 $Log: GameImpl.java,v $
 Revision 1.20  2001/08/30 10:44:38  jiriki
 Finished implementation of claim

 Revision 1.19  2001/08/30 08:05:19  jiriki
 Worked on claiming

 Revision 1.18  2001/08/28 12:35:23  jiriki
 Started Implementation of claim

 Revision 1.17  2001/07/31 12:55:27  betacarotine
 worked on the tournament

 Revision 1.16  2001/07/31 12:15:23  betacarotine
 worked on the tournament

 Revision 1.15  2001/07/13 14:42:38  jiriki
 Worked on bugs.

 Revision 1.14  2001/07/13 10:49:06  jiriki
 Started fix for Bugs 440155 and 440333.

 Revision 1.13  2001/07/04 12:17:12  uid51247
 now the rubber valuations are available to the clients

 Revision 1.12  2001/06/27 11:53:20  betacarotine
 Worked on the Rubber and added comments.

 Revision 1.11  2001/06/15 12:51:06  betacarotine
 Added the possibility to get the number of tricks that the declarer made
 while the game's state is PLAYING.

 Revision 1.10  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.9  2001/06/06 09:22:35  betacarotine
 updated documentation

 Revision 1.8  2001/06/01 14:49:54  betacarotine
 improved the result handling, added tournament scoring

 Revision 1.7  2001/06/01 13:22:58  jiriki
 GameView working again.

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

 Revision 1.5  2001/05/30 08:42:50  betacarotine
 Updated documentation

 Revision 1.4  2001/05/25 14:51:23  betacarotine
 Added a result handling mechanism for the game.

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

 Revision 1.2  2001/05/09 11:44:40  betacarotine
 The Table interface got a getDirection method that returns the
 direction of the calling user.

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

 Revision 1.26  2001/04/27 12:49:35  login
 Added Locale in user creation, improved game stopwatch

 Revision 1.25  2001/04/25 12:47:06  login
 Implemented stopwatch

 Revision 1.24  2001/04/25 12:05:40  login
 Worked on TournamentImpl

 Revision 1.23  2001/04/17 19:30:08  wombat
 Updated Documentation

 Revision 1.22  2001/04/09 15:36:19  wombat
 Improved UserImpl, removed bugs

 Revision 1.21  2001/04/09 13:03:10  wombat
 Removed timeout from threadpool (did not work)

 Revision 1.20  2001/04/08 14:30:45  wombat
 Anfang Implementierung der selbst-alertierung

 Revision 1.19  2001/03/29 21:01:04  wombat
 - Improved logging.
 - Removed bugs from StressClient

 Revision 1.18  2001/03/27 14:51:00  timo
 Removed Copy & Paste Error
 Replaced NorthSouth with EastWest

 Revision 1.17  2001/03/27 12:29:29  wombat
 GameListener are now send the last event, that occurred, when
 they register.

 Revision 1.16  2001/03/27 10:38:53  wombat
 Added getOpener method and modified StressClient to user it.
 There is a problem with the StressClient, when the listeners are
 not registered before events are sent. The GameImpl should the last
 event to the listener, after it registered.

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

 Revision 1.14  2001/03/22 16:40:47  wombat
 - Updated ant to 1.3
 - Removed bugs in GameImpl and StressClient

 Revision 1.13  2001/03/21 22:34:40  wombat
 Worked on StressClient, removed bugs in GameImpl/Bidding, improved logging

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

 Revision 1.11  2001/03/19 21:50:49  wombat
 - Worked on admin client.
 - improved shutdown sequence
 - removed bugs in login/logout sequence

 Revision 1.10  2001/03/16 10:01:48  login
 removed one bug

 Revision 1.9  2001/03/15 19:58:27  login
 now dummy down events are sent!!

 Revision 1.8  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.7  2001/03/06 18:07:19  login
 documented

 Revision 1.6  2001/03/05 20:55:22  login
 - Game (und zugehoerige Klassen) soweit fertig
 - package de.kosi.model.tournament angelegt
 - Pair angelegt
 - Round angelegt
 - Movement-Interface angelegt
 - KosiMovement fertig!!! :-)
 - KosiMovementTest um das KosiMovement zu testen
       (kann mit KOSI/kosimovementtest  aufgerufen werden)
 - Tournament und TournamentImpl in das package de.kosi.model.tournament
       verschoben
 - buildfile fuer die neuen klassen angepasst

 Revision 1.5  2001/03/02 09:43:14  wombat
 Worked on gameimpl

 Revision 1.4  2001/02/27 14:43:14  wombat
 Updated documentation.

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

 Revision 1.2  2001/02/21 11:38:47  wombat
 Worked on GameImpl and Board

 Revision 1.1  2001/02/20 11:32:17  wombat
 Started GameImpl implementation.

 

Version:
$Revision: 1.20 $ ($Date: 2001/08/30 10:44:38 $)
Author:
Timo, Niklas, Ole

Fields inherited from interface de.kosi.model.game.Game
BIDDING, CLAIMING, FINISHED, PLAYING
 
Constructor Summary
GameImpl(Board board, Players players, GameContainer container, ChatChannel chatChannel)
          Creates a new GameImpl.
 
Method Summary
 void addGameListener(GameListener listener)
          Add a GameListener to this Game.
 void answerClaim(boolean accept)
          Answer a claim.
 void appealToJudge(java.lang.String reason)
          Appeal to a judge.
 void bid(Bid bid, boolean alerted)
          Bid a bid.
 void claim(int tricks)
          Claim the remaining tricks.
 int getActivePlayer()
          Returns the player (direction), that is currently due to make a move.
 Alert getAlert(int round, int player)
          Returns an Alert.
 java.util.List getBids()
          Returns a bid.
 java.util.List getCards()
          Returns the cards *currently* in the hand of the caller.
 java.util.List getCards(int direction)
          Returns the cards in one direction of the board.
 ChatChannel getChatChannel()
          This method returns the ChatChannel of this game.
 Contract getContract()
          Returns the contract being played.
 int getDeclarerTricks()
          Returns the number of tricks the declarer made so far.
 int getDirection()
          Returns the direction of the calling player.
 java.util.List getDummyCards()
          Returns the cards of the dummy.
 Trick getLatestTrick()
          Returns the trick currently played.
 int getOpener()
          Returns the opener of the bidding sequence.
 java.lang.String[] getPlayerNames()
          Returns the names of the player currently taking part in this Game.
 Players getPlayers()
           
 Result getResult()
          This method returns the result of the game of Bridge.
 int getStatus()
          This method returns the status of the game.
 boolean isVulnerableEastWest()
          Returns wether East and West are vulnerable.
 boolean isVulnerableNorthSouth()
          Returns wether North and South are vulnerable.
 void play(Card card)
          Play a card.
 void removeGameListener(GameListener listener)
          Removes a GameListener from this Game.
 void terminate()
          Terminate the game in case that the time was exceeded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameImpl

public GameImpl(Board board,
                Players players,
                GameContainer container,
                ChatChannel chatChannel)
Creates a new GameImpl.
Parameters:
board - Board to play.
players - Players of this Game.
container - Container of this game.
chatChannel - ChatChannel of this game.
Method Detail

getStatus

public int getStatus()
This method returns the status of the game.
Specified by:
getStatus in interface Game
Returns:
One of the constants BIDDING, PLAYING, FINISHED.

getChatChannel

public ChatChannel getChatChannel()
This method returns the ChatChannel of this game.
Specified by:
getChatChannel in interface Game
Returns:
ChatChannel or null if the game is finished.

addGameListener

public void addGameListener(GameListener listener)
                     throws InvalidSessionException
Add a GameListener to this Game. The listener is invoked, when changes to the Game are made. See documentation of GameListener for details.
Specified by:
addGameListener in interface Game
Parameters:
listener - the game listener.
Throws:
InvalidSessionException - when not called from within a valid session context.

removeGameListener

public void removeGameListener(GameListener listener)
                        throws InvalidSessionException
Removes a GameListener from this Game.
Specified by:
removeGameListener in interface Game
Parameters:
listener - the game listener.
Throws:
InvalidSessionException - when not called from within a valid session context.

getPlayerNames

public java.lang.String[] getPlayerNames()
Returns the names of the player currently taking part in this Game. Setting players is handled by the objects, that own the game (for example Table, Tournament).
Specified by:
getPlayerNames in interface Game
Returns:
Array of Playernames. This array has the length 4, but may contain null entries if there is currently no player at that place.

getActivePlayer

public int getActivePlayer()
                    throws InvalidGameStateException
Returns the player (direction), that is currently due to make a move. If it is the dummy's turn this method returns the dummy's direction and *NOT* the declarers direction even though it is actually the declarer who has to play one of the dummy's cards.
Specified by:
getActivePlayer in interface Game
Returns:
one of the Player constants (NORTH, SOUTH, EAST, WEST).
Throws:
InvalidGameStateException - If the game is already finished.

appealToJudge

public void appealToJudge(java.lang.String reason)
Appeal to a judge. This method gives players the possibility to request a judgement for the game. A reason for this has to be stated.
Specified by:
appealToJudge in interface Game
Parameters:
reason - Reason for calling a judge.

getDirection

public int getDirection()
                 throws KosiAccessException,
                        InvalidSessionException
Returns the direction of the calling player. This method can be used by a player to find out the direction he is playing at.
Specified by:
getDirection in interface Game
Returns:
one of the Player constante (NORTH, SOUTH, EAST, WEST).
Throws:
KosiAccessException - if the player is not currently seated at this game
InvalidSessionException - if not called from a valid session context. and therefor has no direction assigned.

getOpener

public int getOpener()
Returns the opener of the bidding sequence.
Specified by:
getOpener in interface Game
Returns:
one of the Player constante (NORTH, SOUTH, EAST, WEST).

isVulnerableNorthSouth

public boolean isVulnerableNorthSouth()
Returns wether North and South are vulnerable.
Specified by:
isVulnerableNorthSouth in interface Game
Returns:
true if North and South are vulnerable.

isVulnerableEastWest

public boolean isVulnerableEastWest()
Returns wether East and West are vulnerable.
Specified by:
isVulnerableEastWest in interface Game
Returns:
true if East and West are vulnerable.

getCards

public java.util.List getCards(int direction)
                        throws InvalidGameStateException
Returns the cards in one direction of the board. Only available when the game is finished. To get your own cards or the dummy's cards, use the methods getCards() respectively getDummyCards().
Specified by:
getCards in interface Game
Parameters:
direction - Direction the cards should be returned for.
Returns:
List of Cards.
Throws:
InvalidGameStateException - If the game is not finished yet.

getCards

public java.util.List getCards()
                        throws KosiAccessException,
                               InvalidSessionException
Returns the cards *currently* in the hand of the caller.
Specified by:
getCards in interface Game
Returns:
List of Cards.
Throws:
KosiAccessException - If the caller isn't playing this game.
InvalidSessionException - If called from an invalid session context.

getPlayers

public Players getPlayers()

getDummyCards

public java.util.List getDummyCards()
                             throws KosiAccessException
Returns the cards of the dummy.
Specified by:
getDummyCards in interface Game
Returns:
List of cards.
Throws:
KosiAccessException - If the dummy cards are not available. The dummy cards become available to all players and watchers after the opening lead has been made.

getAlert

public Alert getAlert(int round,
                      int player)
               throws KosiAccessException,
                      InvalidGameStateException,
                      InvalidSessionException
Returns an Alert.
Specified by:
getAlert in interface Game
Parameters:
round - Round the alert is returned for.
player - Player the alert is returned for.
Returns:
Alert object or null, if the bid is not alerted.
Throws:
KosiAccessException - if the calling user is not allowed to request this information.
InvalidSessionException - if not called from a valid session context.
InvalidGameStateException - if not in state of bidding.

getBids

public java.util.List getBids()
                       throws InvalidGameStateException
Returns a bid.
Specified by:
getBids in interface Game
Parameters:
round - Round the bid is returned for.
player - Player the bid is returned for.
Returns:
A bid, or null.
Throws:
InvalidGameStateException - if not in state of bidding.

bid

public void bid(Bid bid,
                boolean alerted)
         throws KosiAccessException,
                InvalidBidException,
                InvalidGameStateException,
                InvalidSessionException
Bid a bid.
Specified by:
bid in interface Game
Parameters:
bid - Bid to bid.
alerted - True, if this bid should be alerted.
Throws:
KosiAccessException - if the calling user is not allowed to place a bid.
InvalidGameStateException - if not in state of bidding.
InvalidBidException - if the bid is not according to the bridge rules.
InvalidSessionException - if not called from a valid session context.

getContract

public Contract getContract()
                     throws InvalidGameStateException
Returns the contract being played.
Specified by:
getContract in interface Game
Returns:
Contract or null if status is BIDDING.
Throws:
InvalidGameStateException - If the game's state is BIDDING.

getLatestTrick

public Trick getLatestTrick()
                     throws InvalidGameStateException,
                            FirstTrickException
Returns the trick currently played. Before the opening lead of the first trick this method throws an exception, else a Trick-instance will be returned.
Specified by:
getLatestTrick in interface Game
Returns:
The latest trick.
Throws:
InvalidGameStateException - If the game's state is BIDDING.
FirstTrickException - If the opening lead has not been made yet.

play

public void play(Card card)
          throws KosiAccessException,
                 InvalidCardException,
                 InvalidSessionException,
                 InvalidGameStateException
Play a card.
Specified by:
play in interface Game
Parameters:
card - Card to play.
Throws:
KosiAccessException - if the calling user is not allowed to play this card.
InvalidCardException - If the card cannot be played.
InvalidSessionException - If the method was called from an invalid session context.
InvalidGameStateException - If the status is either BIDDING or FINISHED.

getResult

public Result getResult()
                 throws InvalidGameStateException
This method returns the result of the game of Bridge.
Specified by:
getResult in interface Game
Returns:
The result of the game.
Throws:
InvalidGameStateException - If the game hasn't been finished yet.

claim

public void claim(int tricks)
           throws KosiAccessException,
                  InvalidGameStateException,
                  InvalidSessionException
Claim the remaining tricks.
Specified by:
claim in interface Game
Parameters:
tricks - number of tricks to claim.

answerClaim

public void answerClaim(boolean accept)
                 throws KosiAccessException,
                        InvalidGameStateException,
                        InvalidSessionException
Answer a claim.
Specified by:
answerClaim in interface Game
Parameters:
accept - wether or not the claim is accepted.

terminate

public void terminate()
Terminate the game in case that the time was exceeded.

getDeclarerTricks

public int getDeclarerTricks()
                      throws InvalidGameStateException
Returns the number of tricks the declarer made so far.
Specified by:
getDeclarerTricks in interface Game
Returns:
The number of tricks the declarer made so far.
Throws:
InvalidGameStateException - If the game is in the bidding phase