Creating Multi Player Controllers

rdgain edited this page May 12, 2016 · 5 revisions

Table of Contents:

Clone this wiki locally

You can create a controller for the Two Player Track of the GVG-AI competition just by creating a Java class that inherits from core.player.AbstractMultiPlayer.java. This class must be named Agent.java and its package must be the same as the username you used to register to this website (this is in order to allow the server to run your controller when you submit). This class must implement two public methods:

  • public Agent(StateObservationMulti so, ElapsedCpuTimer elapsedTimer, int playerID): the constructor of the class.
  • public Types.ACTIONS act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer): the function called every game cycle to retrieve an action from the controller.

Both methods receive two parameters:

  • StateObservationMulti so: The StateObservationMulti (sub-classing StateObservation) is the window the agent has to the world. See Forward Model for detailed information.
  • ElapsedCpuTimer elapsedTimer: The ElapsedCpuTimer is a class that allows querying for the remaining CPU time the agent has to return an action. You can query for the number of milliseconds passed since the method was called (elapsedMillis()) or the remaining time until the timer runs out (remainingTimeMillis()). Exiting these functions after the timer has finished (when remainingTimeMillis() ≤ 0) would make this controller to be disqualified in the game being played.

In addition, the constructor receives the player ID (which should be caught here, as this information will not be available later during the game).

Finally, the method act returns an action of the enum type Types.ACTIONS. The typical values for this type are: ACTION_NIL, ACTION_UP, ACTION_LEFT, ACTION_DOWN, ACTION_RIGHT and ACTION_USE. The first element indicates no action, the next four indicate movement actions, and the last one is used to execute an action (depending on the game, this could mean different things).

Be aware that not all games will allow the agent to execute all actions of the type Types.ACTIONS. It is the agent's responsibility to return an action that is allowed for the game being played at the moment. The list of available actions for the given game can be obtained calling the StateObservationMulti method getAvailableActions(int playerID), that returns an object of type ArrayList<Types.ACTIONS> for the player corresponding to the ID passed to the method.

Important: avatars in the game may have different sets of actions available!

The following pages show different sample controllers that can help you get started with your controller: