Package com.codingame.gameengine.core
Class AbstractPlayer
java.lang.Object
com.codingame.gameengine.core.AbstractPlayer
- Direct Known Subclasses:
AbstractMultiplayerPlayer,AbstractSoloPlayer
The representation of the/a player's AI during the game's execution.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn Exception thrown bygetOutputs()when the player's AI did not respond in time after anexecute(). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidexecute()Executes the player for a maximum of turnMaxTime milliseconds and store the output.final StringReturns a string that will be converted into the real avatar by the viewer, if it exists.abstract intReturns the number of lines that the player must return.longGet the execution time of the last successful execution Will still return the previous value in case of a timeoutfinal StringReturns a string that will be converted into the real nickname by the viewer.Gets the output obtained after an execution.intGet the remaining timebankintGet how often the player has already exceeded the time limit in this gamebooleanGet whether the player exceeded the time limit in the last turnfinal voidsendInputLine(String line) Adds a new line to the input to send to the player on execute.final voidsetLastExecutionTimeMs(long ms)
-
Field Details
-
index
protected int index
-
-
Constructor Details
-
AbstractPlayer
public AbstractPlayer()
-
-
Method Details
-
getNicknameToken
Returns a string that will be converted into the real nickname by the viewer.- Returns:
- the player's nickname token.
-
getAvatarToken
Returns a string that will be converted into the real avatar by the viewer, if it exists.- Returns:
- the player's avatar token.
-
getRemainingTimebank
public int getRemainingTimebank()Get the remaining timebank- Returns:
- the remaining timebank in milliseconds
-
getLastExectionTimeMs
public long getLastExectionTimeMs()Get the execution time of the last successful execution Will still return the previous value in case of a timeout- Returns:
- The execution time of the last execution in milliseconds
-
getTimelimitsExceeded
public int getTimelimitsExceeded()Get how often the player has already exceeded the time limit in this game- Returns:
- how often the player has already exceeded the time limit in this game
-
hasTimelimitExceededLastTurn
public boolean hasTimelimitExceededLastTurn()Get whether the player exceeded the time limit in the last turn- Returns:
- true, if the player exceeded the time limit in the last turn
-
sendInputLine
Adds a new line to the input to send to the player on execute.- Parameters:
line- The input to send.
-
execute
public final void execute()Executes the player for a maximum of turnMaxTime milliseconds and store the output. -
getOutputs
Gets the output obtained after an execution.- Returns:
- a list of output lines
- Throws:
AbstractPlayer.TimeoutException- if the player's AI crashes or stops responding
-
getExpectedOutputLines
public abstract int getExpectedOutputLines()Returns the number of lines that the player must return. If the player do not write that amount of lines before the timeout delay, no outputs at all will be available for this player. The game engine will not read more than the expected output lines. Extra lines will be available for next turn.- Returns:
- the expected amount of lines the player must output
-
setLastExecutionTimeMs
public final void setLastExecutionTimeMs(long ms)
-