core.game

## Class ForwardModel

- java.lang.Object
- - core.game.Game
  - - core.game.ForwardModel

-     public class ForwardModel
      extends Game

  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

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class core.game.Game

      `Game.Bucket`

  - ### Field Summary

    - ### Fields inherited from class core.game.Game

      `avatar, block_size, bucketList, charMapping, classConst, collisionEffects, definedEffects, definedEOSEffects, eosEffects, frame_rate, fwdModel, gameTick, historicEvents, is_stochastic, isEnded, iSubTypes, ki, kill_list, MAX_SPRITES, nextSpriteID, num_sprites, resources_colors, resources_limits, score, screenSize, singletons, size, spriteGroups, spriteOrder, terminations, winner`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ForwardModel(Game a_gameState)` Constructor for StateObservation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `advance(Types.ACTIONS action)` Advances the forward model using the acction supplied.
    `void` | `buildLevel(java.lang.String gamelvl)` Builds a level, receiving a file name.
    `ForwardModel` | `copy()` Creates a copy of this forward model.
    `java.util.ArrayList<Types.ACTIONS>` | `getAvatarActions()` 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()` Returns the list of historic events happened in this game so far.
    `java.util.ArrayList<Observation>[]` | `getFromAvatarSpPositions(Vector2d refPosition)` Returns a list of observations of objects created by the avatar's actions.
    `double` | `getGameScore()` Gets the game score of this state.
    `int` | `getGameTick()` Gets the current game tick of this particular state.
    `Types.WINNER` | `getGameWinner()` Indicates if there is a game winner in the current observation.
    `java.util.ArrayList<Observation>[]` | `getImmovablePositions(Vector2d refPosition)` Observations of static objects in the game.
    `java.util.ArrayList<Observation>[]` | `getMovablePositions(Vector2d refPosition)` Returns a list with observations of sprites that move, but are NOT NPCs.
    `java.util.ArrayList<Observation>[]` | `getNPCPositions(Vector2d refPosition)` Returns a list of observations of NPC in the game.
    `java.util.ArrayList<Observation>[][]` | `getObservationGrid()` Returns a grid with all observations in the level.
    `java.util.ArrayList<Observation>[]` | `getPortalsPositions(Vector2d refPosition)`
    `java.util.Random` | `getRandomGenerator()` Returns the sampleRandom generator of this forward model.
    `java.util.ArrayList<Observation>[]` | `getResourcesPositions(Vector2d refPosition)`
    `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.
    `void` | `printObservationGrid()` Prints the observation grid.
    `void` | `removeSpriteObservation(VGDLSprite sprite)` Removes an sprite observation.
    `protected void` | `tick(Types.ACTIONS action)` Performs one tick for the game: calling update(this) in all sprites.
    `void` | `update(Game a_gameState)` Dumps the game state into 'this' object.

    - ### Methods inherited from class core.game.Game

      `_updateCollisionDict, addSprite, addSprite, addSprite, checkTimeOut, clearAll, disqualify, eventHandling, getAvatar, getCharMapping, getCollisionEffects, getDefinedEffects, getDefinedEosEffects, getEosEffects, getNumSprites, getObservation, getResourceColor, getResourceLimit, getScreenSize, getSpriteGroup, getSpriteOrder, getSprites, getTerminations, getWinner, initForwardModel, initSprites, killSprite, parseParameters, playGame, reset, reverseDirection, runGame, setAvatar, setStochastic, terminationHandling, tick`

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

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

- - ### Constructor Detail

    - #### ForwardModel

          public ForwardModel(Game a_gameState)

      Constructor for StateObservation. Initializes everything
      Parameters:
        `a_gameState` -

  - ### Method Detail

    - #### update

          public final void update(Game a_gameState)

      Dumps the game state into 'this' object. Effectively, creates a state observation from a game state (of class Game).
      Parameters:
        `a_gameState` - game to take the state from.

    - #### removeSpriteObservation

          public final void removeSpriteObservation(VGDLSprite sprite)

      Removes an sprite observation.
      Parameters:
        `sprite` - sprite to remove.

    - #### printObservationGrid

          public void printObservationGrid()

      Prints the observation grid. For debug only.

    - #### getRandomGenerator

          public final java.util.Random getRandomGenerator()

      Returns the sampleRandom generator of this forward model. It is not the same as the sampleRandom number generator of the main game copy.
      Overrides:
        `getRandomGenerator` in class `Game`
      Returns:
        the sampleRandom generator of this forward model.

    - #### tick

          protected void tick(Types.ACTIONS action)

      Performs one tick for the game: calling update(this) in all sprites. It follows the opposite order of the drawing order (spriteOrder[]). It uses the action received as the action of the avatar.
      Parameters:
        `action` - Action to be performed by the avatar for this game tick.

    - #### advance

          public final void advance(Types.ACTIONS action)

      Advances the forward model using the acction supplied.
      Parameters:
        `action` -

    - #### copy

          public final ForwardModel copy()

      Creates a copy of this forward model.
      Returns:
        the copy of this forward model.

    - #### getGameScore

          public double getGameScore()

      Gets the game score of this state.
      Returns:
        the game score.

    - #### getGameTick

          public int getGameTick()

      Gets the current game tick of this particular state.
      Overrides:
        `getGameTick` in class `Game`
      Returns:
        the game tick of the current game state.

    - #### 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.
      Overrides:
        `isGameOver` in class `Game`
      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.

    - #### getAvatarActions

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

      Returns the actions that are available in this game for the avatar.
      Returns:
        the available actions. An empty list if the game is ended.

    - #### 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.
      Returns:
        the grid of observations

    - #### getEventsHistory

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

      Returns the list of historic events happened in this game so far.
      Returns:
        list of historic events happened in this game so far.

    - #### getNPCPositions

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

      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 avatar. Each Observation holds the position, unique id and sprite id of that particular sprite.
      Parameters:
        `refPosition` - 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(Vector2d refPosition)

      Observations of static objects in the game.
      Parameters:
        `refPosition` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        a list with the observations of static objects in the game..

    - #### getMovablePositions

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

      Returns a list with observations of sprites that move, but are NOT NPCs.
      Parameters:
        `refPosition` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        a list with observations of sprites that move, but are NOT NPCs.

    - #### getResourcesPositions

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

    - #### getPortalsPositions

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

    - #### getFromAvatarSpPositions

          public java.util.ArrayList<Observation>[] getFromAvatarSpPositions(Vector2d refPosition)

      Returns a list of observations of objects created by the avatar's actions.
      Parameters:
        `refPosition` - Reference position to use when sorting this array, by ascending distance to this point.
      Returns:
        a list with observations of sprites.

    - #### buildLevel

          public void buildLevel(java.lang.String gamelvl)

      Description copied from class: `Game`
      Builds a level, receiving a file name.
      Specified by:
        `buildLevel` in class `Game`
      Parameters:
        `gamelvl` - file name containing the level.