Class GridWorldModel

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

public class GridWorldModel
extends java.lang.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.
Author:
Jomi
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int AGENT  
    protected Location[] agPos  
    static int CLEAN  
    protected int[][] data  
    protected int height  
    static int OBSTACLE  
    protected java.util.Random random  
    protected GridWorldView view  
    protected int width  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected GridWorldModel​(int w, int h, int nbAgs)  
  • Method Summary

    Modifier and Type Method Description
    void add​(int value, int x, int y)  
    void add​(int value, Location l)  
    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 there
    int getAgAtPos​(Location l)
    returns the agent at location l or -1 if there is not one there
    Location getAgPos​(int ag)  
    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)
    protected Location getFreePos​(int obj)
    returns a random free location using isFree(object) to test the availability of some possible location
    int getHeight()  
    int getNbOfAgs()  
    int getWidth()  
    boolean hasObject​(int obj, int x, int y)  
    boolean hasObject​(int obj, Location l)  
    boolean inGrid​(int x, int y)  
    boolean inGrid​(Location l)  
    boolean isFree​(int x, int y)
    returns true if the location x,y has neither obstacle nor agent
    boolean isFree​(int obj, int x, int y)
    returns true if the location x,y has not the object obj
    boolean isFree​(int obj, Location l)
    returns true if the location l has not the object obj
    boolean isFree​(Location l)
    returns true if the location l has no obstacle neither agent
    boolean isFreeOfObstacle​(int x, int y)  
    boolean isFreeOfObstacle​(Location l)  
    void remove​(int value, int x, int y)  
    void remove​(int value, Location l)  
    void set​(int value, int x, int y)  
    void setAgPos​(int ag, int x, int y)  
    void setAgPos​(int ag, Location l)  
    void setView​(GridWorldView v)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
    • 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