|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectsoc.game.SOCGame
A class for holding and manipulating game data.
Most methods are not implicitly thread-safe;
call takeMonitor() and releaseMonitor() around them.
The model in this client/server game is: The SOCGame at server contains the game's
complete state information, and game logic advances there.
Each client's local SOCGame contains only partial state (for instance, other
players' resources or devel cards may be of unknown type); and the server directly
updates clients' game state by sending messages such as
SOCGameState and SOCSetPlayedDevCard.
For the board coordinate system and terms (hex, node, edge), see the
SOCBoard class javadoc.
putPiece(SOCPlayingPiece) and other game-action methods update gameState.
| Field Summary | |
private boolean |
active
true if this game is ACTIVE |
(package private) boolean |
allOriginalPlayers
used to track if there were any player subs |
private SOCBoard |
board
the game board |
private int |
boardResetVoteRequester
If a board reset vote is active, player number who requested the vote. |
private int[] |
boardResetVotes
If a board reset vote is active, votes are recorded here. |
private int |
boardResetVotesWaiting
If a board reset vote is active, we're waiting to receive this many more votes. |
static SOCResourceSet |
CARD_SET
the set of resources a player needs to buy a development card |
static SOCResourceSet |
CITY_SET
the set of resources a player needs to build a city |
int |
clientVersionHighest
For use at server; lowest and highest version of connected clients. |
int |
clientVersionLowest
For use at server; lowest and highest version of connected clients. |
private int |
currentDice
the current dice result |
private int |
currentPlayerNumber
the number of the current player |
private int[] |
devCardDeck
the development card deck |
static SOCResourceSet |
EMPTY_RESOURCES
the set of resources a player needs to build a settlement |
(package private) long |
expiration
expiration time for this game in milliseconds |
private int |
firstPlayerNumber
the first player to place a settlement |
private boolean |
forcingEndTurn
If true, this turn is being ended. |
private int |
gameState
the current game state |
boolean |
hasOldClients
For use at server; are there clients connected which aren't at the latest version? |
(package private) boolean |
inUse
monitor for synchronization |
private boolean |
isFromBoardReset
true if the game came from a board reset |
boolean |
isLocal
true if the game's network is local for practice. |
private int |
lastPlayerNumber
the last player to place the first settlement |
static boolean |
LOCKED
seatLock states |
static int |
MAXPLAYERS
maximum number of players in a game |
static int |
MINPLAYERS
minimum number of players in a game (was assumed ==MAXPLAYERS in standard 1.0.6). |
private java.lang.String |
name
the name of the game |
static int |
NEW
Game states. |
private int |
numDevCards
the number of development cards left |
static int |
OCCUPIED
seat states |
private int |
oldGameState
the old game state |
private int |
oldPlayerWithLargestArmy
|
(package private) java.util.Stack |
oldPlayerWithLongestRoad
used to restore the LR player |
static int |
OVER
The game is over. |
static int |
PLACING_CITY
|
static int |
PLACING_FREE_ROAD1
|
static int |
PLACING_FREE_ROAD2
|
static int |
PLACING_ROAD
|
static int |
PLACING_ROBBER
|
static int |
PLACING_SETTLEMENT
|
private boolean |
placingRobberForKnightCard
If true, and if state is PLACING_ROBBER,
the robber is being moved because a knight card
has just been played. |
static int |
PLAY
Start of a normal turn. |
static int |
PLAY1
Done rolling (or moving robber on 7). |
private SOCPlayer[] |
players
the players; never contains a null element, use isSeatVacant(int)
to see if a position is occupied. |
private int |
playerWithLargestArmy
the player with the largest army, or -1 if none |
private int |
playerWithLongestRoad
the player with the longest road, or -1 if none |
private int |
playerWithWin
the player declared winner, if gamestate == OVER; otherwise -1 |
private java.util.Random |
rand
used to generate random numbers |
static int |
READY
Ready to start playing. |
static int |
RESET_OLD
This game is an obsolete old copy of a new (reset) game with the same name. |
static SOCResourceSet |
ROAD_SET
the set of resources a player needs to build a road |
private boolean[] |
seatLocks
the states if the locks for the player's seats |
private int[] |
seats
the states for the player's seats |
static int |
SETOPTIONS_EXCL
|
static int |
SETOPTIONS_INCL
|
static SOCResourceSet |
SETTLEMENT_SET
the set of resources a player needs to build a settlement |
static int |
START1A
Players place first settlement. |
static int |
START1B
Players place first road. |
static int |
START2A
Players place second settlement. |
static int |
START2B
Players place second road. |
(package private) java.util.Date |
startTime
when this game was created |
static boolean |
UNLOCKED
seatLock states |
static int |
VACANT
seat states |
static int |
VOTE_NO
|
static int |
VOTE_NONE
boardResetVotes per-player states: no vote sent; yes; no. |
static int |
VOTE_YES
|
static int |
VP_WINNER
Number of victory points (10) needed to win. |
static int |
WAITING_FOR_CHOICE
|
static int |
WAITING_FOR_DISCARDS
|
static int |
WAITING_FOR_DISCOVERY
|
static int |
WAITING_FOR_MONOPOLY
|
| Constructor Summary | |
SOCGame(java.lang.String n)
create a new game |
|
SOCGame(java.lang.String n,
boolean a)
create a new game that can be INACTIVE |
|
| Method Summary | |
void |
addPlayer(java.lang.String name,
int pn)
add a new player |
protected void |
advanceTurn()
advance the turn to the next player |
protected void |
advanceTurnBackwards()
advance the turn to the previous player, used during initial placement |
private void |
advanceTurnStateAfterPutPiece()
After placing a piece on the board, update the state of the game, and possibly current player, for play to continue. |
boolean |
allOriginalPlayers()
|
void |
buyCity(int pn)
a player is buying a city |
int |
buyDevCard()
the current player is buying a dev card |
void |
buyRoad(int pn)
a player is buying a road |
void |
buySettlement(int pn)
a player is buying a settlement |
void |
cancelBuildCity(int pn)
a player is UNbuying a city; return resources, set gameState PLAY1 |
void |
cancelBuildRoad(int pn)
a player is UNbuying a road; return resources, set gameState PLAY1 |
void |
cancelBuildSettlement(int pn)
a player is UNbuying a settlement; return resources, set gameState PLAY1 |
boolean |
canChoosePlayer(int pn)
|
boolean |
canDiscard(int pn,
SOCResourceSet rs)
|
boolean |
canDoDiscoveryAction(SOCResourceSet pick)
|
boolean |
canDoMonopolyAction()
|
boolean |
canEndTurn(int pn)
Can this player end the current turn? |
boolean |
canMakeBankTrade(SOCResourceSet give,
SOCResourceSet get)
|
boolean |
canMakeTrade(int offering,
int accepting)
|
boolean |
canMoveRobber(int pn,
int co)
|
boolean |
canPlayDiscovery(int pn)
return true if the player can play a Discovery card |
boolean |
canPlayKnight(int pn)
|
boolean |
canPlayMonopoly(int pn)
return true if the player can play a Monopoly card |
boolean |
canPlayRoadBuilding(int pn)
Can the current player play a Road Building card? |
boolean |
canRollDice(int pn)
|
void |
checkForWinner()
check current player's vp total to see if the game is over. |
boolean |
couldBuildCity(int pn)
|
boolean |
couldBuildRoad(int pn)
|
boolean |
couldBuildSettlement(int pn)
|
boolean |
couldBuyDevCard(int pn)
|
void |
destroyGame()
set vars to null so gc can clean up |
void |
discard(int pn,
SOCResourceSet rs)
A player is discarding resources. |
static void |
discardPickRandom(SOCResourceSet fromHand,
int numDiscards,
SOCResourceSet discards,
java.util.Random rand)
Choose discards at random; does not actually discard anything. |
void |
doDiscoveryAction(SOCResourceSet pick)
perform the Discovery card action |
void |
doMonopolyAction(int pick)
perform the Monopoly card action |
void |
endTurn()
end the turn for the current player, and check for winner. |
SOCForceEndTurnResult |
forceEndTurn()
In an active game, force current turn to be able to be ended. |
private SOCForceEndTurnResult |
forceEndTurnChkDiscards(int pn)
Randomly discard from this player's hand, by calling discard(int, SOCResourceSet). |
private SOCForceEndTurnResult |
forceEndTurnStartState(boolean advTurnForward)
Special forceEndTurn() treatment for start-game states. |
java.lang.String |
gameOverMessageToPlayer(SOCPlayer pl)
If game is over, formulate a message to tell a player. |
SOCBoard |
getBoard()
|
int |
getCurrentDice()
|
int |
getCurrentPlayerNumber()
|
long |
getExpiration()
|
int |
getFirstPlayer()
|
int |
getGameState()
Current game state. |
java.lang.String |
getName()
|
int |
getNumDevCards()
|
SOCPlayer |
getPlayer(int pn)
|
SOCPlayer |
getPlayer(java.lang.String nn)
|
SOCPlayer[] |
getPlayers()
|
java.util.Vector |
getPlayersOnHex(int hex)
|
SOCPlayer |
getPlayerWithLargestArmy()
|
SOCPlayer |
getPlayerWithLongestRoad()
|
SOCPlayer |
getPlayerWithWin()
Find the player who was declared winner at end of game. |
java.util.Vector |
getPossibleVictims()
|
int |
getResetOldGameState()
If the game board was reset, get the old game state. |
int |
getResetPlayerVote(int pn)
Get this player's vote on a board reset request. |
boolean |
getResetVoteActive()
|
int |
getResetVoteRequester()
If a board reset vote is active, player number who requested the vote. |
boolean |
getResetVoteResult()
If a board-reset vote is complete, give its result. |
SOCResourceSet |
getResourcesGainedFromRoll(SOCPlayer player,
int roll)
figure out what resources a player would get on a given roll |
java.util.Date |
getStartTime()
|
boolean |
isBoardReset()
|
boolean |
isForcingEndTurn()
If true, this turn is being ended. |
boolean |
isSeatLocked(int pn)
|
boolean |
isSeatVacant(int pn)
|
void |
lockSeat(int pn)
locks a seat, so no one can take it |
void |
makeBankTrade(SOCResourceSet give,
SOCResourceSet get)
perform a bank trade |
void |
makeTrade(int offering,
int accepting)
perform a trade between two players the trade performed is described in the offering player's current offer |
SOCMoveRobberResult |
moveRobber(int pn,
int co)
move the robber. |
void |
playDiscovery()
the current player plays a Discovery card |
SOCResourceSet |
playerDiscardRandom(int pn)
Force this non-current player to discard randomly. |
void |
playKnight()
the current player plays a Knight card |
void |
playMonopoly()
the current player plays a monopoly card |
void |
playRoadBuilding()
The current player plays a Road Building card. |
void |
putPiece(SOCPlayingPiece pp)
Put this piece on the board and update all related game state. |
void |
putTempPiece(SOCPlayingPiece pp)
a temporary piece has been put on the board |
void |
releaseMonitor()
release the monitor for this game |
void |
removePlayer(java.lang.String name)
remove a player |
SOCGame |
resetAsCopy()
Create a new game with same players and name, new board; like calling constructor otherwise. |
void |
resetVoteBegin(int reqPN)
Begin a board-reset vote. |
void |
resetVoteClear()
At end of turn, clear flags for board reset voting: requester, players' setAskedBoardReset. |
boolean |
resetVoteRegister(int pn,
boolean votingYes)
Register this player's vote in a board reset request. |
void |
restoreLargestArmyState()
restore the state of who had largest army |
IntPair |
rollDice()
roll the dice |
void |
saveLargestArmyState()
save the state of who has largest army |
protected void |
setBoard(SOCBoard gb)
set the game board |
void |
setCurrentDice(int dr)
set the current dice result |
void |
setCurrentPlayerNumber(int pn)
Set the number of the current player, and check for winner. |
void |
setExpiration(long ex)
set the expiration time |
void |
setFirstPlayer(int pn)
sets who the first player is |
void |
setGameState(int gs)
set the current game state. |
void |
setNumDevCards(int nd)
set the number of dev cards in the deck |
protected void |
setPlayer(int pn,
SOCPlayer pl)
set the data for a player |
void |
setPlayerWithLargestArmy(SOCPlayer pl)
set the player with the largest army |
void |
setPlayerWithLongestRoad(SOCPlayer pl)
set the player with the longest road |
void |
startGame()
do the things involved in starting a game: shuffle the tiles and cards, make a board, choose first player. |
int |
stealFromPlayer(int pn)
the current player has choosen a victim to rob. |
void |
takeMonitor()
take the monitor for this game |
void |
undoPutInitSettlement(SOCPlayingPiece pp)
undo the putting of an initial settlement. |
protected void |
undoPutPieceCommon(SOCPlayingPiece pp)
undo the putting of a temporary or initial piece |
void |
undoPutTempPiece(SOCPlayingPiece pp)
undo the putting of a temporary piece |
void |
unlockSeat(int pn)
unlocks a seat |
void |
updateLargestArmy()
update which player has the largest army larger than 2 |
void |
updateLongestRoad(int pn)
update which player has longest road longer than 4 this version only calculates the longest road for the player who is affected by the most recently placed piece |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int NEW
READY if robots, or START1A if only humans
are playing.
General assumptions for states and their numeric values:
START1A and < OVER
START2B, going directly to PLAY
PLAY1, after dice-roll/card-play in PLAY
PLAY1, < OVER; state name starts with
PLACING_ or WAITING_
The code reacts to (switches based on) game state in several places. The main places to check, if you add a game state:
SOCBoardPanel.updateMode()
SOCBuildingPanel.updateButtonStatus()
SOCPlayerInterface.updateAtGameState()
putPiece(SOCPlayingPiece)
SOCRobotBrain.run()
SOCServer.sendGameState(SOCGame)
Other places to check, if you add a game state:
SOCBoardPanel.BoardPopupMenu.showBuild, showCancelBuild
SOCBoardPanel.drawBoard
SOCHandPanel.addPlayer, began, removePlayer, updateAtTurn, updateValue
SOCGame.addPlayer
SOCServer.handleSTARTGAME, leaveGame, sitDown, handleCANCELBUILDREQUEST, handlePUTPIECE
SOCPlayerClient.handleCANCELBUILDREQUEST, SOCDisplaylessPlayerClient.handleCANCELBUILDREQUEST
public static final int READY
START1A.
public static final int SETOPTIONS_EXCL
public static final int SETOPTIONS_INCL
public static final int START1A
START1B to place each player's 1st road.
public static final int START1B
START1A to place next
player's 1st settlement, or if all have placed settlements,
START2A to place 2nd settlement.
public static final int START2A
START2B to place 2nd road.
public static final int START2B
START2A to place previous
player's 2nd settlement (player changes in reverse order), or if all have placed
settlements, PLAY to begin first player's turn.
public static final int PLAY
PLAY1.
public static final int PLAY1
PLAY.
public static final int PLACING_ROAD
public static final int PLACING_SETTLEMENT
public static final int PLACING_CITY
public static final int PLACING_ROBBER
public static final int PLACING_FREE_ROAD1
public static final int PLACING_FREE_ROAD2
public static final int WAITING_FOR_DISCARDS
public static final int WAITING_FOR_CHOICE
public static final int WAITING_FOR_DISCOVERY
public static final int WAITING_FOR_MONOPOLY
public static final int OVER
VP_WINNER) victory points.
public static final int RESET_OLD
OVER.
resetAsCopy(),
getResetOldGameState(),
Constant Field Valuespublic static final int VACANT
public static final int OCCUPIED
public static final boolean LOCKED
public static final boolean UNLOCKED
public static final int VOTE_NONE
boardResetVotes per-player states: no vote sent; yes; no.
public static final int VOTE_YES
public static final int VOTE_NO
public static final int MAXPLAYERS
public static final int MINPLAYERS
public static final int VP_WINNER
public static final SOCResourceSet EMPTY_RESOURCES
public static final SOCResourceSet SETTLEMENT_SET
public static final SOCResourceSet ROAD_SET
public static final SOCResourceSet CITY_SET
public static final SOCResourceSet CARD_SET
boolean inUse
private java.lang.String name
private boolean active
public boolean isLocal
public boolean hasOldClients
public int clientVersionLowest
public int clientVersionHighest
private boolean isFromBoardReset
private int boardResetVoteRequester
boardResetVotes before reading or writing.
private int[] boardResetVotes
VOTE_NONE, VOTE_YES, VOTE_NO.
Indexed 0 to SOCGame.MAXPLAYERS-1.
Synchronize on this object before reading or writing.
private int boardResetVotesWaiting
boardResetVotes before reading or writing.
When the vote is complete, this is 0.
Undefined before the first vote; this field is not reset each turn.
Set in resetVoteBegin, resetVoteRegister.
private SOCBoard board
private SOCPlayer[] players
isSeatVacant(int)
to see if a position is occupied.
private int[] seats
private boolean[] seatLocks
private int currentPlayerNumber
private int firstPlayerNumber
private int lastPlayerNumber
private int currentDice
private int gameState
private int oldGameState
private boolean placingRobberForKnightCard
PLACING_ROBBER,
the robber is being moved because a knight card
has just been played. This, if forceEndTurn()
is called, the knight card should be returned to
the player's hand.
private boolean forcingEndTurn
endTurn()
whenever possible. Usually set when we have called forceEndTurn(), and
forced the current player to discard randomly, and are waiting for other players
to discard in gamestate WAITING_FOR_DISCARDS. Once all players have
discarded, the turn should be ended.
forceEndTurn()private int playerWithLargestArmy
private int oldPlayerWithLargestArmy
private int playerWithLongestRoad
private int playerWithWin
private int numDevCards
private int[] devCardDeck
private java.util.Random rand
boolean allOriginalPlayers
java.util.Stack oldPlayerWithLongestRoad
java.util.Date startTime
long expiration
| Constructor Detail |
public SOCGame(java.lang.String n)
n - the name of the game
public SOCGame(java.lang.String n,
boolean a)
n - the name of the gamea - true if this is an active game, false for inactive| Method Detail |
public void takeMonitor()
public void releaseMonitor()
public boolean allOriginalPlayers()
public java.util.Date getStartTime()
public long getExpiration()
Date.getTime()public void setExpiration(long ex)
ex - the expiration time in milliseconds,
same epoch as Date.getTime()
public void addPlayer(java.lang.String name,
int pn)
name - the player's namepn - the player's numberpublic void removePlayer(java.lang.String name)
name - the player's namepublic boolean isSeatVacant(int pn)
pn - the number of the seat
public void lockSeat(int pn)
pn - the number of the seatpublic void unlockSeat(int pn)
pn - the number of the seatpublic boolean isSeatLocked(int pn)
pn - the number of the seat
public SOCPlayer getPlayer(int pn)
pn - the player number, in range 0 to MAXPLAYERS-1
public SOCPlayer getPlayer(java.lang.String nn)
nn - the nickname
public java.lang.String getName()
public boolean isBoardReset()
public SOCBoard getBoard()
protected void setBoard(SOCBoard gb)
gb - the game boardpublic SOCPlayer[] getPlayers()
protected void setPlayer(int pn,
SOCPlayer pl)
pn - the number of the playerpl - the player datapublic int getCurrentPlayerNumber()
public void setCurrentPlayerNumber(int pn)
OVER after calling
setCurrentPlayerNumber.
This is needed because a player can win only during their own turn;
if they reach winning points (VP_WINNER or more) during another
player's turn, they must wait.
pn - the player numberendTurn(),
checkForWinner()public int getCurrentDice()
public void setCurrentDice(int dr)
dr - the dice resultpublic int getGameState()
NEW.
public void setGameState(int gs)
OVER, and no playerWithWin yet determined, call checkForWinner.
For general information about what states are expected when,
please see the javadoc for NEW.
gs - the game statecheckForWinner()
public int getResetOldGameState()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - Game state must be RESET_OLD
when called; during normal game play, oldGameState is private.public boolean isForcingEndTurn()
endTurn()
whenever possible. Usually set if we have called forceEndTurn(), and
forced the current player to discard randomly, and are waiting for other players
to discard in gamestate WAITING_FOR_DISCARDS. Once all players have
discarded, the turn should be ended.
forceEndTurn()public int getNumDevCards()
public void setNumDevCards(int nd)
nd - the number of dev cards in the deckpublic SOCPlayer getPlayerWithLargestArmy()
public void setPlayerWithLargestArmy(SOCPlayer pl)
pl - the playerpublic SOCPlayer getPlayerWithLongestRoad()
public void setPlayerWithLongestRoad(SOCPlayer pl)
pl - the playerpublic SOCPlayer getPlayerWithWin()
checkForWinner(); there is no corresponding setter.
public java.lang.String gameOverMessageToPlayer(SOCPlayer pl)
throws java.lang.IllegalStateException
pl - Player to tell (may be the winner)
java.lang.IllegalStateException - If the game state is not OVERprotected void advanceTurnBackwards()
protected void advanceTurn()
public void putPiece(SOCPlayingPiece pp)
pp - the piece to put on the boardprivate void advanceTurnStateAfterPutPiece()
Also used in forceEndTurn() to continue the game
after a cancelled piece placement in START1A..START2B .
If the current player number changes here, isForcingEndTurn() is cleared.
public void putTempPiece(SOCPlayingPiece pp)
pp - the piece to put on the boardprotected void undoPutPieceCommon(SOCPlayingPiece pp)
pp - the piece to put on the boardpublic void undoPutTempPiece(SOCPlayingPiece pp)
pp - the piece to put on the boardundoPutInitSettlement(SOCPlayingPiece)public void undoPutInitSettlement(SOCPlayingPiece pp)
pp - the piece to remove from the boardpublic void startGame()
START1A.
public void setFirstPlayer(int pn)
pn - the seat number of the first playerpublic int getFirstPlayer()
public boolean canEndTurn(int pn)
In some states, the current player can't end their turn yet (such as needing to move the robber, or choose resources for a year-of-plenty card, or discard if a 7 is rolled).
pn - player number of the player who wants to end the turn
PLAY1)endTurn(),
forceEndTurn()public void endTurn()
OVER after calling endTurn.
endTurn() is called only at server - client instead calls
setCurrentPlayerNumber.
The winner check is needed because a player can win only
during their own turn; if they reach winning points (VP_WINNER
or more) during another player's turn, they must wait.
setCurrentPlayerNumber(int),
checkForWinner(),
forceEndTurn(),
isForcingEndTurn()
public SOCForceEndTurnResult forceEndTurn()
throws java.lang.IllegalStateException
PLAY1, but does not call endTurn().
May be used if player loses connection, or robot does not respond.
TODO finish this javadoc...
Since only the server calls endTurn(), this method does not do so.
After calling forceEndTurn, usually the gameState will be PLAY1,
and the caller should call endTurn(). The isForcingEndTurn()
flag is also set.
Exceptions (caller should not call endTurn) are these return types:
SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_DISCARD_WAIT
- Have forced current player to discard randomly, must now
wait for other players to discard.
gameState is WAITING_FOR_DISCARDS, current player
as yet unchanged.
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADV
- During initial placement, have skipped placement of
a player's first settlement or road.
gameState is START1A, current player has changed.
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADVBACK
- During initial placement, have skipped placement of
a player's second settlement or road. (Or, final player's
first _and_ second settlement or road.)
gameState is START2A, current player has changed.
Note that for the very last initial road placed, during normal
gameplay, that player continues by rolling the first turn's dice.
To force skipping such a placement, the caller should call endTurn()
to change the current player. This is indicated by
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_TURN.
SOCForceEndTurnResult.FORCE_ENDTURN_NONE
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADV
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADVBACK
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_TURN
SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_RET_UNPLACE
SOCForceEndTurnResult.FORCE_ENDTURN_UNPLACE_ROBBER
SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_DISCARD
SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_DISCARD_WAIT
SOCForceEndTurnResult.FORCE_ENDTURN_LOST_CHOICE
java.lang.IllegalStateException - if game is not active
(gamestate < START1A or >= OVER)canEndTurn(int),
endTurn()private SOCForceEndTurnResult forceEndTurnStartState(boolean advTurnForward)
forceEndTurn() for description.
advTurnForward - Should the next player be normal (placing first settlement),
or backwards (placing second settlement)?
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADV,
SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_ADVBACK,
or SOCForceEndTurnResult.FORCE_ENDTURN_SKIP_START_TURN.private SOCForceEndTurnResult forceEndTurnChkDiscards(int pn)
discard(int, SOCResourceSet).
Then look at other players' hand size. If no one else must discard,
ready to end turn, set state PLAY1.
Otherwise, must wait for them; if so,
set game state to WAITING_FOR_DISCARDS.
When called, assumes isForcingEndTurn() flag is already set.
pn - Player number to force to randomly discard
SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_DISCARD
or SOCForceEndTurnResult.FORCE_ENDTURN_RSRC_DISCARD_WAIT.
public static void discardPickRandom(SOCResourceSet fromHand,
int numDiscards,
SOCResourceSet discards,
java.util.Random rand)
fromHand - Discard from this setnumDiscards - This many must be discardeddiscards - Add discards to this set (typically new,empty, when called)rand - Source of random
public SOCResourceSet playerDiscardRandom(int pn)
throws java.lang.IllegalStateException
On return, gameState will be:
WAITING_FOR_DISCARDS if other players still must discard
PLAY1 if everyone has discarded, and isForcingEndTurn() is set
PLACING_ROBBER if everyone has discarded, and isForcingEndTurn() is not set
pn - Player number to discard; player must must need to discard,
must not be current player (use forceEndTurn() for that)
java.lang.IllegalStateException - If the gameState isn't WAITING_FOR_DISCARDS,
or if pn's SOCPlayer.getNeedToDiscard() is false,
or if pn == currentPlayer.public boolean canRollDice(int pn)
pn - player number of the player who wants to roll
public IntPair rollDice()
public SOCResourceSet getResourcesGainedFromRoll(SOCPlayer player,
int roll)
player - the playerroll - the roll
public boolean canDiscard(int pn,
SOCResourceSet rs)
pn - the number of the player that is discardingrs - the resources that the player is discarding
public void discard(int pn,
SOCResourceSet rs)
WAITING_FOR_DISCARDS
or PLACING_ROBBER accordingly.
Special case:
If isForcingEndTurn(), and no one else needs to discard,
gameState becomes PLAY1 but the caller must call
endTurn() as soon as possible.
pn - the number of the playerrs - the resources that are being discarded
public boolean canMoveRobber(int pn,
int co)
pn - the number of the player that is moving the robberco - the coordinates
public SOCMoveRobberResult moveRobber(int pn,
int co)
pn - the number of the player that is moving the robberco - the coordinates
public boolean canChoosePlayer(int pn)
pn - the number of the player to rob
public java.util.Vector getPlayersOnHex(int hex)
hex - the coordinates of the hex
public java.util.Vector getPossibleVictims()
public int stealFromPlayer(int pn)
pn - the number of the player being robbed
SOCResourceConstants
public boolean canMakeTrade(int offering,
int accepting)
offering - the number of the player making the offeraccepting - the number of the player accepting the offer
public void makeTrade(int offering,
int accepting)
offering - the number of the player making the offeraccepting - the number of the player accepting the offer
public boolean canMakeBankTrade(SOCResourceSet give,
SOCResourceSet get)
give - what the player will give to the bankget - what the player wants from the bank
public void makeBankTrade(SOCResourceSet give,
SOCResourceSet get)
give - the number of the player making the offerget - the number of the player accepting the offerpublic boolean couldBuildRoad(int pn)
pn - the number of the player
public boolean couldBuildSettlement(int pn)
pn - the number of the player
public boolean couldBuildCity(int pn)
pn - the number of the player
public boolean couldBuyDevCard(int pn)
pn - the number of the player
public void buyRoad(int pn)
pn - the number of the playerpublic void buySettlement(int pn)
pn - the number of the playerpublic void buyCity(int pn)
pn - the number of the playerpublic void cancelBuildRoad(int pn)
pn - the number of the playerpublic void cancelBuildSettlement(int pn)
pn - the number of the playerpublic void cancelBuildCity(int pn)
pn - the number of the playerpublic int buyDevCard()
public boolean canPlayKnight(int pn)
pn - the number of the player
public boolean canPlayRoadBuilding(int pn)
This card directs the player to place 2 roads. Checks of game rules online show they "MAY" or "CAN", not "MUST", place 2. If they have 2 or more roads, place 2. If they have just 1 road, place 1. If they have 0 roads, cannot play the card.
pn - the number of the player
public boolean canPlayDiscovery(int pn)
pn - the number of the playerpublic boolean canPlayMonopoly(int pn)
pn - the number of the playerpublic void playKnight()
public void playRoadBuilding()
canPlayRoadBuilding(int) has already been called, and move is valid.
public void playDiscovery()
public void playMonopoly()
public boolean canDoDiscoveryAction(SOCResourceSet pick)
pick - the resources that the player wants
public boolean canDoMonopolyAction()
public void doDiscoveryAction(SOCResourceSet pick)
pick - what the player pickedpublic void doMonopolyAction(int pick)
pick - the type of resource to monopolizepublic void updateLargestArmy()
public void saveLargestArmyState()
public void restoreLargestArmyState()
public void updateLongestRoad(int pn)
pn - the number of the player who is affectedpublic void checkForWinner()
Per rules FAQ, a player can win only during their own turn. If a player reaches winning points (VP_WINNER or more) but it's not their turn, there is not yet a winner. This could happen if, for example, the longest road is broken by a new settlement, and the next-longest road is not the current player's road.
getGameState(),
getPlayerWithWin()public void destroyGame()
public SOCGame resetAsCopy()
Old game's state becomes RESET_OLD.
Old game's previous state is saved to getResetOldGameState().
Please call destroyGame() on old game when done examining its state.
Assumes that if the game had more than one human player, they've already voted interactively to reset the board.
resetVoteBegin(int)
public void resetVoteBegin(int reqPN)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException
reqPN - Player number requesting the vote
java.lang.IllegalArgumentException - If this player number has already
requested a reset this turn
java.lang.IllegalStateException - If there is alread a vote in progressgetResetVoteRequester(),
resetVoteRegister(int, boolean),
getResetVoteResult()public int getResetVoteRequester()
resetVoteBegin(int)public boolean getResetVoteActive()
public boolean resetVoteRegister(int pn,
boolean votingYes)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException
pn - Player numbervotingYes - Are they voting yes, or no?
java.lang.IllegalArgumentException - If pn already voted, or can't vote (vacant or robot).
java.lang.IllegalStateException - If voting is not currently active.getResetPlayerVote(int)public int getResetPlayerVote(int pn)
pn - Player number
VOTE_YES, VOTE_NO,
or if player hasn't yet voted, VOTE_NONE.resetVoteRegister(int, boolean),
getResetVoteResult()public void resetVoteClear()
endTurn() because
endTurn is called only at the server, not at clients.
Do not call this to cancel a vote, because it would
allow players to ask for a reset more than once per turn.
public boolean getResetVoteResult()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if voting is still active. See getResetVoteActive().getResetPlayerVote(int)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||