ai.worlds
Class GridEnvironment

java.lang.Object
  extended byai.worlds.Environment
      extended byai.worlds.GridEnvironment
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable
Direct Known Subclasses:
VacuumWorld, WumpusWorld

public abstract class GridEnvironment
extends Environment
implements java.lang.Cloneable

An environment with a two-dimensional grid layout occupied by objects.

Author:
Jill Zimmerman -- jill.zimmerman@goucher.edu

Nested Class Summary
 class GridEnvironment.GridCanvas
           
 
Field Summary
 GridEnvironment.GridCanvas canvas
          The grid display.
static Location DOWN
           
 java.lang.Object[][] grid
          The grid of cells.
static Location LEFT
           
static Location RIGHT
           
 Location size
          The size of the grid.
 Location start
          The starting location.
static Location UP
           
 boolean[][] visited
          Indicates whether a cell has been visited or not.
 
Fields inherited from class ai.worlds.Environment
agents, display, maxSteps, runner, step
 
Constructor Summary
GridEnvironment(Agent[] a, int xsize, int ysize, javax.swing.JFrame f)
           
 
Method Summary
 void addObj(Location loc, Obj ob)
          Add an object to the grid.
 java.lang.Object clone()
           
 boolean contains(java.util.Vector v, java.lang.Class c)
          Determine if vector contains an instance of given class.
static void copyGrid(GridEnvironment from, GridEnvironment to, int xsize, int ysize)
           
 void fillGrid(double prob, java.lang.Class c)
          Fill grid with objects.
 void fillLoc(Location loc, java.lang.Class c)
           
 void forward(AgentBody body)
          Move the agent forward.
 Obj getItem(java.util.Vector v, java.lang.Class c)
          Return the first instance of a class in a Vector.
 void grab(AgentBody body)
          Grab a "grabable" object at the current location.
 boolean neighbor(Location loc, java.lang.Class c)
          Determine whether a class object is in a neighboring cell.
 void removeObj(Location loc, Obj ob)
          Remove object from grid.
 void snapshot()
          Paint a snapshot of the environment onto the canvas and update fields in the gridPanel.
 boolean termination()
          Terminate if all agents are dead.
 void turn(AgentBody body, java.lang.String direction)
          Turn the agent either left or right.
 void updateEnv()
          Turn off all bump flags and execute the agent actions.
 
Methods inherited from class ai.worlds.Environment
displayEnv, executeAgentActions, getPercept, legalAction, performanceMeasure, run, start, stop, takeStep
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final Location LEFT

RIGHT

public static final Location RIGHT

UP

public static final Location UP

DOWN

public static final Location DOWN

size

public Location size
The size of the grid.


grid

public java.lang.Object[][] grid
The grid of cells.


visited

public boolean[][] visited
Indicates whether a cell has been visited or not.


start

public Location start
The starting location.


canvas

public GridEnvironment.GridCanvas canvas
The grid display.

Constructor Detail

GridEnvironment

public GridEnvironment(Agent[] a,
                       int xsize,
                       int ysize,
                       javax.swing.JFrame f)
Method Detail

clone

public java.lang.Object clone()

forward

public void forward(AgentBody body)
Move the agent forward.

Parameters:
body - is the agent body.

turn

public void turn(AgentBody body,
                 java.lang.String direction)
Turn the agent either left or right.

Parameters:
body - is the agent body.
direction - is "left" or "right"

grab

public void grab(AgentBody body)
Grab a "grabable" object at the current location.

Parameters:
body - is the agent body.

termination

public boolean termination()
Terminate if all agents are dead.

Specified by:
termination in class Environment

updateEnv

public void updateEnv()
Turn off all bump flags and execute the agent actions.

Overrides:
updateEnv in class Environment

removeObj

public void removeObj(Location loc,
                      Obj ob)
Remove object from grid.

Parameters:
loc - is location in grid.
ob - is object to be removed

addObj

public void addObj(Location loc,
                   Obj ob)
Add an object to the grid.

Parameters:
loc - is the location in grid.
ob - is object to be added.

fillGrid

public void fillGrid(double prob,
                     java.lang.Class c)
Fill grid with objects.

Parameters:
prob - is the probability of object occurring.
c - is class to be added to grid.

fillLoc

public void fillLoc(Location loc,
                    java.lang.Class c)

contains

public boolean contains(java.util.Vector v,
                        java.lang.Class c)
Determine if vector contains an instance of given class.

Parameters:
v - is the vector.
c - is the given class.

getItem

public Obj getItem(java.util.Vector v,
                   java.lang.Class c)
Return the first instance of a class in a Vector.

Parameters:
v - is the vector.
c - is the class.

neighbor

public boolean neighbor(Location loc,
                        java.lang.Class c)
Determine whether a class object is in a neighboring cell.

Parameters:
loc - is a grid location.
c - is a class.

snapshot

public void snapshot()
Paint a snapshot of the environment onto the canvas and update fields in the gridPanel.

Specified by:
snapshot in class Environment

copyGrid

public static final void copyGrid(GridEnvironment from,
                                  GridEnvironment to,
                                  int xsize,
                                  int ysize)