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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int value, int x, int y) void
void
addWall
(int x1, int y1, int x2, int y2) int
countObjects
(int obj) int
getAgAtPos
(int x, int y) returns the agent at x,y or -1 if there is not one thereint
returns the agent at location l or -1 if there is not one theregetAgPos
(int ag) protected Location
returns a random free location using isFree to test the availability of some possible location (it means free of agents and obstacles)protected Location
getFreePos
(int obj) returns a random free location using isFree(object) to test the availability of some possible locationint
int
int
getWidth()
boolean
hasObject
(int obj, int x, int y) boolean
boolean
inGrid
(int x, int y) boolean
boolean
isFree
(int x, int y) returns true if the location x,y has neither obstacle nor agentboolean
isFree
(int obj, int x, int y) returns true if the location x,y has not the object objboolean
returns true if the location l has not the object objboolean
returns true if the location l has no obstacle neither agentboolean
isFreeOfObstacle
(int x, int y) boolean
void
remove
(int value, int x, int y) void
void
removeAll
(int value) void
set
(int value, int x, int y) void
setAgPos
(int ag, int x, int y) void
void
-
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
-