Package com.codingame.gameengine.core
Class GameManager<T extends AbstractPlayer>
java.lang.Object
com.codingame.gameengine.core.GameManager<T>
- Type Parameters:
T- Your implementation of AbstractPlayer
- Direct Known Subclasses:
MultiplayerGameManager,SoloGameManager
The
GameManager takes care of running each turn of the game and computing each visual frame of the replay. It provides many utility
methods that handle instances of your implementation of AbstractPlayer.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToGameSummary(String summary) Add a new line to the game summary for the current turn.voidaddTooltip(AbstractPlayer player, String message) Adds a tooltip for the current turn.voidaddTooltip(Tooltip tooltip) Adds a tooltip for the current turn.protected abstract booleanprotected voidprotected voidendGame()Set game end.protected voidExecutes a player for a maximum of turnMaxTime milliseconds and store the output.static StringformatErrorMessage(String message) Helper function to display a colored message.static StringformatSuccessMessage(String message) Helper function to display a colored message.intGet the timeout delay of the first turn for every player.intReturns the duration in milliseconds for the frame currently being computed.protected abstract com.codingame.gameengine.core.OutputCommandintGet current league level.intGet the maximum amount of turns.intGet the timeout delay for every player.booleanCheck if the game has been terminated by the referee.final voidputMetadata(String key, double value) Puts a new metadata that will be included in the game'sGameResult.protected abstract voidreadGameProperties(com.codingame.gameengine.core.InputCommand iCmd, Scanner s) voidregisterModule(Module module) Register a module to the gameManager.voidsetFirstTurnMaxTime(int firstTurnMaxTime) Set the timeout delay of the first turn for every player.voidsetFrameDuration(int frameDuration) Specifies the frameDuration in milliseconds.voidsetMaxTurns(int maxTurns) Set the maximum amount of turns.voidsetTurnMaxTime(int turnMaxTime) Set the timeout delay for every player.voidsetViewData(Object data) Set data for use by the viewer, for the current frame.voidsetViewData(String moduleName, Object data) Set data for use by the viewer, for the current frame, for a specific module.voidsetViewGlobalData(String moduleName, Object data) Set data for use by the viewer and not related to a specific frame.
-
Field Details
-
log
protected static org.apache.commons.logging.Log log -
players
-
out
-
-
Constructor Details
-
GameManager
public GameManager()
-
-
Method Details
-
allPlayersInactive
protected abstract boolean allPlayersInactive() -
readGameProperties
protected abstract void readGameProperties(com.codingame.gameengine.core.InputCommand iCmd, Scanner s) -
execute
Executes a player for a maximum of turnMaxTime milliseconds and store the output. Used by player.execute().- Parameters:
player- Player to execute.nbrOutputLines- The amount of expected output lines from the player.
-
dumpGameProperties
protected void dumpGameProperties() -
getGameSummaryOutputCommand
protected abstract com.codingame.gameengine.core.OutputCommand getGameSummaryOutputCommand() -
putMetadata
Puts a new metadata that will be included in the game'sGameResult.Can be used for:
- Setting the value of an optimization criteria for OPTI games, used by the CodinGame IDE
- Dumping game statistics for local analysis after a batch run of GameRunner.simulate()
- Parameters:
key- the property to sendvalue- the property's value
-
setFrameDuration
public void setFrameDuration(int frameDuration) Specifies the frameDuration in milliseconds. Default: 1000ms- Parameters:
frameDuration- The frame duration in milliseconds.- Throws:
IllegalArgumentException- if frameDuration ≤ 0
-
getFrameDuration
public int getFrameDuration()Returns the duration in milliseconds for the frame currently being computed.- Returns:
- the frame duration in milliseconds.
-
endGame
protected void endGame()Set game end. -
isGameEnd
public boolean isGameEnd()Check if the game has been terminated by the referee.- Returns:
- true if the game is over.
-
setMaxTurns
Set the maximum amount of turns. Default: 400.- Parameters:
maxTurns- the number of turns for a game.- Throws:
IllegalArgumentException- if maxTurns ≤ 0
-
getMaxTurns
public int getMaxTurns()Get the maximum amount of turns.- Returns:
- the maximum number of turns.
-
setTurnMaxTime
Set the timeout delay for every player. This value can be updated during a game and will be used by execute(). Default is 50ms.- Parameters:
turnMaxTime- Duration in milliseconds.- Throws:
IllegalArgumentException- if turnMaxTime < 50 or > 25000
-
setFirstTurnMaxTime
Set the timeout delay of the first turn for every player. Default is 1000ms.- Parameters:
firstTurnMaxTime- Duration in milliseconds.- Throws:
IllegalArgumentException- if firstTurnMaxTime < 50 or > 25000
-
getTurnMaxTime
public int getTurnMaxTime()Get the timeout delay for every player.- Returns:
- the current timeout duration in milliseconds.
-
getFirstTurnMaxTime
public int getFirstTurnMaxTime()Get the timeout delay of the first turn for every player.- Returns:
- the first turn timeout duration in milliseconds.
-
setViewData
Set data for use by the viewer, for the current frame.- Parameters:
data- any object that can be serialized in JSON using gson.
-
setViewData
Set data for use by the viewer, for the current frame, for a specific module.- Parameters:
moduleName- the name of the moduledata- any object that can be serialized in JSON using gson.
-
setViewGlobalData
Set data for use by the viewer and not related to a specific frame. This must be use in the init only.- Parameters:
moduleName- the name of the moduledata- any object that can be serialized in JSON using gson.
-
addTooltip
Adds a tooltip for the current turn.- Parameters:
tooltip- A tooltip that will be shown in the player.
-
addTooltip
Adds a tooltip for the current turn.- Parameters:
player- The player the tooltip information is about.message- Tooltip message.
-
addToGameSummary
Add a new line to the game summary for the current turn.- Parameters:
summary- summary line to add to the current summary.
-
registerModule
Register a module to the gameManager. After this, the gameManager will call the module callbacks automatically.- Parameters:
module- the module to register
-
getLeagueLevel
public int getLeagueLevel()Get current league level. The value can be set by using -Dleague.level=X where X is the league level.- Returns:
- a strictly positive integer. 1 is the lowest level and default value.
-
formatSuccessMessage
Helper function to display a colored message. Usually used at the end of the game.- Parameters:
message- The message to display.- Returns:
- The formatted string.
-
formatErrorMessage
Helper function to display a colored message. Usually used at the end of the game.- Parameters:
message- The message to display.- Returns:
- The formatted string.
-