Package jason.environment.grid
Class GridWorldModel
java.lang.Object
jason.environment.grid.GridWorldModel
Simple model for a grid world (with agents and obstacles).
Every agent gets an identification (a integer from 0 to the number of ag - 1). The relation of this identification with agent's name should be done in the environment class and is application dependent.
Every type of object in the environment is represented by a bit mask: an agent is 000010; an obstacle is 000100; .... New types of objects should follow this pattern, for example, GOLD = 8 (001000), ENEMY=16 (010000), ... A place with two object is represented by the OR between the masks: an agent and a gold is 001010.
Limitations:
- The number of agents can not change dynamically
- Two agents can not share the same place. More generally, two objects with the same "mask" can not share a place.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int value, int x, int y) voidvoidaddWall(int x1, int y1, int x2, int y2) intcountObjects(int obj) intgetAgAtPos(int x, int y) returns the agent at x,y or -1 if there is not one thereintreturns the agent at location l or -1 if there is not one theregetAgPos(int ag) protected Locationreturns a random free location using isFree to test the availability of some possible location (it means free of agents and obstacles)protected LocationgetFreePos(int obj) returns a random free location using isFree(object) to test the availability of some possible locationintintintgetWidth()booleanhasObject(int obj, int x, int y) booleanbooleaninGrid(int x, int y) booleanbooleanisFree(int x, int y) returns true if the location x,y has neither obstacle nor agentbooleanisFree(int obj, int x, int y) returns true if the location x,y has not the object objbooleanreturns true if the location l has not the object objbooleanreturns true if the location l has no obstacle neither agentbooleanisFreeOfObstacle(int x, int y) booleanvoidremove(int value, int x, int y) voidvoidremoveAll(int value) voidset(int value, int x, int y) voidsetAgPos(int ag, int x, int y) voidvoid
-
Field Details
-
CLEAN
public static final int CLEAN- See Also:
-
AGENT
public static final int AGENT- See Also:
-
OBSTACLE
public static final int OBSTACLE- See Also:
-
width
protected int width -
height
protected int height -
data
protected int[][] data -
agPos
-
view
-
random
-
-
Constructor Details
-
GridWorldModel
protected GridWorldModel(int w, int h, int nbAgs)
-
-
Method Details
-
setView
-
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getNbOfAgs
public int getNbOfAgs() -
inGrid
-
inGrid
public boolean inGrid(int x, int y) -
hasObject
-
hasObject
public boolean hasObject(int obj, int x, int y) -
countObjects
public int countObjects(int obj) -
set
public void set(int value, int x, int y) -
add
-
add
public void add(int value, int x, int y) -
addWall
public void addWall(int x1, int y1, int x2, int y2) -
remove
-
remove
public void remove(int value, int x, int y) -
removeAll
public void removeAll(int value) -
setAgPos
-
setAgPos
public void setAgPos(int ag, int x, int y) -
getAgPos
-
getAgAtPos
returns the agent at location l or -1 if there is not one there -
getAgAtPos
public int getAgAtPos(int x, int y) returns the agent at x,y or -1 if there is not one there -
isFree
returns true if the location l has no obstacle neither agent -
isFree
public boolean isFree(int x, int y) returns true if the location x,y has neither obstacle nor agent -
isFree
returns true if the location l has not the object obj -
isFree
public boolean isFree(int obj, int x, int y) returns true if the location x,y has not the object obj -
isFreeOfObstacle
-
isFreeOfObstacle
public boolean isFreeOfObstacle(int x, int y) -
getFreePos
returns a random free location using isFree to test the availability of some possible location (it means free of agents and obstacles) -
getFreePos
returns a random free location using isFree(object) to test the availability of some possible location
-