Class GridWorldModel

java.lang.Object
jason.environment.grid.GridWorldModel

public class GridWorldModel extends Object
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 Details

  • Constructor Details

    • GridWorldModel

      protected GridWorldModel(int w, int h, int nbAgs)
  • Method Details

    • setView

      public void setView(GridWorldView v)
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getNbOfAgs

      public int getNbOfAgs()
    • inGrid

      public boolean inGrid(Location l)
    • inGrid

      public boolean inGrid(int x, int y)
    • hasObject

      public boolean hasObject(int obj, Location l)
    • 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

      public void add(int value, Location l)
    • add

      public void add(int value, int x, int y)
    • addWall

      public void addWall(int x1, int y1, int x2, int y2)
    • remove

      public void remove(int value, Location l)
    • remove

      public void remove(int value, int x, int y)
    • removeAll

      public void removeAll(int value)
    • setAgPos

      public void setAgPos(int ag, Location l)
    • setAgPos

      public void setAgPos(int ag, int x, int y)
    • getAgPos

      public Location getAgPos(int ag)
    • getAgAtPos

      public int getAgAtPos(Location l)
      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

      public boolean isFree(Location l)
      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

      public boolean isFree(int obj, Location l)
      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

      public boolean isFreeOfObstacle(Location l)
    • isFreeOfObstacle

      public boolean isFreeOfObstacle(int x, int y)
    • getFreePos

      protected Location getFreePos()
      returns a random free location using isFree to test the availability of some possible location (it means free of agents and obstacles)
    • getFreePos

      protected Location getFreePos(int obj)
      returns a random free location using isFree(object) to test the availability of some possible location