core.game

## Class StateObservation

- java.lang.Object
- - core.game.StateObservation

-     public class StateObservation
      extends java.lang.Object

  Created with IntelliJ IDEA. User: Diego Date: 13/11/13 Time: 15:37 This is a Java port from Tom Schaul's VGDL - https://github.com/schaul/py-vgdl

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StateObservation(ForwardModel a_model)` Constructor for StateObservation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `advance(Types.ACTIONS action)` Advances the state using the action passed as the move of the agent.
    `StateObservation` | `copy()` Returns an exact copy of the state observation object.
    `java.util.ArrayList<Types.ACTIONS>` | `getAvailableActions()` Returns the actions that are available in this game for the avatar.
    `Vector2d` | `getAvatarOrientation()` Returns the orientation of the avatar.
    `Vector2d` | `getAvatarPosition()` Returns the position of the avatar.
    `java.util.HashMap<java.lang.Integer,java.lang.Integer>` | `getAvatarResources()` Returns the resources in the avatar's possession.
    `double` | `getAvatarSpeed()` Returns the speed of the avatar.
    `int` | `getBlockSize()` Indicates how many pixels form a block in the game.
    `java.util.TreeSet<Event>` | `getEventsHistory()` This method retrieves a list of events that happened so far in the game.
    `java.util.ArrayList<Observation>[]` | `getFromAvatarSpritesPositions()` Returns a list of observations of sprites created by the avatar (usually, by applying the action Types.ACTIONS.ACTION_USE).
    `java.util.ArrayList<Observation>[]` | `getFromAvatarSpritesPositions(Vector2d reference)` Returns a list of observations of sprites created by the avatar (usually, by applying the action Types.ACTIONS.ACTION_USE).
    `double` | `getGameScore()` Gets the score of the game at this observation.
    `int` | `getGameTick()` Returns the game tick of this particular observation.
    `Types.WINNER` | `getGameWinner()` Indicates if there is a game winner in the current observation.
    `java.util.ArrayList<Observation>[]` | `getImmovablePositions()` Returns a list of observations of immovable sprites in the game.
    `java.util.ArrayList<Observation>[]` | `getImmovablePositions(Vector2d reference)` Returns a list of observations of immovable sprites in the game.
    `java.util.ArrayList<Observation>[]` | `getMovablePositions()` Returns a list of observations of sprites that move, but are NOT NPCs in the game.
    `java.util.ArrayList<Observation>[]` | `getMovablePositions(Vector2d reference)` Returns a list of observations of movable (not NPCs) sprites in the game.
    `java.util.ArrayList<Observation>[]` | `getNPCPositions()` Returns a list of observations of NPC in the game.
    `java.util.ArrayList<Observation>[]` | `getNPCPositions(Vector2d reference)` Returns a list of observations of NPC in the game.
    `java.util.ArrayList<Observation>[][]` | `getObservationGrid()` Returns a grid with all observations in the level, accessible by the x,y coordinates of the grid.
    `java.util.ArrayList<Observation>[]` | `getPortalsPositions()` Returns a list of observations of portals in the game.
    `java.util.ArrayList<Observation>[]` | `getPortalsPositions(Vector2d reference)` Returns a list of observations of portals in the game.
    `java.util.ArrayList<Observation>[]` | `getResourcesPositions()` Returns a list of observations of resources in the game.
    `java.util.ArrayList<Observation>[]` | `getResourcesPositions(Vector2d reference)` Returns a list of observations of resources in the game.
    `java.awt.Dimension` | `getWorldDimension()` Returns the world dimensions, in pixels.
    `boolean` | `isGameOver()` Indicates if the game is over or if it hasn't finished yet.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StateObservation

          public StateObservation(ForwardModel a_model)

      Constructor for StateObservation. Requires a forward model
      Parameters:
        `a_model` - forward model of the game.

  - ### Method Detail

    - #### copy

          public StateObservation copy()

      Returns an exact copy of the state observation object.
      Returns:
        a copy of the state observation.

    - #### advance

          public void advance(Types.ACTIONS action)

      Advances the state using the action passed as the move of the agent. It updates all entities in the game. It modifies the object 'this' to represent the next state after the action has been executed and all entities have moved. Note: stochastic events will not be necessarily the same as in the real game.
      Parameters:
        `action` - agent action to execute in the next cycle.

    - #### getAvailableActions

          public java.util.ArrayList<Types.ACTIONS> getAvailableActions()

      Returns the actions that are available in this game for the avatar.
      Returns:
        the available actions.

    - #### getGameScore

          public double getGameScore()

      Gets the score of the game at this observation.
      Returns:
        score of the game.

    - #### getGameTick

          public int getGameTick()

      Returns the game tick of this particular observation.
      Returns:
        the game tick.

    - #### getGameWinner

          public Types.WINNER getGameWinner()

      Indicates if there is a game winner in the current observation. Possible values are Types.WINNER.PLAYER_WINS, Types.WINNER.PLAYER_LOSES and Types.WINNER.NO_WINNER.
      Returns:
        the winner of the game.

    - #### isGameOver

          public boolean isGameOver()

      Indicates if the game is over or if it hasn't finished yet.
      Returns:
        true if the game is over.

    - #### getWorldDimension

          public java.awt.Dimension getWorldDimension()

      Returns the world dimensions, in pixels.
      Returns:
        the world dimensions, in pixels.

    - #### getBlockSize

          public int getBlockSize()

      Indicates how many pixels form a block in the game.
      Returns:
        how many pixels form a block in the game.

    - #### getAvatarPosition

          public Vector2d getAvatarPosition()

      Returns the position of the avatar. If the game is finished, we cannot guarantee that this position reflects the real position of the avatar (the avatar itself could be destroyed). If game finished, this returns Types.NIL.
      Returns:
        position of the avatar, or Types.NIL if game is over.

    - #### getAvatarSpeed

          public double getAvatarSpeed()

      Returns the speed of the avatar. If the game is finished, we cannot guarantee that this speed reflects the real speed of the avatar (the avatar itself could be destroyed). If game finished, this returns 0.
      Returns:
        orientation of the avatar, or 0 if game is over.

    - #### getAvatarOrientation

          public Vector2d getAvatarOrientation()

      Returns the orientation of the avatar. If the game is finished, we cannot guarantee that this orientation reflects the real orientation of the avatar (the avatar itself could be destroyed). If game finished, this returns Types.NIL.
      Returns:
        orientation of the avatar, or Types.NIL if game is over.

    - #### getAvatarResources

          public java.util.HashMap<java.lang.Integer,java.lang.Integer> getAvatarResources()

      Returns the resources in the avatar's possession. As there can be resources of different nature, each entry is a key-value pair where the key is the resource ID, and the value is the amount of that resource type owned. It should be assumed that there might be other resources available in the game, but the avatar could have none of them. If the avatar has no resources, an empty HashMap is returned.
      Returns:
        resources owned by the avatar.

    - #### getObservationGrid

          public java.util.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.
      Returns:
        the grid of observations

    - #### getEventsHistory

          public java.util.TreeSet<Event> getEventsHistory()

      This method retrieves a list of events that happened so far in the game. In this context, events are collisions of the avatar with other sprites in the game. Additionally, the list also contains information about collisions of a sprite created by the avatar (usually by using the action Types.ACTIONS.ACTION_USE) with other sprites. The list is ordered asc. by game step.
      Returns:
        list of events triggered by the avatar or sprites it created.

    - #### getNPCPositions

          public java.util.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, unique id and sprite id of that particular sprite.
      Returns:
        Observations of NPCs in the game.

    - #### getNPCPositions

          public java.util.ArrayList<Observation>[] getNPCPositions(Vector2d reference)

      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, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of NPCs in the game.

    - #### getImmovablePositions

          public java.util.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, unique id and sprite id of that particular sprite.
      Returns:
        Observations of immovable sprites in the game.

    - #### getImmovablePositions

          public java.util.ArrayList<Observation>[] getImmovablePositions(Vector2d reference)

      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, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of immovable sprites in the game.

    - #### getMovablePositions

          public java.util.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, unique id and sprite id of that particular sprite.
      Returns:
        Observations of movable, not NPCs, sprites in the game.

    - #### getMovablePositions

          public java.util.ArrayList<Observation>[] getMovablePositions(Vector2d reference)

      Returns a list of observations of movable (not NPCs) sprites in the game. As there can be movable (not NPCs) sprites of different type, each entry in the array corresponds to a sprite type. Every ArrayList contains a list of objects of type Observation, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of movable (not NPCs) sprites in the game.

    - #### getResourcesPositions

          public java.util.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, unique id and sprite id of that particular sprite.
      Returns:
        Observations of resources in the game.

    - #### getResourcesPositions

          public java.util.ArrayList<Observation>[] getResourcesPositions(Vector2d reference)

      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, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of resources in the game.

    - #### getPortalsPositions

          public java.util.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, unique id and sprite id of that particular sprite.
      Returns:
        Observations of portals in the game.

    - #### getPortalsPositions

          public java.util.ArrayList<Observation>[] getPortalsPositions(Vector2d reference)

      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, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of portals in the game.

    - #### getFromAvatarSpritesPositions

          public java.util.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. Each Observation holds the position, unique id and sprite id of that particular sprite.
      Returns:
        Observations of sprites the avatar created.

    - #### getFromAvatarSpritesPositions

          public java.util.ArrayList<Observation>[] getFromAvatarSpritesPositions(Vector2d reference)

      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, ordered asc. by distance to the reference passed. Each Observation holds the position, sprite type id and sprite id of that particular sprite.
      Parameters:
        `reference` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        Observations of sprites the avatar created.