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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An Exception thrown by getOutputs() when the player's AI did not respond in time after an execute().
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Executes the player for a maximum of turnMaxTime milliseconds and store the output.
    final String
    Returns a string that will be converted into the real avatar by the viewer, if it exists.
    abstract int
    Returns the number of lines that the player must return.
    final String
    Returns a string that will be converted into the real nickname by the viewer.
    final List<String>
    Gets the output obtained after an execution.
    final void
    Adds a new line to the input to send to the player on execute.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.
    • 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