Class MultiplayerGameRunner

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

public class MultiplayerGameRunner 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 "multi"
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAgent(Class<?> playerClass)
    Adds an AI to the next game to run.
    void
    addAgent(Class<?> playerClass, String nickname)
    Adds an AI to the next game to run, with the specified nickname.
    void
    addAgent(Class<?> playerClass, String nickname, String avatarUrl)
    Adds an AI to the next game to run.
    void
    addAgent(String commandLine)
    Adds an AI to the next game to run.
    void
    addAgent(String[] commandArray)
    Adds an AI to the next game to run.
    void
    addAgent(String[] commandArray, String nickname)
    Adds an AI to the next game to run.
    void
    addAgent(String[] commandArray, String nickname, String avatarUrl)
    Adds an AI to the next game to run.
    void
    addAgent(String commandLine, String nickname)
    Adds an AI to the next game to run, with the specified nickname.
    void
    addAgent(String commandLine, String nickname, String avatarUrl)
    Adds an AI to the next game to run.
    protected void
    buildInitCommand(com.codingame.gameengine.runner.Command initCommand)
     
    void
    setGameParameters(Properties gameParameters)
    The game parameters are used to pass additional information to the Game Manager.
    void
    setLeagueLevel(int leagueLevel)
    Sets the league level to run.
    void
    setSeed(Long seed)
    The seed is used to generated parameters such as width and height.
    If a seed is present in the given input, the input value should override the generated values.
    The seed will be sent to the GameManager.
    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

    • MultiplayerGameRunner

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

    • setLeagueLevel

      public void setLeagueLevel(int leagueLevel)
      Sets the league level to run. The first league is 1.

      The value can also be set by setting the environment variable league.level.

      The value is program-wide, and will not be reset for subsequent instances of MultiplayerGameRunner.
      Parameters:
      leagueLevel - the league level. 1 is the lowest level and default value.
    • setSeed

      public void setSeed(Long seed)

      The seed is used to generated parameters such as width and height.
      If a seed is present in the given input, the input value should override the generated values.
      The seed will be sent to the GameManager.

      Typically, the seed is used to generated other parameters such as width and height, then those parameters are placed back in the Properties.
      If those parameters are present in the given input, the input values should override the generated values.

      Parameters:
      seed - this game's seed returned by the GameManager during execution
    • setGameParameters

      public void setGameParameters(Properties gameParameters)

      The game parameters are used to pass additional information to the Game Manager.

      Parameters:
      gameParameters - the parameters to send
    • addAgent

      public void addAgent(Class<?> playerClass)
      Adds an AI to the next game to run. You must keep any standard output for the game inside the given class.
      Parameters:
      playerClass - the Java class of an AI for your game.
    • addAgent

      public void addAgent(String commandLine)
      Adds 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.
    • addAgent

      public void addAgent(Class<?> playerClass, String nickname, String avatarUrl)
      Adds 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
    • addAgent

      public void addAgent(String commandLine, String nickname, String avatarUrl)
      Adds 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
    • addAgent

      public void addAgent(Class<?> playerClass, String nickname)
      Adds an AI to the next game to run, with the specified nickname.
      Parameters:
      playerClass - the Java class of an AI for your game.
      nickname - the player's nickname
    • addAgent

      public void addAgent(String commandLine, String nickname)
      Adds an AI to the next game to run, with the specified nickname.

      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
    • buildInitCommand

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

      public void addAgent(String[] commandArray, String nickname, String avatarUrl)
      Adds an AI to the next game to run.

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

      Example: new String[]{"bash", "-c", "echo command1 && echo command2"}
      Parameters:
      commandArray - the system command array to run the AI.
      nickname - the player's nickname
      avatarUrl - the url of the player's avatar
    • addAgent

      public void addAgent(String[] commandArray, String nickname)
      Adds an AI to the next game to run.

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

      Example: new String[]{"bash", "-c", "echo command1 && echo command2"}
      Parameters:
      commandArray - the system command array to run the AI.
      nickname - the player's nickname
    • addAgent

      public void addAgent(String[] commandArray)
      Adds an AI to the next game to run.

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

      Example: new String[]{"bash", "-c", "echo command1 && echo command2"}
      Parameters:
      commandArray - the system command array to run the AI.
    • 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