JSettlers v1.0.6 API
Built ${date}

soc.game
Class SOCGame

java.lang.Object
  extended bysoc.game.SOCGame
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class SOCGame
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A class for holding and manipulating game data

Author:
Robert S. Thomas
See Also:
Serialized Form

Field Summary
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
static SOCResourceSet EMPTY_RESOURCES
          the set of resources a player needs to build a settlement
static boolean LOCKED
           
static int MAXPLAYERS
          maximum number of players in a game
static int NEW
          game states
static int OCCUPIED
           
static int 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
           
static int PLAY
           
static int PLAY1
           
static int READY
           
static SOCResourceSet ROAD_SET
          the set of resources a player needs to build a road
static SOCResourceSet SETTLEMENT_SET
          the set of resources a player needs to build a settlement
static int START1A
           
static int START1B
           
static int START2A
           
static int START2B
           
static boolean UNLOCKED
           
static int VACANT
          seat states
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 next player
 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
 void cancelBuildRoad(int pn)
          a player is UNbuying a road
 void cancelBuildSettlement(int pn)
          a player is UNbuying a settlement
 boolean canChoosePlayer(int pn)
           
 boolean canDiscard(int pn, SOCResourceSet rs)
           
 boolean canDoDiscoveryAction(SOCResourceSet pick)
           
 boolean canDoMonopolyAction()
           
 boolean canEndTurn(int pn)
           
 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)
          return true if the player can play a Road Building card
 boolean canRollDice(int pn)
           
 void checkForWinner()
          check all the vp totals 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
 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
 SOCBoard getBoard()
           
 int getCurrentDice()
           
 int getCurrentPlayerNumber()
           
 long getExpiration()
           
 int getFirstPlayer()
           
 int getGameState()
           
 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()
           
 java.util.Vector getPossibleVictims()
           
 SOCResourceSet getResourcesGainedFromRoll(SOCPlayer player, int roll)
          figure out what resources a player would get on a given roll
 java.util.Date getStartTime()
           
 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
 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)
          a piece has been put on the board
 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
 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
 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
 int stealFromPlayer(int pn)
          the current player has choosen a victim to rob.
 void takeMonitor()
          take the monitor for this game
 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

NEW

public static final int NEW
game states

See Also:
Constant Field Values

READY

public static final int READY
See Also:
Constant Field Values

START1A

public static final int START1A
See Also:
Constant Field Values

START1B

public static final int START1B
See Also:
Constant Field Values

START2A

public static final int START2A
See Also:
Constant Field Values

START2B

public static final int START2B
See Also:
Constant Field Values

PLAY

public static final int PLAY
See Also:
Constant Field Values

PLAY1

public static final int PLAY1
See Also:
Constant Field Values

PLACING_ROAD

public static final int PLACING_ROAD
See Also:
Constant Field Values

PLACING_SETTLEMENT

public static final int PLACING_SETTLEMENT
See Also:
Constant Field Values

PLACING_CITY

public static final int PLACING_CITY
See Also:
Constant Field Values

PLACING_ROBBER

public static final int PLACING_ROBBER
See Also:
Constant Field Values

PLACING_FREE_ROAD1

public static final int PLACING_FREE_ROAD1
See Also:
Constant Field Values

PLACING_FREE_ROAD2

public static final int PLACING_FREE_ROAD2
See Also:
Constant Field Values

WAITING_FOR_DISCARDS

public static final int WAITING_FOR_DISCARDS
See Also:
Constant Field Values

WAITING_FOR_CHOICE

public static final int WAITING_FOR_CHOICE
See Also:
Constant Field Values

WAITING_FOR_DISCOVERY

public static final int WAITING_FOR_DISCOVERY
See Also:
Constant Field Values

WAITING_FOR_MONOPOLY

public static final int WAITING_FOR_MONOPOLY
See Also:
Constant Field Values

OVER

public static final int OVER
See Also:
Constant Field Values

VACANT

public static final int VACANT
seat states

See Also:
Constant Field Values

OCCUPIED

public static final int OCCUPIED
See Also:
Constant Field Values

LOCKED

public static final boolean LOCKED
See Also:
Constant Field Values

UNLOCKED

public static final boolean UNLOCKED
See Also:
Constant Field Values

MAXPLAYERS

public static final int MAXPLAYERS
maximum number of players in a game

See Also:
Constant Field Values

EMPTY_RESOURCES

public static final SOCResourceSet EMPTY_RESOURCES
the set of resources a player needs to build a settlement


SETTLEMENT_SET

public static final SOCResourceSet SETTLEMENT_SET
the set of resources a player needs to build a settlement


ROAD_SET

public static final SOCResourceSet ROAD_SET
the set of resources a player needs to build a road


CITY_SET

public static final SOCResourceSet CITY_SET
the set of resources a player needs to build a city


CARD_SET

public static final SOCResourceSet CARD_SET
the set of resources a player needs to buy a development card

Constructor Detail

SOCGame

public SOCGame(java.lang.String n)
create a new game

Parameters:
n - the name of the game

SOCGame

public SOCGame(java.lang.String n,
               boolean a)
create a new game that can be INACTIVE

Parameters:
n - the name of the game
a - true if this is an active game, false for inactive
Method Detail

takeMonitor

public void takeMonitor()
take the monitor for this game


releaseMonitor

public void releaseMonitor()
release the monitor for this game


allOriginalPlayers

public boolean allOriginalPlayers()
Returns:
allOriginalPlayers

getStartTime

public java.util.Date getStartTime()
Returns:
the start time for this game

getExpiration

public long getExpiration()
Returns:
the expiration time

setExpiration

public void setExpiration(long ex)
set the expiration time

Parameters:
ex - the expiration time in milliseconds

addPlayer

public void addPlayer(java.lang.String name,
                      int pn)
add a new player

Parameters:
name - the player's name
pn - the player's number

removePlayer

public void removePlayer(java.lang.String name)
remove a player

Parameters:
name - the player's name

isSeatVacant

public boolean isSeatVacant(int pn)
Parameters:
pn - the number of the seat
Returns:
true if the seat is VACANT

lockSeat

public void lockSeat(int pn)
locks a seat, so no one can take it

Parameters:
pn - the number of the seat

unlockSeat

public void unlockSeat(int pn)
unlocks a seat

Parameters:
pn - the number of the seat

isSeatLocked

public boolean isSeatLocked(int pn)
Parameters:
pn - the number of the seat
Returns:
true if this seat is locked

getPlayer

public SOCPlayer getPlayer(int pn)
Parameters:
pn - the player number
Returns:
the player object for a player id

getPlayer

public SOCPlayer getPlayer(java.lang.String nn)
Parameters:
nn - the nickname
Returns:
the player object for a player nickname if there is no match, return null

getName

public java.lang.String getName()
Returns:
the name of the game

getBoard

public SOCBoard getBoard()
Returns:
the game board

setBoard

protected void setBoard(SOCBoard gb)
set the game board

Parameters:
gb - the game board

getPlayers

public SOCPlayer[] getPlayers()
Returns:
the list of players

setPlayer

protected void setPlayer(int pn,
                         SOCPlayer pl)
set the data for a player

Parameters:
pn - the number of the player
pl - the player data

getCurrentPlayerNumber

public int getCurrentPlayerNumber()
Returns:
the number of the current player

setCurrentPlayerNumber

public void setCurrentPlayerNumber(int pn)
set the number of the current player

Parameters:
pn - the player number

getCurrentDice

public int getCurrentDice()
Returns:
the current dice result

setCurrentDice

public void setCurrentDice(int dr)
set the current dice result

Parameters:
dr - the dice result

getGameState

public int getGameState()
Returns:
the current game state

setGameState

public void setGameState(int gs)
set the current game state

Parameters:
gs - the game state

getNumDevCards

public int getNumDevCards()
Returns:
the number of dev cards in the deck

setNumDevCards

public void setNumDevCards(int nd)
set the number of dev cards in the deck

Parameters:
nd - the number of dev cards in the deck

getPlayerWithLargestArmy

public SOCPlayer getPlayerWithLargestArmy()
Returns:
the player with the largest army

setPlayerWithLargestArmy

public void setPlayerWithLargestArmy(SOCPlayer pl)
set the player with the largest army

Parameters:
pl - the player

getPlayerWithLongestRoad

public SOCPlayer getPlayerWithLongestRoad()
Returns:
the player with the longest road

setPlayerWithLongestRoad

public void setPlayerWithLongestRoad(SOCPlayer pl)
set the player with the longest road

Parameters:
pl - the player

advanceTurnBackwards

protected void advanceTurnBackwards()
advance the turn to the next player


advanceTurn

protected void advanceTurn()
advance the turn to the next player


putPiece

public void putPiece(SOCPlayingPiece pp)
a piece has been put on the board

Parameters:
pp - the piece to put on the board

putTempPiece

public void putTempPiece(SOCPlayingPiece pp)
a temporary piece has been put on the board

Parameters:
pp - the piece to put on the board

undoPutTempPiece

public void undoPutTempPiece(SOCPlayingPiece pp)
undo the putting of a temporary piece

Parameters:
pp - the piece to put on the board

startGame

public void startGame()
do the things involved in starting a game shuffle the tiles and cards make a board


setFirstPlayer

public void setFirstPlayer(int pn)
sets who the first player is

Parameters:
pn - the seat number of the first player

getFirstPlayer

public int getFirstPlayer()
Returns:
the seat number of the first player

canEndTurn

public boolean canEndTurn(int pn)
Parameters:
pn - player number of the player who wants to end the turn
Returns:
true if its ok for this player end the turn

endTurn

public void endTurn()
end the turn for the current player


canRollDice

public boolean canRollDice(int pn)
Parameters:
pn - player number of the player who wants to roll
Returns:
true if it's ok for this player to roll the dice

rollDice

public IntPair rollDice()
roll the dice


getResourcesGainedFromRoll

public SOCResourceSet getResourcesGainedFromRoll(SOCPlayer player,
                                                 int roll)
figure out what resources a player would get on a given roll

Parameters:
player - the player
roll - the roll
Returns:
the resource set

canDiscard

public boolean canDiscard(int pn,
                          SOCResourceSet rs)
Parameters:
pn - the number of the player that is discarding
rs - the resources that the player is discarding
Returns:
true if the player can discard these resources

discard

public void discard(int pn,
                    SOCResourceSet rs)
A player is discarding resources

Parameters:
pn - the number of the player
rs - the resources that are being discarded

canMoveRobber

public boolean canMoveRobber(int pn,
                             int co)
Parameters:
pn - the number of the player that is moving the robber
co - the coordinates
Returns:
true if the player can move the robber to the coordinates

moveRobber

public SOCMoveRobberResult moveRobber(int pn,
                                      int co)
move the robber

Parameters:
pn - the number of the player that is moving the robber
co - the coordinates
Returns:
returns a result that says if a resource was stolen, or if the player needs to make a choice. It also returns what was stolen and who was the victim.

canChoosePlayer

public boolean canChoosePlayer(int pn)
Parameters:
pn - the number of the player to rob
Returns:
true if the current player can choose a player to rob

getPlayersOnHex

public java.util.Vector getPlayersOnHex(int hex)
Parameters:
hex - the coordinates of the hex
Returns:
a list of players touching a hex

getPossibleVictims

public java.util.Vector getPossibleVictims()
Returns:
a list of possible players to rob

stealFromPlayer

public int stealFromPlayer(int pn)
the current player has choosen a victim to rob. perform the robbery.

Parameters:
pn - the number of the player being robbed
Returns:
the type of resource that was stolen

canMakeTrade

public boolean canMakeTrade(int offering,
                            int accepting)
Parameters:
offering - the number of the player making the offer
accepting - the number of the player accepting the offer
Returns:
true if the two players can make the trade described in the offering players current offer

makeTrade

public void makeTrade(int offering,
                      int accepting)
perform a trade between two players the trade performed is described in the offering player's current offer

Parameters:
offering - the number of the player making the offer
accepting - the number of the player accepting the offer

canMakeBankTrade

public boolean canMakeBankTrade(SOCResourceSet give,
                                SOCResourceSet get)
Parameters:
give - what the player will give to the bank
get - what the player wants from the bank
Returns:
true if the current player can make a particular bank/port trade

makeBankTrade

public void makeBankTrade(SOCResourceSet give,
                          SOCResourceSet get)
perform a bank trade

Parameters:
give - the number of the player making the offer
get - the number of the player accepting the offer

couldBuildRoad

public boolean couldBuildRoad(int pn)
Parameters:
pn - the number of the player
Returns:
true if the player has the resources, pieces, and room to build a road

couldBuildSettlement

public boolean couldBuildSettlement(int pn)
Parameters:
pn - the number of the player
Returns:
true if the player has the resources, pieces, and room to build a settlement

couldBuildCity

public boolean couldBuildCity(int pn)
Parameters:
pn - the number of the player
Returns:
true if the player has the resources, pieces, and room to build a city

couldBuyDevCard

public boolean couldBuyDevCard(int pn)
Parameters:
pn - the number of the player
Returns:
true if the player has the resources to buy a dev card, and if there are dev cards left to buy

buyRoad

public void buyRoad(int pn)
a player is buying a road

Parameters:
pn - the number of the player

buySettlement

public void buySettlement(int pn)
a player is buying a settlement

Parameters:
pn - the number of the player

buyCity

public void buyCity(int pn)
a player is buying a city

Parameters:
pn - the number of the player

cancelBuildRoad

public void cancelBuildRoad(int pn)
a player is UNbuying a road

Parameters:
pn - the number of the player

cancelBuildSettlement

public void cancelBuildSettlement(int pn)
a player is UNbuying a settlement

Parameters:
pn - the number of the player

cancelBuildCity

public void cancelBuildCity(int pn)
a player is UNbuying a city

Parameters:
pn - the number of the player

buyDevCard

public int buyDevCard()
the current player is buying a dev card

Returns:
the card that was drawn

canPlayKnight

public boolean canPlayKnight(int pn)
Parameters:
pn - the number of the player
Returns:
true if the player can play a knight card

canPlayRoadBuilding

public boolean canPlayRoadBuilding(int pn)
return true if the player can play a Road Building card

Parameters:
pn - the number of the player

canPlayDiscovery

public boolean canPlayDiscovery(int pn)
return true if the player can play a Discovery card

Parameters:
pn - the number of the player

canPlayMonopoly

public boolean canPlayMonopoly(int pn)
return true if the player can play a Monopoly card

Parameters:
pn - the number of the player

playKnight

public void playKnight()
the current player plays a Knight card


playRoadBuilding

public void playRoadBuilding()
the current player plays a Road Building card


playDiscovery

public void playDiscovery()
the current player plays a Discovery card


playMonopoly

public void playMonopoly()
the current player plays a monopoly card


canDoDiscoveryAction

public boolean canDoDiscoveryAction(SOCResourceSet pick)
Parameters:
pick - the resources that the player wants
Returns:
true if the current player can do the discovery card action and the pick contains exactly 2 resources

canDoMonopolyAction

public boolean canDoMonopolyAction()
Returns:
true if the current player can do the Monopoly card action

doDiscoveryAction

public void doDiscoveryAction(SOCResourceSet pick)
perform the Discovery card action

Parameters:
pick - what the player picked

doMonopolyAction

public void doMonopolyAction(int pick)
perform the Monopoly card action

Parameters:
pick - the type of resource to monopolize

updateLargestArmy

public void updateLargestArmy()
update which player has the largest army larger than 2


saveLargestArmyState

public void saveLargestArmyState()
save the state of who has largest army


restoreLargestArmyState

public void restoreLargestArmyState()
restore the state of who had largest army


updateLongestRoad

public 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

Parameters:
pn - the number of the player who is affected

checkForWinner

public void checkForWinner()
check all the vp totals to see if the game is over


destroyGame

public void destroyGame()
set vars to null so gc can clean up


JSettlers v1.0.6 API
Built ${date}