de.kosi.model.game
Class Bidding

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

public class Bidding
extends java.lang.Object
implements GamePhase

This class handles the bidding sequence which is the first phase in a game of Bridge. It has methods for adding bids at the end of the sequence and checks the compliance to the bidding rules of Bridge.

ChangeLog:

 
 $Log: Bidding.java,v $
 Revision 1.9  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.8  2001/06/15 12:32:15  betacarotine
 hopefully removed two bugs

 Revision 1.7  2001/06/06 09:22:35  betacarotine
 updated documentation

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

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

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

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

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

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

 Revision 1.14  2001/04/20 12:57:56  login
 added testcase for the Bidding class

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

 Revision 1.12  2001/04/08 14:30:44  wombat
 Anfang Implementierung der selbst-alertierung

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

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

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

 Revision 1.8  2001/03/06 18:07:19  login
 documented

 Revision 1.7  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.6  2001/02/27 14:43:14  wombat
 Updated documentation.

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

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

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

 Revision 1.2  2001/02/06 15:37:44  login
 Updated docs


 

Version:
$Revision: 1.9 $ ($Date: 2001/06/15 12:51:06 $)
Author:
Timo, Niklas, Ole

Constructor Summary
Bidding(Players players, Board board)
          This constructor creates a new Bidding instance for the given players.
 
Method Summary
 void addBid(Bid bid, Alert alert)
          Adds the given bid to the end of the vector of bids.
 int getActivePlayer()
          Returns the direction of the active player.
 Alert getAlert(int round, int player)
          Returns an Alert.
 Bid getBid(int round, int player)
          Returns the Bid that the given player made in the given bidding round.
 java.util.List getBidList()
          Return the list of bids.
 java.util.List getBids()
          Returns a list of Bids without information about alerts.
 Board getBoard()
          Returns the board that the game is played on.
 java.util.List getCards(int direction)
          Returns a list of cards currently in the hands of the player at the given direction.
 Contract getContract()
          Returns the contract once the bidding is finished.
 int getFirstSuitBidIndex(int startIndex, int suit)
          Returns the index of the bid, that is the first occurance of the suit (But only by the pair that bid the bid at startIndex).
 SuitBid getLastSuitBid()
          Returns the latest suit bid in the vector of bids (the one with the highest index) or null if no player has made a suit bid yet.
 int getLastSuitBidIndex()
          Returns the index of the latest suit bid in the vector of bids (the one with the highest index) or -1 if no player has made a suit bid yet.
 int getNumRounds()
          Returns the number of completed bidding rounds (rounds in which every player made an announcement).
 int getState()
          Returns the state of the game which is Game.BIDDING.
 boolean isDoublePossible()
          Checks whether the active player is allowed to double according to the rules of bridge.
 boolean isFinished()
          Returns if the bidding is finished.
 boolean isRedoublePossible()
          Checks whether the active player is allowed to redouble according to the rules of bridge.
 void removeLastBid()
          Removes the latest bid from the vector of bids.
 int size()
          Returns the number of bids made yet.
 java.lang.String toString()
          Returns a String representation of the bidding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bidding

public Bidding(Players players,
               Board board)
This constructor creates a new Bidding instance for the given players.
Parameters:
players - The players that have a game of Bridge together and therefore need a bidding phase.
board - The board that the game of Bridge will be played with. Needed to find out which player the opener is.
Method Detail

removeLastBid

public void removeLastBid()
Removes the latest bid from the vector of bids.

getLastSuitBid

public SuitBid getLastSuitBid()
Returns the latest suit bid in the vector of bids (the one with the highest index) or null if no player has made a suit bid yet.
Returns:
The latest suit bid in the vector of bids.

getFirstSuitBidIndex

public int getFirstSuitBidIndex(int startIndex,
                                int suit)
Returns the index of the bid, that is the first occurance of the suit (But only by the pair that bid the bid at startIndex). This is used to find out, who has to play a contract.
Parameters:
startIndex - Bid that made the contract.
suit - Suit to look for.
Returns:
the index of the first bid of suit suit, by the pair, that bid the bid at index startIndex.

getLastSuitBidIndex

public int getLastSuitBidIndex()
Returns the index of the latest suit bid in the vector of bids (the one with the highest index) or -1 if no player has made a suit bid yet.
Returns:
The index of the latest suit bid in the vector of bids.

isRedoublePossible

public boolean isRedoublePossible()
Checks whether the active player is allowed to redouble according to the rules of bridge.
Returns:
true, if redouble is allowed, else false.

isDoublePossible

public boolean isDoublePossible()
Checks whether the active player is allowed to double according to the rules of bridge.
Returns:
true, if double is allowed, else false.

addBid

public void addBid(Bid bid,
                   Alert alert)
            throws InvalidBidException
Adds the given bid to the end of the vector of bids. If this would violate the rules of Bridge an exception was thrown and the bid wasn't added.
Parameters:
bid - The bid to add.
alert - Alert object if the bid has been alerted, null otherwise.
Throws:
InvalidBidException - If the addition violates the rules of Bridge bidding.
java.lang.IllegalArgumentException - If bid is null.
java.lang.IllegalStateException - If the bidding has ended.

isFinished

public boolean isFinished()
Returns if the bidding is finished.
Returns:
true if the bidding is finished.

getContract

public Contract getContract()
                     throws InvalidGameStateException
Returns the contract once the bidding is finished.
Returns:
the contract to be played.
Throws:
InvalidGameStateException - If the bidding phase is not finished yet.

getBid

public Bid getBid(int round,
                  int player)
Returns the Bid that the given player made in the given bidding round.
Parameters:
round - The bidding round.
player - The player who made the returned bid.
Returns:
The bid that the given player made in the given bidding round, or null if the player has not yet bid..
Throws:
java.lang.IllegalArgumentException - If the round or player are out of bounds.
ArrayIndexOutOfBoundsException - If the round hasn't been played yet or the player hasn't bidden in the specified round yet.

getAlert

public Alert getAlert(int round,
                      int player)
Returns an Alert.
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.

getNumRounds

public int getNumRounds()
Returns the number of completed bidding rounds (rounds in which every player made an announcement).
Returns:
The number of completed bidding rounds.

getBidList

public java.util.List getBidList()
Return the list of bids.
Returns:
List containing Bid objects.

getBids

public java.util.List getBids()
Returns a list of Bids without information about alerts.
Returns:
List of bids in correct order.

getState

public int getState()
Returns the state of the game which is Game.BIDDING.
Specified by:
getState in interface GamePhase
Returns:
The constant Game.BIDDING.

getCards

public java.util.List getCards(int direction)
Returns a list of cards currently in the hands of the player at the given direction.
Specified by:
getCards in interface GamePhase
Parameters:
direction - The direction the player whose cards are to be returned is seated at.
Returns:
List of cards.

getActivePlayer

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

size

public int size()
Returns the number of bids made yet.
Returns:
the number of bids made yet.

toString

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

getBoard

public Board getBoard()
Returns the board that the game is played on.
Returns:
A board.