Skip to content

Creating an AI Player

Raluca D. Gaina edited this page Jun 4, 2019 · 1 revision

Creating a new AI player

All AI players must extend from players.Player.java class and implement:

  • A constructor which takes as a minimum random seed and playerID as arguments and calls the super(seed, playerID) constructor.
  • act(GameState gs) method which receives a GameState as input and must return a Types.ACTIONS action to play in the game.
  • copy() method which should return an exact copy of the AI instance.

Examples of current AI Players can be found here.

Interacting with the game

AI Players have access to several methods from the core.GameState.java class, as follows.

Core methods

  • boolean next(Types.ACTIONS[] actions) - Advances the current game state one tick forward, given a list of actions (one for each player). It returns true if the game was successfully advanced, or false otherwise (if game is at maximum ticks allowed).
  • GameState copy() - Returns a copy of the current game state.
  • boolean isTerminal() - Returns true if the game state is terminal, false otherwise.
  • int getTick() - Returns the current game tick.
  • int nActions() - Returns the number of available actions.
  • Types.GAME_MODE getGameMode() - Returns the current game mode.

Game state information

  • Types.TILETYPE[][] getBoard() - Returns the current game board, 2D array with Types.TILETYPE objects. In partial observability, objects outside the vision range will be depicted as Types.TILETYPE.Fog and removed from the game engine.
  • int[][] getBombBlastStrength()- Returns the bomb blast strength array, 2D array of ints. If a bomb exists at the location, then a number > 0 will be in the array.
  • int[][] getBombLife() - Returns the bomb life array, 2D array of ints. If a bomb exists at the location, then a number > 0 will be in the array.
  • Types.TILETYPE[] getAliveAgentIDs() - Returns the player IDs of all agents still alive in the game.

Teammates & enemies information

  • int getTeam() - Returns this player's team ID
  • Types.TILETYPE[] getTeammates() - Returns an array of length 1 containing this player's teammates. Some elements may be Types.TILETYPE.Dummy if not enough teammates defined in the game mode.
  • Types.TILETYPE[] getEnemies() - Returns an array of length 2 containing this player's teammates. Some elements may be Types.TILETYPE.Dummy if not enough teammates defined in the game mode.
  • ArrayList<Types.TILETYPE> getAliveTeammateIDs() - Helper function returning a list of IDs of alive teammates.
  • ArrayList<Types.TILETYPE> getAliveEnemyIDs() - Helper function returning a list of IDs of alive enemies.
  • ArrayList<Types.TILETYPE> trimAliveList(List<Types.TILETYPE> aliveAgents, Types.TILETYPE[] trimIDs) - Helper function returning a list of given IDs, if alive.

Avatar properties

  • int getPlayerId() - Returns the ID of this player.
  • Types.RESULT winner() - Returns the win status of this player (win, loss, tie, incomplete).
  • int getBlastStrength() - Returns the blast strength of this player.
  • int getAmmo() - Returns the ammo of this player.
  • boolean canKick() - Returns true if this player can kick, false otherwise.
  • Vector2d getPosition() - Returns the position of this player in a vector containing x, y coordinates. In the game board (or other 2D arrays), the location would be found as board[y][x].

Game state modifications

  • void addBomb(int x, int y, int blastStrength, int bombLife, int playerIdx, boolean addToBoard) - Adds a bomb at the indicated location, with given blast strength and life, placed by specified player. If addToBoard is true, the bomb will be inserted into the board as well, otherwise it will only be added into the bomb array.
  • void addFlame(int x, int y, int life) - Adds a flame at the indicated location, with given life. Flames are added into the board if necessary by the game engine.
  • void addPowerUp(int x, int y, Types.TILETYPE type, boolean visible) - Adds a power-up of given type at the specified location. If visible, the power-up will be added directly in the board, otherwise the wooden block at that location in the board will have to be destroyed first in order for this power-up to become visible. If no wooden block at location, the power-up will never be visible.
  • void removePowerUp(int x, int y, Types.TILETYPE type) - Removes the power-up at that location from the board.
  • void addObject(int x, int y, Types.TILETYPE type) - Adds a generic object into the board (wooden block, rigid, fog, passage).
  • void removeObject(int x, int y, Types.TILETYPE type, boolean onlyBoard) - Removes the object from the board. If onlyBoard is true, the object will be kept in lists (if any, valid for agents, bombs and flames).
  • void addAgent(int x, int y, int idx) - Adds an agent in the board.
  • void setAgent(int playerIdx, int x, int y, boolean canKick, int ammo, int blastStrength) - Sets properties for an agent in the board, identified by location.
  • void setBomb(int x, int y, int playerIdx, Vector2d velocity) - Sets properties for a bomb in the board, identified by location.
  • void setFlame(int x, int y, int life) - Sets properties for a flame in the board, identified by location.

Other methods

  • String toString() - Returns a string of the current game board.
  • boolean equals(Object o) - Checks if two game states are equal.