Class AbstractPlayer

java.lang.Object
com.codingame.gameengine.core.AbstractPlayer
Direct Known Subclasses:
AbstractMultiplayerPlayer, AbstractSoloPlayer

public abstract class AbstractPlayer extends Object
The representation of the/a player's AI during the game's execution.
  • Field Details

    • index

      protected int index
  • Constructor Details

    • AbstractPlayer

      public AbstractPlayer()
  • Method Details

    • getNicknameToken

      public final String getNicknameToken()
      Returns a string that will be converted into the real nickname by the viewer.
      Returns:
      the player's nickname token.
    • getAvatarToken

      public final String 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

      public final void sendInputLine(String line)
      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

      public final List<String> getOutputs() throws AbstractPlayer.TimeoutException
      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)