Class SoloGameRunner

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

public class SoloGameRunner extends Object
The class to use to run local games and display the replay in a webpage on a temporary local server.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static org.apache.commons.logging.Log
     
    protected final List<com.codingame.gameengine.runner.Agent>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Once this runner is instantiated, the system property game.mode is set to "solo"
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    buildInitCommand(com.codingame.gameengine.runner.Command initCommand)
     
    void
    setAgent(Class<?> playerClass)
    Sets an AI to the next game to run.
    void
    setAgent(Class<?> playerClass, String nickname, String avatarUrl)
    Sets an AI to the next game to run.
    void
    setAgent(String commandLine)
    Sets an AI to the next game to run.
    void
    setAgent(String commandLine, String nickname, String avatarUrl)
    Sets an AI to the next game to run.
    void
    setTestCase(File testCaseFile)
    Sets a test case file which testIn value will be sent to the Game Manager as a test case input.
    void
    setTestCase(String testCaseFileName)
    Sets a test case file by file path which testIn value will be sent to the Game Manager as a test case input.
    void
    setTestCaseInput(String testCaseInput)
    Sets a String as a test case input that will be sent to the Game Manager.
    void
    setTestCaseInput(List<String> testCaseInput)
    Sets a list of String as a test case input that will be sent to the Game Manager.
    Runs the game without a server and returns computed game results
    void
    Runs the game and attempts to start a server on the port 8888.
    void
    start(int port)
    Runs the game and attempts to start a server on the given port.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      protected static org.apache.commons.logging.Log log
    • players

      protected final List<com.codingame.gameengine.runner.Agent> players
  • Constructor Details

    • SoloGameRunner

      public SoloGameRunner()
      Once this runner is instantiated, the system property game.mode is set to "solo"
  • Method Details

    • setTestCase

      public void setTestCase(String testCaseFileName)
      Sets a test case file by file path which testIn value will be sent to the Game Manager as a test case input.

      The file path must be relative considering the root directory is config.

      Parameters:
      testCaseFileName - the test case file path (JSON or YAML)
    • setTestCase

      public void setTestCase(File testCaseFile)
      Sets a test case file which testIn value will be sent to the Game Manager as a test case input.
      Parameters:
      testCaseFile - the test case file (JSON or YAML)
    • setTestCaseInput

      public void setTestCaseInput(List<String> testCaseInput)
      Sets a list of String as a test case input that will be sent to the Game Manager.
      Parameters:
      testCaseInput - the list of String of the test case input
    • setTestCaseInput

      public void setTestCaseInput(String testCaseInput)
      Sets a String as a test case input that will be sent to the Game Manager.

      The input will be split in several lines by \n.

      Parameters:
      testCaseInput - the String of the test case input
    • setAgent

      public void setAgent(Class<?> playerClass)
      Sets an AI to the next game to run.
      Parameters:
      playerClass - the Java class of an AI for your game.
    • setAgent

      public void setAgent(String commandLine)
      Sets an AI to the next game to run.

      The given command will be executed with Runtime.getRuntime().exec().

      Parameters:
      commandLine - the system command line to run the AI.
    • setAgent

      public void setAgent(Class<?> playerClass, String nickname, String avatarUrl)
      Sets an AI to the next game to run.
      Parameters:
      playerClass - the Java class of an AI for your game.
      nickname - the player's nickname
      avatarUrl - the url of the player's avatar
    • setAgent

      public void setAgent(String commandLine, String nickname, String avatarUrl)
      Sets an AI to the next game to run.

      The given command will be executed with Runtime.getRuntime().exec().

      Parameters:
      commandLine - the system command line to run the AI.
      nickname - the player's nickname
      avatarUrl - the url of the player's avatar
    • buildInitCommand

      protected void buildInitCommand(com.codingame.gameengine.runner.Command initCommand)
    • start

      public void start()
      Runs the game and attempts to start a server on the port 8888.

      Open a webpage to the server to watch the game's replay.

    • start

      public void start(int port)
      Runs the game and attempts to start a server on the given port.

      Open a webpage to the server to watch the game's replay.

      Parameters:
      port - the port on which to attempt to start the a server for the game's replay.
    • simulate

      public GameResult simulate()
      Runs the game without a server and returns computed game results
      Returns:
      game result of the game