net.sf.colossus.game
Class Game

java.lang.Object
  extended by net.sf.colossus.game.Game
Direct Known Subclasses:
GameClientSide, GameServerSide

public class Game
extends java.lang.Object

An ongoing game in Colossus. As opposed to Variant this class holds information about an ongoing game and its status.


Field Summary
protected  Battle battle
           
private  BattleStrike battleStrike
           
private  Caretaker caretaker
          The caretaker takes care of managing the available and dead creatures.
private  Engagement engagement
           
private  boolean gameOver
          Status for Game is over and message for it On client side this also implies: If the game is over, then quitting does not require confirmation.
private  java.lang.String gameOverMessage
           
private static java.util.logging.Logger LOGGER
           
private  int movementRoll
          Last movement roll for any player.
protected  Phase phase
          The current game phase (Split, Move, Fight, Muster)
protected  java.util.List<Player> players
          The state of the different players in the game.
protected  int turnNumber
          The current turn number.
private  Variant variant
          The variant played in this game.
 
Constructor Summary
Game(Variant variant, java.lang.String[] playerNames)
          Create a Game object.
 
Method Summary
 void addPlayer(Player p)
           
 void clearEngagementData()
           
 boolean containsOpposingLegions(MasterHex hex)
          Return set of hexLabels for engagements found.
 void createEngagement(MasterHex hex, Legion attacker, Legion defender)
           
(package private)  java.util.List<CreatureType> findAvailableEligibleAngels(MasterBoardTerrain terrain, int score)
          Return a list of angel types that can be acquired based on the hex in which legion is, when reaching given score threshold, and if they are still available from caretaker
 java.util.Set<MasterHex> findEngagements()
          Return a set of all hexes with engagements.
 java.util.List<Legion> findLegionsWithSummonables(Legion summoner)
          Return a set of all other unengaged legions of the legion's player that have summonables (not sorted in any particular order).
 java.util.List<Legion> getAllLegions()
          Return a list of all legions of all players.
 Legion getAttacker()
           
 Battle getBattle()
           
 Legion getBattleActiveLegion()
           
 MasterHex getBattleSite()
           
 BattleStrike getBattleStrike()
           
 int getBattleTurnNumber()
           
 Caretaker getCaretaker()
           
 Legion getDefender()
           
 java.util.List<Legion> getEnemyLegions(MasterHex hex, Player player)
           
 java.util.List<Legion> getEnemyLegions(Player player)
          Return a list of all legions not belonging to player.
 Engagement getEngagement()
           
 Legion getFirstEnemyLegion(MasterHex masterHex, Player player)
          Finds the first legion in a hex not belonging to a certain player.
 Legion getFirstFriendlyLegion(MasterHex masterHex, Player player)
           
 Legion getFirstLegion(MasterHex masterHex)
           
 java.util.List<Legion> getFriendlyLegions(MasterHex hex, Player player)
           
 java.lang.String getGameOverMessage()
           
 Legion getLegionByMarkerId(java.lang.String markerId)
           
 java.util.List<Legion> getLegionsByHex(MasterHex masterHex)
           
 int getMovementRoll()
           
 int getNumEnemyLegions(MasterHex masterHex, Player player)
           
 int getNumFriendlyLegions(MasterHex masterHex, Player player)
           
protected  int getNumHumansRemaining()
          Returns the number of real players (Human or Network) which are still alive.
 int getNumLegions(MasterHex masterHex)
           
 int getNumLivingCreatures(CreatureType type)
           
 int getNumLivingPlayers()
           
 int getNumPlayers()
           
 int getNumRemoteRemaining()
           
 Phase getPhase()
           
 java.util.Collection<Player> getPlayers()
           
 java.util.Collection<java.lang.String> getPreliminaryPlayerNames()
          Get a list of preliminary player names, during game startup / clients connecting.
 int getTurnNumber()
          Returns the current turn in the game
 Variant getVariant()
           
 boolean isEngagementInProgress()
           
 boolean isEngagementOngoing()
           
 boolean isGameOver()
           
 boolean isOccupied(MasterHex masterHex)
           
 boolean isPhase(Phase phase)
           
 boolean onlyAIsRemain()
           
 void setGameOver(boolean gameOver, java.lang.String message)
           
 void setMovementRoll(int roll)
           
 void setPhase(Phase phase)
           
 void setTurnNumber(int turn)
          Set the current turn number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

variant

private final Variant variant
The variant played in this game.


players

protected final java.util.List<Player> players
The state of the different players in the game.


caretaker

private final Caretaker caretaker
The caretaker takes care of managing the available and dead creatures.


turnNumber

protected int turnNumber
The current turn number. Advance when every player has done his move


phase

protected Phase phase
The current game phase (Split, Move, Fight, Muster)


movementRoll

private int movementRoll
Last movement roll for any player.


gameOver

private boolean gameOver
Status for Game is over and message for it On client side this also implies: If the game is over, then quitting does not require confirmation.


gameOverMessage

private java.lang.String gameOverMessage

engagement

private Engagement engagement

battle

protected Battle battle

battleStrike

private final BattleStrike battleStrike
Constructor Detail

Game

public Game(Variant variant,
            java.lang.String[] playerNames)
Create a Game object.

Parameters:
variant - The variant object, not null
playerNames - Names of the players, not used yet
Method Detail

getVariant

public Variant getVariant()

addPlayer

public void addPlayer(Player p)

getPlayers

public java.util.Collection<Player> getPlayers()

getPreliminaryPlayerNames

public java.util.Collection<java.lang.String> getPreliminaryPlayerNames()
Get a list of preliminary player names, during game startup / clients connecting. Preliminary, because some of them might change their name later (e.g. the "byColor" ones).

Returns:
List of player names

getNumPlayers

public int getNumPlayers()

getNumLivingPlayers

public int getNumLivingPlayers()

onlyAIsRemain

public boolean onlyAIsRemain()
Returns:
Returns true if all still alive players are AIs

getNumHumansRemaining

protected int getNumHumansRemaining()
Returns the number of real players (Human or Network) which are still alive. TODO partly same idea as "onlyAIsRemain()"


getNumRemoteRemaining

public int getNumRemoteRemaining()

getCaretaker

public Caretaker getCaretaker()

getMovementRoll

public int getMovementRoll()

setMovementRoll

public void setMovementRoll(int roll)

isGameOver

public boolean isGameOver()

getGameOverMessage

public java.lang.String getGameOverMessage()

setGameOver

public void setGameOver(boolean gameOver,
                        java.lang.String message)

createEngagement

public void createEngagement(MasterHex hex,
                             Legion attacker,
                             Legion defender)

clearEngagementData

public void clearEngagementData()

isEngagementInProgress

public boolean isEngagementInProgress()

getEngagement

public Engagement getEngagement()

getBattle

public Battle getBattle()

getBattleActiveLegion

public Legion getBattleActiveLegion()

getBattleSite

public MasterHex getBattleSite()

getDefender

public Legion getDefender()

getAttacker

public Legion getAttacker()

findAvailableEligibleAngels

java.util.List<CreatureType> findAvailableEligibleAngels(MasterBoardTerrain terrain,
                                                         int score)
Return a list of angel types that can be acquired based on the hex in which legion is, when reaching given score threshold, and if they are still available from caretaker

Parameters:
terrain - The terrain in which this legion wants to acquire
score - A acquring threshold, e.g. in Default 100, ..., 400, 500
Returns:
list of acquirables

getAllLegions

public java.util.List<Legion> getAllLegions()
Return a list of all legions of all players.


getNumLivingCreatures

public int getNumLivingCreatures(CreatureType type)

getLegionsByHex

public java.util.List<Legion> getLegionsByHex(MasterHex masterHex)

getNumEnemyLegions

public int getNumEnemyLegions(MasterHex masterHex,
                              Player player)

getNumLegions

public int getNumLegions(MasterHex masterHex)

getFriendlyLegions

public java.util.List<Legion> getFriendlyLegions(MasterHex hex,
                                                 Player player)

getEnemyLegions

public java.util.List<Legion> getEnemyLegions(Player player)
Return a list of all legions not belonging to player.


getEnemyLegions

public java.util.List<Legion> getEnemyLegions(MasterHex hex,
                                              Player player)

getFirstFriendlyLegion

public Legion getFirstFriendlyLegion(MasterHex masterHex,
                                     Player player)

isOccupied

public boolean isOccupied(MasterHex masterHex)

getFirstLegion

public Legion getFirstLegion(MasterHex masterHex)

getNumFriendlyLegions

public int getNumFriendlyLegions(MasterHex masterHex,
                                 Player player)

getFirstEnemyLegion

public Legion getFirstEnemyLegion(MasterHex masterHex,
                                  Player player)
Finds the first legion in a hex not belonging to a certain player. Note that there is no assumption that the player has a legion in that location itself. This method is e.g. used to evaluate moves in the AI.

Parameters:
masterHex - the hex where to look for enemy regions. Not null.
player - the player whose enemies we are looking for. Not null.
Returns:
the first legion that is in the specified hex and does not belong to the given player, null if no such legion exists

findEngagements

public java.util.Set<MasterHex> findEngagements()
Return a set of all hexes with engagements. TODO if we can be sure that the activePlayer is set properly, we could just create a set of all hexes he is on and then check if someone else occupies any of the same


containsOpposingLegions

public boolean containsOpposingLegions(MasterHex hex)
Return set of hexLabels for engagements found.


findLegionsWithSummonables

public java.util.List<Legion> findLegionsWithSummonables(Legion summoner)
Return a set of all other unengaged legions of the legion's player that have summonables (not sorted in any particular order).


getLegionByMarkerId

public Legion getLegionByMarkerId(java.lang.String markerId)

setTurnNumber

public void setTurnNumber(int turn)
Set the current turn number. Used only on client side; server side increments directly.

Parameters:
turn - Set this number as current turn number

getTurnNumber

public int getTurnNumber()
Returns the current turn in the game

Returns:
returns the current turn number

isPhase

public boolean isPhase(Phase phase)

setPhase

public void setPhase(Phase phase)

getPhase

public Phase getPhase()

isEngagementOngoing

public boolean isEngagementOngoing()

getBattleTurnNumber

public int getBattleTurnNumber()

getBattleStrike

public BattleStrike getBattleStrike()