public abstract class Game
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
Game.Bucket
Class for helping collision detection.
|
Modifier and Type | Field and Description |
---|---|
protected Types.ACTIONS[] |
avatarLastAction
Avatars last actions.
|
protected MovingAvatar[] |
avatars
Quick reference to the gamer
|
protected int |
block_size
Size of the block in pixels.
|
protected Game.Bucket[] |
bucketList
Arraylist to hold collisions between objects in every frame
|
protected java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> |
charMapping
Mapping between characters in the level and the entities they represent.
|
protected Content[] |
classConst
Content objects for the different sprite types..
|
protected java.util.ArrayList<Effect>[][] |
collisionEffects
Relationships for collisions: double array of (list of) effects.
|
int[] |
counter |
protected java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>> |
definedEffects
Pairs of all defined effects in the game.
|
protected java.util.ArrayList<java.lang.Integer> |
definedEOSEffects
List of types that can trigger an EOS effect.
|
protected java.util.ArrayList<Effect>[] |
eosEffects
List of EOS effects
|
protected ForwardModel |
fwdModel
State observation for this game.
|
protected int |
gameTick
Game tick
|
protected java.util.TreeSet<Event> |
historicEvents
Historic of events related to the avatar happened during the game.
|
boolean[] |
humanPlayer
indicates if player i is human or not
|
protected boolean |
is_stochastic
Indicates if the game is stochastic.
|
protected boolean |
isEnded
Indicates if the game is ended.
|
protected java.util.ArrayList<java.lang.Integer>[] |
iSubTypes
For each entry, int identifier of sprite type, a list with all the itypes
this sprite belongs to.
|
java.lang.String |
key_handler
Key Handler for human play.
|
static KeyHandler |
ki |
java.util.ArrayList<VGDLSprite> |
kill_list
List of sprites killed in the game.
|
protected static int |
MAX_SPRITES
Maximum number of sprites in a game.
|
protected int |
nextSpriteID
Next ID to generate for sprites;
|
int |
no_counters |
int |
no_players |
protected int |
num_sprites
Number of sprites this game has.
|
java.util.HashMap<java.lang.String,ParameterContent> |
parameters
Parameters for a Game Space.
|
protected PathFinder |
pathf
Pathfinder.
|
protected java.awt.Color[] |
resources_colors
Color for each resource
|
protected int[] |
resources_limits
Limit number of each resource type
|
protected java.awt.Dimension |
screenSize
Screen size.
|
protected java.util.ArrayList<Pair<java.lang.Integer,java.lang.Long>>[] |
shieldedEffects
For each entry, int identifier of sprite type, a list with all the itypes
this sprite belongs to.
|
protected boolean[] |
singletons
Singletons of the game.
|
protected java.awt.Dimension |
size
Dimensions of the game.
|
protected SpriteGroup[] |
spriteGroups
Groups of sprites in the level.
|
protected int[] |
spriteOrder
z-level of sprite types (in case of overlap)
|
protected VGDLSprite[] |
templateSprites
List of template sprites, one for each object in the above "classConst"
array.
|
protected java.util.ArrayList<Termination> |
terminations
Termination set conditions to finish the game.
|
protected java.util.TreeSet<TimeEffect> |
timeEffects
List of TIME effects
|
static WindowInput |
wi
Handling when the window is closed
|
Constructor and Description |
---|
Game()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
_updateCollisionDict(VGDLSprite sprite) |
void |
abort()
Aborts a game.
|
void |
addShield(int type1,
int type2,
long functHash)
Adds a new Shield effect to the scene.
|
VGDLSprite |
addSprite(int itype,
Vector2d position)
Adds a sprite given a content and position.
|
VGDLSprite |
addSprite(int itype,
Vector2d position,
boolean force)
Adds a sprite given a content and position.
|
VGDLSprite |
addSprite(SpriteContent content,
Vector2d position,
int itype,
boolean force)
Adds a sprite given a content and position.
|
protected void |
addSprite(VGDLSprite sprite,
int itype)
Adds a new sprite to the pool of sprites of the game.
|
void |
addTimeEffect(TimeEffect ef)
Adds a time effect to the game.
|
void |
buildLevel(java.lang.String gamelvl,
int randomSeed)
Builds a level, receiving a file name.
|
abstract void |
buildStringLevel(java.lang.String[] levelString,
int randomSeed) |
void |
changeSpriteOrder(java.util.ArrayList<java.lang.Integer> spOrder)
Modify the sprite order for the renderer of the GVG-AI
|
protected void |
checkTimeOut()
Checks if the game must finish because of number of cycles played.
|
protected void |
clearAll(ForwardModel fm)
Deletes all the sprites killed in the previous step.
|
void |
clearInteractionTerminationData()
clear all the interactions and termination in the current game
|
void |
createAvatars(int humanID)
Method to create the array of avatars from the sprites.
|
void |
disqualify()
Disqualifies the player in the game, and also sets the isEnded flag to
true.
|
void |
disqualify(int id)
Overloaded method for multiplayer games.
|
protected void |
eventHandling()
Handles collisions and triggers events.
|
MovingAvatar |
getAvatar()
Returns the avatar of the game in single player games.
|
MovingAvatar |
getAvatar(int playerID)
Overloaded method, returns the avatar of the player specified (for multi
player games).
|
MovingAvatar[] |
getAvatars()
Returns an array of all avatars in the game.
|
int |
getBlockSize()
Indicates how many pixels form a block in the game.
|
java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> |
getCharMapping()
Returns the char mapping of this array, that relates characters in the
level with sprite names that it references.
|
java.util.ArrayList<Effect> |
getCollisionEffects(int spriteItype1,
int spriteItype2)
Gets the array of collisions defined for two types of sprites.
|
java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>> |
getDefinedEffects()
Returns all paired effects defined in the game.
|
java.util.ArrayList<java.lang.Integer> |
getDefinedEosEffects()
Returns the list of sprite type with at least one EOS effect defined.
|
java.util.ArrayList<Effect> |
getEosEffects(int obj1)
Returns all EOS effects defined in the game.
|
double[] |
getFullResult()
Returns the complete result of the game (victory, score, timestep).
|
int |
getGameTick()
Returns the current game tick of this game.
|
java.util.ArrayList<GameDescription.InteractionData> |
getInteractionData(int itype1,
int itype2)
Get a list of interaction data objects between two sprite types.
|
static int |
getMaxSprites()
Returns the number of sprites
|
Types.WINNER[] |
getMultiWinner()
Returns an array of type Types.WINNER containing the win state of all
players in the game.
|
int |
getNoCounters() |
int |
getNoPlayers()
Method used to access the number of players in a game.
|
int |
getNumDisabledSprites(int itype)
Returns the number of sprites disabled of the type given by parameter and
all its subtypes
|
int |
getNumSprites(int itype)
Returns the number of sprites of the type given by parameter, and all its
subtypes
|
StateObservation |
getObservation()
Retuns the observation of this state.
|
StateObservationMulti |
getObservationMulti(int playerID)
Retuns the observation of this state (for multiplayer).
|
java.util.HashMap<java.lang.String,ParameterContent> |
getParameters() |
java.util.ArrayList<Node> |
getPath(Vector2d start,
Vector2d end) |
java.util.Random |
getRandomGenerator()
Returns the sampleRandom object
|
java.awt.Color |
getResourceColor(int resourceId)
Gets the color of the resource of type resourceId
|
int |
getResourceLimit(int resourceId)
Gets the maximum amount of resources of type resourceId that are allowed
by entities in the game.
|
double |
getScore()
Returns the game score.
|
double |
getScore(int playerID)
Method overloaded for multi player games.
|
java.awt.Dimension |
getScreenSize()
Gets the dimensions of the screen.
|
java.util.ArrayList<GameDescription.SpriteData> |
getSpriteData()
Get an array of sprite data objects for all leaf sprite nodes.
|
java.util.Iterator<VGDLSprite> |
getSpriteGroup(int spriteItype)
Gets an iterator for the collection of sprites for a particular sprite
type.
|
int[] |
getSpriteOrder()
Gets the order in which the sprites are drawn.
|
java.util.ArrayList<VGDLSprite> |
getSprites(int spriteItype)
Gets the collection of sprites for a particular sprite type.
|
java.util.Iterator<VGDLSprite> |
getSubSpritesGroup(int spriteItype)
Gets an iterator for the collection of sprites for a particular sprite
type, AND all subtypes.
|
java.util.ArrayList<java.lang.Integer> |
getSubTypes(int itype)
Returns an arraylist of subtypes of the given parent type.
|
VGDLSprite |
getTempAvatar(GameDescription.SpriteData sprite)
Construct and return a temporary avatar sprite
|
java.util.ArrayList<GameDescription.TerminationData> |
getTerminationData()
Return an array of termination data objects.
|
java.util.ArrayList<Termination> |
getTerminations()
Gets the array of termination conditions for this game.
|
int |
getValueCounter(int idx) |
Types.WINNER |
getWinner()
Returns the winner of this game.
|
Types.WINNER |
getWinner(int playerID)
Overloaded method for multi player games.
|
double[] |
handleResult()
Handles the result for the game, considering disqualifications.
|
void |
initForwardModel()
Starts the forward model for the game.
|
void |
initMulti()
Initialisation after the game is parsed.
|
void |
initSprites(java.util.ArrayList<java.lang.Integer> spOrder,
java.util.ArrayList<java.lang.Integer> sings,
java.util.HashMap<java.lang.Integer,SpriteContent> constructors)
Initializes the sprite structures that hold the game.
|
abstract boolean |
isGameOver()
Indicates if the game is over, or if it is still being played.
|
void |
killSprite(VGDLSprite sprite,
boolean transformed)
Kills a given sprite, adding it to the list of sprites killed at this
step.
|
void |
loadDefaultConstr()
Loads the constructor information for default objects (walls, avatar).
|
protected void |
parseParameters(GameContent content)
Reads the parameters of a game type.
|
double[] |
playGame(Player[] players,
int randomSeed,
boolean isHuman,
int humanID)
Plays the game, graphics enabled.
|
double[] |
playOnlineGame(Player[] players,
int randomSeed,
boolean isHuman,
int humanID) |
void |
printLearningResult(int levelIdx,
boolean isValidation)
Prints the result of the game, indicating the game id, level id, winner, the score and the
number of game ticks played, in this order.
|
void |
printResult()
Prints the result of the game, indicating the winner, the score and the
number of game ticks played, in this order.
|
void |
reset()
Sets the game back to the state prior to load a level.
|
void |
reverseDirection(VGDLSprite sprite)
Reverses the direction of a given sprite.
|
double[] |
runGame(Player[] players,
int randomSeed)
Runs a game, without graphics.
|
void |
setAvatar(MovingAvatar newAvatar)
Sets the avatar of the game.
|
void |
setAvatar(MovingAvatar newAvatar,
int playerID)
Overloaded method, sets the avatar specified.
|
void |
setAvatarLastAction(Types.ACTIONS action)
Sets the last action executed by the avatar.
|
void |
setAvatarLastAction(Types.ACTIONS action,
int playerID)
Overloaded method for multi player games.
|
void |
setCharMapping(java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> charMapping)
Set the char mapping that is used to parse loaded levels
|
void |
setParameters(java.util.HashMap<java.lang.String,ParameterContent> parameters) |
void |
setStochastic(boolean stoch)
Defines this game as stochastic (or not) depending on the parameter
passed.
|
protected void |
terminationHandling()
Handles termination conditions, for every termination defined in
'terminations' array.
|
protected void |
tick()
Performs one tick for the game: calling update(this) in all sprites.
|
public boolean[] humanPlayer
protected int[] spriteOrder
protected boolean[] singletons
protected Content[] classConst
public java.util.HashMap<java.lang.String,ParameterContent> parameters
protected VGDLSprite[] templateSprites
protected SpriteGroup[] spriteGroups
protected java.util.ArrayList<Effect>[][] collisionEffects
protected java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>> definedEffects
protected java.util.ArrayList<Effect>[] eosEffects
protected java.util.TreeSet<TimeEffect> timeEffects
protected java.util.ArrayList<java.lang.Integer> definedEOSEffects
protected java.util.TreeSet<Event> historicEvents
protected java.util.ArrayList<java.lang.Integer>[] iSubTypes
protected java.util.ArrayList<Pair<java.lang.Integer,java.lang.Long>>[] shieldedEffects
protected Game.Bucket[] bucketList
protected java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> charMapping
protected java.util.ArrayList<Termination> terminations
public java.util.ArrayList<VGDLSprite> kill_list
protected int[] resources_limits
protected java.awt.Color[] resources_colors
protected java.awt.Dimension screenSize
protected java.awt.Dimension size
protected boolean is_stochastic
protected int num_sprites
protected int gameTick
public static WindowInput wi
protected int block_size
protected MovingAvatar[] avatars
protected boolean isEnded
protected ForwardModel fwdModel
protected static int MAX_SPRITES
protected int nextSpriteID
public java.lang.String key_handler
protected PathFinder pathf
protected Types.ACTIONS[] avatarLastAction
public int no_players
public int no_counters
public int[] counter
public static KeyHandler ki
public void loadDefaultConstr()
public void initMulti()
public void changeSpriteOrder(java.util.ArrayList<java.lang.Integer> spOrder)
spOrder
- the request orderpublic void initSprites(java.util.ArrayList<java.lang.Integer> spOrder, java.util.ArrayList<java.lang.Integer> sings, java.util.HashMap<java.lang.Integer,SpriteContent> constructors)
spOrder
- order of sprite types to be drawn on the screen.sings
- sprites that are marked as singletons.constructors
- map of sprite constructor's information.public int getNoPlayers()
public int getNoCounters()
public int getValueCounter(int idx)
public java.util.ArrayList<GameDescription.SpriteData> getSpriteData()
public VGDLSprite getTempAvatar(GameDescription.SpriteData sprite)
public java.util.ArrayList<GameDescription.TerminationData> getTerminationData()
public java.util.ArrayList<GameDescription.InteractionData> getInteractionData(int itype1, int itype2)
itype1
- The first sprite type objectitype2
- The second sprite type objectpublic void reset()
public void initForwardModel()
protected void parseParameters(GameContent content)
content
- list of parameter-value pairs.protected void addSprite(VGDLSprite sprite, int itype)
sprite
- the new sprite to add.itype
- main int type of this sprite (leaf of the hierarchy of types).public int getNumSprites(int itype)
itype
- parent itype requested.public java.util.ArrayList<java.lang.Integer> getSubTypes(int itype)
itype
- parent itype requested.public int getNumDisabledSprites(int itype)
itype
- parent itype requested.public double[] runGame(Player[] players, int randomSeed)
players
- Players that play this game.randomSeed
- sampleRandom seed for the whole game.public double[] playGame(Player[] players, int randomSeed, boolean isHuman, int humanID)
players
- Players that play this game.randomSeed
- sampleRandom seed for the whole game.isHuman
- indicates if a human is playing the game.humanID
- ID of the human playerpublic double[] playOnlineGame(Player[] players, int randomSeed, boolean isHuman, int humanID)
public double[] handleResult()
protected void checkTimeOut()
public void printResult()
public void printLearningResult(int levelIdx, boolean isValidation)
public double[] getFullResult()
public void disqualify()
public void disqualify(int id)
id
- - id of the player that was disqualifiedpublic void abort()
public void createAvatars(int humanID)
protected void tick()
protected void eventHandling()
protected void terminationHandling()
protected void clearAll(ForwardModel fm)
fm
- Forward model where we are cleaning sprites.public void addShield(int type1, int type2, long functHash)
type1
- Recipient of the effect (sprite ID)type2
- Second sprite IDfunctHash
- Hash of the effect name to shield.public VGDLSprite addSprite(int itype, Vector2d position)
itype
- integer that identifies the definition of the sprite to addposition
- where the sprite has to be placed.public VGDLSprite addSprite(int itype, Vector2d position, boolean force)
itype
- integer that identifies the definition of the sprite to addposition
- where the sprite has to be placed.force
- if true, ignores the singleton restrictions and creates it
anyway.public VGDLSprite addSprite(SpriteContent content, Vector2d position, int itype, boolean force)
content
- definition of the sprite to addposition
- where the sprite has to be placed.itype
- integer identifier of this type of sprite.force
- If true, forces the creation ignoring singleton restrictionspublic void _updateCollisionDict(VGDLSprite sprite)
public double getScore()
public double getScore(int playerID)
playerID
- ID of the player.public void reverseDirection(VGDLSprite sprite)
sprite
- sprite to reverse.public void killSprite(VGDLSprite sprite, boolean transformed)
sprite
- the sprite to kill.transformed
- - indicates if the sprite was transformed (necessary to kill
sprite even if avatar, instead of disabling it).public java.util.Iterator<VGDLSprite> getSpriteGroup(int spriteItype)
spriteItype
- type of the sprite to retrieve.public java.util.Iterator<VGDLSprite> getSubSpritesGroup(int spriteItype)
spriteItype
- type of the sprite to retrieve.public java.util.ArrayList<VGDLSprite> getSprites(int spriteItype)
spriteItype
- type of the sprite to retrieve.public java.util.ArrayList<Effect> getCollisionEffects(int spriteItype1, int spriteItype2)
spriteItype1
- type of the first sprite.spriteItype2
- type of the second sprite.public java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>> getDefinedEffects()
public java.util.ArrayList<java.lang.Integer> getDefinedEosEffects()
public java.util.ArrayList<Effect> getEosEffects(int obj1)
public void addTimeEffect(TimeEffect ef)
public java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> getCharMapping()
public void setCharMapping(java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> charMapping)
charMapping
- new character mappingpublic java.util.ArrayList<Termination> getTerminations()
public int getResourceLimit(int resourceId)
resourceId
- the id of the resource to query for.public java.awt.Color getResourceColor(int resourceId)
resourceId
- id of the resource to query for.public java.awt.Dimension getScreenSize()
public void setStochastic(boolean stoch)
stoch
- true if the game is stochastic.public MovingAvatar getAvatar()
public MovingAvatar getAvatar(int playerID)
playerID
- ID of the player desired.public MovingAvatar[] getAvatars()
public void setAvatar(MovingAvatar newAvatar)
newAvatar
- the avatar of the game.public void setAvatar(MovingAvatar newAvatar, int playerID)
newAvatar
- the avatar of the game.playerID
- the ID of the player desired.public void setAvatarLastAction(Types.ACTIONS action)
action
- the action to set.public void setAvatarLastAction(Types.ACTIONS action, int playerID)
action
- the action to set.playerID
- the ID of the player.public abstract boolean isGameOver()
public void clearInteractionTerminationData()
public StateObservation getObservation()
public StateObservationMulti getObservationMulti(int playerID)
public java.util.Random getRandomGenerator()
public int getGameTick()
public Types.WINNER getWinner()
public Types.WINNER getWinner(int playerID)
playerID
- ID of the player.public Types.WINNER[] getMultiWinner()
public int[] getSpriteOrder()
public static int getMaxSprites()
public int getBlockSize()
public abstract void buildStringLevel(java.lang.String[] levelString, int randomSeed)
public void buildLevel(java.lang.String gamelvl, int randomSeed)
gamelvl
- file name containing the level.public java.util.HashMap<java.lang.String,ParameterContent> getParameters()
public void setParameters(java.util.HashMap<java.lang.String,ParameterContent> parameters)