Class CommandLinePlayerAgent

java.lang.Object
com.codingame.gameengine.runner.CommandLinePlayerAgent

public class CommandLinePlayerAgent extends Object
This class is used in with the GameRunner to add an AI as a player.
  • Field Details

    • UTF8

      public static final Charset UTF8
    • AGENT_MAX_BUFFER_SIZE

      public static final int AGENT_MAX_BUFFER_SIZE
      See Also:
    • THRESHOLD_LIMIT_STDERR_SIZE

      public static final int THRESHOLD_LIMIT_STDERR_SIZE
      See Also:
  • Constructor Details

    • CommandLinePlayerAgent

      public CommandLinePlayerAgent(String commandLine)
      Creates an Agent for your game, will run the given commandLine at game start
      Parameters:
      commandLine - the command line to run
    • CommandLinePlayerAgent

      public CommandLinePlayerAgent(String[] commandArray)
      Creates an Agent for your game, will run the given commandLine at game start
      Parameters:
      commandArray - the command array to run
  • Method Details

    • getInputStream

      protected OutputStream getInputStream()
    • getOutputStream

      protected InputStream getOutputStream()
    • getErrorStream

      protected InputStream getErrorStream()
    • initialize

      public void initialize(Properties conf)
      Initialize an agent given global properties. A call to this function is needed before-all
      Parameters:
      conf - Global configuration
    • getOutput

      public String getOutput(int nbLine, long timeout)
      Get the output of an agent
      Parameters:
      nbLine - Number of lines wanted
      timeout - Stop reading after timeout milliseconds
      Returns:
      the agent output
    • runInputOutput

      protected void runInputOutput() throws Exception
      Launch the agent. After the call, agent is ready to process input / output
      Throws:
      Exception - if an error occurs
    • destroy

      public void destroy()
    • execute

      public void execute()
      Compile and run an agent. After this, agent is ready for input / output
    • sendInput

      public void sendInput(String input)
      Write 'input' to standard input of agent
      Parameters:
      input - an input to write
    • readError

      public String readError()
      Read all errors from standard error stream
      Returns:
      all errors
    • getAgentId

      public int getAgentId()
    • setAgentId

      public void setAgentId(int agentId)
    • setFailed

      public void setFailed(boolean failed)
    • isFailed

      public boolean isFailed()
    • getNickname

      public String getNickname()
    • setNickname

      public void setNickname(String nickname)
    • getAvatar

      public String getAvatar()
    • setAvatar

      public void setAvatar(String avatar)
    • getOutput

      public String getOutput(int nbLine, long timeout, boolean extraBufferSpace)