rails.game
Class StockRound

java.lang.Object
  extended by rails.game.Round
      extended by rails.game.StockRound
All Implemented Interfaces:
RoundI
Direct Known Subclasses:
PrussianFormationRound, ShareSellingRound, StockRound_1825, StockRound_1835, StockRound_1856, StockRound_1880, StockRound_18EU, TreasuryShareRound

public class StockRound
extends Round

Implements a basic Stock Round.

A new instance must be created for each new Stock Round. At the end of a round, the current instance should be discarded.

Permanent memory is formed by static attributes (like who has the Priority Deal).


Field Summary
static int BOUGHT
           
protected  State companyBoughtThisTurnWrapper
           
protected  Player currentPlayer
           
protected  BooleanState hasActed
           
protected  BooleanState hasSoldThisTurnBeforeBuying
           
protected  int numberOfPlayers
           
protected  IntegerState numPasses
           
protected  java.util.HashMap<Player,java.util.HashMap<PublicCompanyI,java.lang.Object>> playersThatSoldThisRound
          HashMap per player containing a HashMap per company
protected static int SELL_BUY
           
protected static int SELL_BUY_OR_BUY_SELL
           
protected static int SELL_BUY_SELL
           
protected  HashSetState<PublicCompanyI> sellObligationLifted
          Records lifted share selling obligations in the current round
protected  java.util.Map<java.lang.String,StockSpaceI> sellPrices
           
protected  int sequenceRule
           
static int SOLD
           
protected  Player startingPlayer
           
 
Fields inherited from class rails.game.Round
autopasses, bank, canRequestTurn, companyManager, gameManager, guiHints, hasRequestedTurn, ipo, log, mapManager, moveStack, playerManager, pool, possibleActions, scrapHeap, stockMarket, unavailable, wasInterrupted
 
Constructor Summary
StockRound(GameManagerI aGameManager)
          Constructor with the GameManager, will call super class (Round's) Constructor to initialize
 
Method Summary
protected  void adjustSharePrice(PublicCompanyI company, int numberSold, boolean soldBefore)
           
 boolean buyShares(java.lang.String playerName, BuyCertificate action)
          Buying one or more single or double-share certificates (more is sometimes possible)
 boolean checkAgainstHoldLimit(Player player, PublicCompanyI company, int number)
          Check if a player may buy the given number of shares from a given company, given the "hold limit" per company, that is the percentage of shares of one company that a player may hold (typically 60%).
 boolean done(java.lang.String playerName, boolean hasAutopassed)
          The current Player passes or is done.
 boolean executeExchangeForShare(ExchangeForShare sp)
           
protected  void executeShareTransfer(PublicCompanyI company, java.util.List<PublicCertificateI> certsToSell, Player dumpedPlayer, int presSharesToSell)
           
protected  void finishRound()
           
protected  void finishTurn()
           
protected  void gameSpecificChecks(Portfolio boughtFrom, PublicCompanyI company)
          Stub, may be overridden in subclasses
protected  int getBuyPrice(BuyCertificate action, StockSpaceI currentSpace)
          Allow different price setting in subclasses (i.e.
 int getCurrentPlayerIndex()
           
protected  int getCurrentSellPrice(PublicCompanyI company)
           
 java.lang.String getHelp()
           
 java.lang.String getRoundName()
           
protected  CashHolder getSharePriceRecipient(PublicCompanyI comp, Portfolio from, int price)
          Who receives the cash when a certificate is bought.
 int getStockRoundNumber()
           
protected  void initPlayer()
           
protected  boolean isPlayerOverLimits(Player player)
           
protected  java.lang.String isPlayerOverLimitsDetail(Player player)
           
protected  boolean isSaleRecorded(Player player, PublicCompanyI company)
           
 boolean isSellObligationLifted(PublicCompanyI company)
           
 int maxAllowedNumberOfSharesToBuy(Player player, PublicCompanyI company, int shareSize)
          Return the number of additional shares of a certain company and of a certain size that a player may buy, given the share "hold limit" per company, that is the percentage of shares of one company that a player may hold (typically 60%).
 boolean mayCurrentPlayerBuyAnything()
          Can the current player do any buying?
 boolean mayCurrentPlayerSellAnything()
          Can the current player do any selling?
 boolean mayPlayerBuyCertificate(Player player, PublicCompanyI comp, float number)
          Check if a player may buy the given number of certificates.
 boolean mayPlayerSellShareOfCompany(PublicCompanyI company)
           
protected  boolean noSaleIfNotOperated()
           
protected  boolean noSaleInFirstSR()
           
 boolean process(PossibleAction action)
           
protected  boolean processGameSpecificAction(PossibleAction action)
           
protected  void recordSale(Player player, PublicCompanyI company)
           
protected  void releaseCompanyShares(PublicCompanyI company)
          Make the certificates of one company available for buying by putting these in the IPO.
protected  boolean requestTurn(RequestTurn action)
           
 boolean sellShares(SellShares action)
           
 void setBuyableCerts()
          Create a list of certificates that a player may buy in a Stock Round, taking all rules into account.
 void setCurrentPlayer(Player player)
           
protected  void setGameSpecificActions()
          Stub, can be overridden in subclasses
protected  void setNextPlayer()
          Internal method: pass the turn to the next player.
 boolean setPossibleActions()
          Default version, does nothing.
protected  void setPriority()
          Remember the player that has the Priority Deal.
 void setSellableShares()
          Create a list of certificates that a player may sell in a Stock Round, taking all rules taken into account.
 void setSellObligationLifted(PublicCompanyI company)
           
protected  void setSpecialActions()
           
 void start()
           
 boolean startCompany(java.lang.String playerName, StartCompany action)
          Start a company by buying one or more shares (more applies to e.g.
 java.lang.String toString()
           
 boolean useSpecialProperty(UseSpecialProperty action)
           
 
Methods inherited from class rails.game.Round
canCompanyOperateThisRound, canRequestTurn, certCountsAsSold, checkFlotation, exchangeTokens, floatCompany, getAutopasses, getCurrentPhase, getCurrentPlayer, getGameManager, getGameOption, getGameParameter, getGameParameterAsBoolean, getGameParameterAsInt, getNumberOfActivePlayers, getNumberOfPlayers, getPlayers, getRoundTypeForUI, getSoldPercentage, getSpecialProperties, hasAutopassed, pay, pay, requestTurn, resume, setAutopass, setCanRequestTurn, setCurrentPlayerIndex, setOperatingCompanies, setOperatingCompanies, transferCertificate, transferCertificates, wasInterrupted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numberOfPlayers

protected int numberOfPlayers

currentPlayer

protected Player currentPlayer

startingPlayer

protected Player startingPlayer

companyBoughtThisTurnWrapper

protected State companyBoughtThisTurnWrapper

hasSoldThisTurnBeforeBuying

protected BooleanState hasSoldThisTurnBeforeBuying

hasActed

protected BooleanState hasActed

numPasses

protected IntegerState numPasses

sellPrices

protected java.util.Map<java.lang.String,StockSpaceI> sellPrices

sellObligationLifted

protected HashSetState<PublicCompanyI> sellObligationLifted
Records lifted share selling obligations in the current round

Example: >60% ownership allowed after a merger in 18EU.


playersThatSoldThisRound

protected java.util.HashMap<Player,java.util.HashMap<PublicCompanyI,java.lang.Object>> playersThatSoldThisRound
HashMap per player containing a HashMap per company


SELL_BUY_SELL

protected static final int SELL_BUY_SELL
See Also:
Constant Field Values

SELL_BUY

protected static final int SELL_BUY
See Also:
Constant Field Values

SELL_BUY_OR_BUY_SELL

protected static final int SELL_BUY_OR_BUY_SELL
See Also:
Constant Field Values

BOUGHT

public static final int BOUGHT
See Also:
Constant Field Values

SOLD

public static final int SOLD
See Also:
Constant Field Values

sequenceRule

protected int sequenceRule
Constructor Detail

StockRound

public StockRound(GameManagerI aGameManager)
Constructor with the GameManager, will call super class (Round's) Constructor to initialize

Parameters:
aGameManager - The GameManager Object needed to initialize the Round Class
Method Detail

start

public void start()

getStockRoundNumber

public int getStockRoundNumber()

setPossibleActions

public boolean setPossibleActions()
Description copied from class: Round
Default version, does nothing. Subclasses should override this method with a real version.

Specified by:
setPossibleActions in interface RoundI
Overrides:
setPossibleActions in class Round

setGameSpecificActions

protected void setGameSpecificActions()
Stub, can be overridden in subclasses


setBuyableCerts

public void setBuyableCerts()
Create a list of certificates that a player may buy in a Stock Round, taking all rules into account.


setSellableShares

public void setSellableShares()
Create a list of certificates that a player may sell in a Stock Round, taking all rules taken into account.


setSpecialActions

protected void setSpecialActions()

process

public boolean process(PossibleAction action)
Specified by:
process in interface RoundI
Overrides:
process in class Round

processGameSpecificAction

protected boolean processGameSpecificAction(PossibleAction action)

startCompany

public boolean startCompany(java.lang.String playerName,
                            StartCompany action)
Start a company by buying one or more shares (more applies to e.g. 1841)

Parameters:
player - The player that wants to start a company.
company - The company to start.
price - The start (par) price (ignored if the price is fixed).
shares - The number of shares to buy (can be more than 1 in e.g. 1841).
Returns:
True if the company could be started. False indicates an error.

buyShares

public boolean buyShares(java.lang.String playerName,
                         BuyCertificate action)
Buying one or more single or double-share certificates (more is sometimes possible)

Parameters:
player - The player that wants to buy shares.
action - The executed BuyCertificates action
Returns:
True if the certificates could be bought. False indicates an error.

gameSpecificChecks

protected void gameSpecificChecks(Portfolio boughtFrom,
                                  PublicCompanyI company)
Stub, may be overridden in subclasses


getBuyPrice

protected int getBuyPrice(BuyCertificate action,
                          StockSpaceI currentSpace)
Allow different price setting in subclasses (i.e. 1835 Nationalisation)


getSharePriceRecipient

protected CashHolder getSharePriceRecipient(PublicCompanyI comp,
                                            Portfolio from,
                                            int price)
Who receives the cash when a certificate is bought. With incremental capitalization, this can be the company treasure. This method must be called before transferring the certificate.

Parameters:
cert -
Returns:

releaseCompanyShares

protected void releaseCompanyShares(PublicCompanyI company)
Make the certificates of one company available for buying by putting these in the IPO.

Parameters:
company - The company to be released.

recordSale

protected void recordSale(Player player,
                          PublicCompanyI company)

isSaleRecorded

protected boolean isSaleRecorded(Player player,
                                 PublicCompanyI company)

sellShares

public boolean sellShares(SellShares action)

executeShareTransfer

protected void executeShareTransfer(PublicCompanyI company,
                                    java.util.List<PublicCertificateI> certsToSell,
                                    Player dumpedPlayer,
                                    int presSharesToSell)

getCurrentSellPrice

protected int getCurrentSellPrice(PublicCompanyI company)

adjustSharePrice

protected void adjustSharePrice(PublicCompanyI company,
                                int numberSold,
                                boolean soldBefore)

useSpecialProperty

public boolean useSpecialProperty(UseSpecialProperty action)

executeExchangeForShare

public boolean executeExchangeForShare(ExchangeForShare sp)

done

public boolean done(java.lang.String playerName,
                    boolean hasAutopassed)
The current Player passes or is done.

Parameters:
player - Name of the passing player.
Returns:
False if an error is found.

finishRound

protected void finishRound()
Overrides:
finishRound in class Round

requestTurn

protected boolean requestTurn(RequestTurn action)

finishTurn

protected void finishTurn()

setNextPlayer

protected void setNextPlayer()
Internal method: pass the turn to the next player.


initPlayer

protected void initPlayer()

setPriority

protected void setPriority()
Remember the player that has the Priority Deal. Must be called BEFORE setNextPlayer()!


setCurrentPlayer

public void setCurrentPlayer(Player player)
Overrides:
setCurrentPlayer in class Round

getCurrentPlayerIndex

public int getCurrentPlayerIndex()
Overrides:
getCurrentPlayerIndex in class Round
Returns:
The index of the player that has the turn.

mayCurrentPlayerSellAnything

public boolean mayCurrentPlayerSellAnything()
Can the current player do any selling?

Returns:
True if any selling is allowed.

mayPlayerSellShareOfCompany

public boolean mayPlayerSellShareOfCompany(PublicCompanyI company)

mayCurrentPlayerBuyAnything

public boolean mayCurrentPlayerBuyAnything()
Can the current player do any buying?

Returns:
True if any buying is allowed.

isPlayerOverLimits

protected boolean isPlayerOverLimits(Player player)

isPlayerOverLimitsDetail

protected java.lang.String isPlayerOverLimitsDetail(Player player)

mayPlayerBuyCertificate

public boolean mayPlayerBuyCertificate(Player player,
                                       PublicCompanyI comp,
                                       float number)
Check if a player may buy the given number of certificates.

Parameters:
number - Number of certificates to buy (usually 1 but not always so).
Returns:
True if it is allowed.

checkAgainstHoldLimit

public boolean checkAgainstHoldLimit(Player player,
                                     PublicCompanyI company,
                                     int number)
Check if a player may buy the given number of shares from a given company, given the "hold limit" per company, that is the percentage of shares of one company that a player may hold (typically 60%).

Parameters:
player - the buying player
company - The company from which to buy
number - The number of shares (usually 1 but not always so)
Returns:
True if it is allowed.

maxAllowedNumberOfSharesToBuy

public int maxAllowedNumberOfSharesToBuy(Player player,
                                         PublicCompanyI company,
                                         int shareSize)
Return the number of additional shares of a certain company and of a certain size that a player may buy, given the share "hold limit" per company, that is the percentage of shares of one company that a player may hold (typically 60%).

If no hold limit applies, it is taken to be 100%.

Parameters:
company - The company from which to buy
number - The share unit (typically 10%).
Returns:
The maximum number of such shares that would not let the player overrun the per-company share hold limit.

noSaleInFirstSR

protected boolean noSaleInFirstSR()

noSaleIfNotOperated

protected boolean noSaleIfNotOperated()

getHelp

public java.lang.String getHelp()
Specified by:
getHelp in interface RoundI
Overrides:
getHelp in class Round

toString

public java.lang.String toString()
Overrides:
toString in class Round

getRoundName

public java.lang.String getRoundName()
Specified by:
getRoundName in interface RoundI
Overrides:
getRoundName in class Round

isSellObligationLifted

public boolean isSellObligationLifted(PublicCompanyI company)

setSellObligationLifted

public void setSellObligationLifted(PublicCompanyI company)