Skip to content

Information about other sprites in the game

Raluca D. Gaina edited this page Feb 12, 2018 · 1 revision

The rest of the functions of the StateObservation class can be used to retrieve information of the current state of the game. This class provides information about the game (score, winner, game tick, available actions), the avatar (position, resources, speed orientation) and past events. The other information the StateObservation class provides revolves around Observation objects. An Observation is an object that represents a sprite on the screen, and it contains information about its position, ID, unique type of sprite and category (if it is an NPC, static, resource, etc. object). These observations can be accessed in two different ways:

  • Observation grid: The observations can be accessed via (x,y) coordinates, retrieving a list of observations present in a given position. Note that the same observation can occupy more than one grid cell. See the "getObservationGrid()" method below.
  • Observation lists: Observations can be also retrieved via their category (see the "getXXXPositions()" methods below). This allows to obtain all observations of a given category (i.e. NPCs), and optionally they can be returned sorted by distance to a arbitrary position passed by parameter.

The Observation objects are persisitent. This is, the same Java object will represent the same Observation both in the grid and in the list, and also in different time steps. Here are the most important methods of StateObservation:

State Observation functions Decription
ArrayList<Observation>[][] getObservationGrid() Returns a grid with all observations in the level, accessible by the x,y coordinates of the grid. Each grid cell has a width and height of getBlockSize() pixels. Each cell contains a list with all observations in that position. Note that the same observation may occupy more than one grid cell.
ArrayList<Observation>[] getNPCPositions() Returns a list of observations of NPC in the game. As there can be NPCs of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation. Each Observation holds the position, sprite type id and sprite id of that particular sprite. If a vector is passed as parameter, the observations are returned in ascending order according to the distance to that point.
ArrayList<Observation>[] getNPCPositions(Vector2d)
ArrayList<Observation>[] getImmovablePositions() Returns a list of observations of immovable sprites in the game. As there can be immovable sprites of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation. Each Observation holds the position, sprite type id and sprite id of that particular sprite. If a vector is passed as parameter, the observations are returned in ascending order according to the distance to that point.
ArrayList<Observation>[] getImmovablePositions(Vector2d)
ArrayList<Observation>[] getMovablePositions() Returns a list of observations of sprites that move, but are NOT NPCs in the game. As there can be movable sprites of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation. Each Observation holds the position, sprite type id and sprite id of that particular sprite. If a vector is passed as parameter, the observations are returned in ascending order according to the distance to that point.
ArrayList<Observation>[] getMovablePositions(Vector2d)
ArrayList<Observation>[] getResourcesPositions() Returns a list of observations of resources in the game. As there can be resources of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation. Each Observation holds the position, sprite type id and sprite id of that particular sprite. If a vector is passed as parameter, the observations are returned in ascending order according to the distance to that point.
ArrayList<Observation>[] getResourcesPositions(Vector2d)
ArrayList<Observation>[] getPortalsPositions() Returns a list of observations of portals in the game. As there can be portals of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation. Each Observation holds the position, sprite type id and sprite id of that particular sprite. If a vector is passed as parameter, the observations are returned in ascending order according to the distance to that point.
ArrayList<Observation>[] getPortalsPositions(Vector2d)
ArrayList<Observation>[] getFromAvatarSpritesPositions() Returns a list of observations of sprites created by the avatar (usually, by applying the action Types.ACTIONS.ACTION_USE). As there can be sprites of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation, and if a vector is passed as a parameter, the list is ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
ArrayList<Observation>[] getFromAvatarSpritesPositions(Vector2d)

Table of Contents:

Clone this wiki locally