org.jscience.computing.ai.util
Class StandardMap2D

java.lang.Object
  extended by org.jscience.computing.ai.util.StandardMap2D
All Implemented Interfaces:
Navigable, Visualizable
Direct Known Subclasses:
AStarMap

public class StandardMap2D
extends java.lang.Object
implements Navigable, Visualizable

Implements a standard 2D map. For efficiency purposes, distance is implemented as Manhattan distance. Map values are specified between 0 and 255 (rendered as black to white). A position on the map is valid if the map value is less than 32.

Cost is determined as (255 - map_value) + 1, although a small additional bias is added if the movement is diagonal.


Field Summary
protected  int height
          The height of the map.
protected  int[][] mapValues
          The value of the map.
protected  int renderSize
          The render size of the map. 4
protected  int width
          The width of the map.
 
Constructor Summary
StandardMap2D()
          Creates a new instance of Map2D
StandardMap2D(int width, int height)
          Create a new instance of StandardMap2D with dimensional information.
 
Method Summary
 int createNodeID(Pathfinder.Node node)
          Create the node ID from positional information.
 double getCost(Pathfinder.Node parent, Pathfinder.Node node)
          DOCUMENT ME!
 double getDistance(Pathfinder.Node goal, Pathfinder.Node node)
          DOCUMENT ME!
 int getHeight()
          Return the height of the map.
 int getRenderSize()
          Return the render size of the map.
 int getWidth()
          Return the width of the map.
 boolean isValid(int x, int y)
          DOCUMENT ME!
 boolean isValid(Pathfinder.Node node)
          DOCUMENT ME!
 void render(java.awt.Graphics g, int ww, int hh)
          Render the map.
 void setMapAt(int x, int y, int value)
          Set the map at the given location with the given value.
 void setRenderSize(int rs)
          Set the render size of the map.
 void writeImage(java.lang.String s, int width, int height)
          Write an image of the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

renderSize

protected int renderSize
The render size of the map. 4


width

protected int width
The width of the map.


height

protected int height
The height of the map.


mapValues

protected int[][] mapValues
The value of the map.

Constructor Detail

StandardMap2D

public StandardMap2D()
Creates a new instance of Map2D


StandardMap2D

public StandardMap2D(int width,
                     int height)
Create a new instance of StandardMap2D with dimensional information.

Parameters:
width - the width of the map.
height - the height of the map.
Method Detail

getWidth

public int getWidth()
Return the width of the map.

Returns:
the width of the map.

getHeight

public int getHeight()
Return the height of the map.

Returns:
the height of the map.

getRenderSize

public int getRenderSize()
Return the render size of the map.

Returns:
the render size.

setRenderSize

public void setRenderSize(int rs)
Set the render size of the map.

Parameters:
rs - the new render size.

setMapAt

public void setMapAt(int x,
                     int y,
                     int value)
Set the map at the given location with the given value. Note that while the positional information is checked, no limits are based on the map value.

Parameters:
x - the x-position.
y - the y-position.
value - the new map value.

createNodeID

public int createNodeID(Pathfinder.Node node)
Create the node ID from positional information. This is calculated as: node.getX() * width + node.getY()

Specified by:
createNodeID in interface Navigable
Parameters:
node - the node to calculate.
Returns:
the node ID.

getCost

public double getCost(Pathfinder.Node parent,
                      Pathfinder.Node node)
DOCUMENT ME!

Specified by:
getCost in interface Navigable
Parameters:
parent - DOCUMENT ME!
node - DOCUMENT ME!
Returns:
DOCUMENT ME!

getDistance

public double getDistance(Pathfinder.Node goal,
                          Pathfinder.Node node)
DOCUMENT ME!

Specified by:
getDistance in interface Navigable
Parameters:
goal - DOCUMENT ME!
node - DOCUMENT ME!
Returns:
DOCUMENT ME!

isValid

public boolean isValid(int x,
                       int y)
DOCUMENT ME!

Parameters:
x - DOCUMENT ME!
y - DOCUMENT ME!
Returns:
DOCUMENT ME!

isValid

public boolean isValid(Pathfinder.Node node)
DOCUMENT ME!

Specified by:
isValid in interface Navigable
Parameters:
node - DOCUMENT ME!
Returns:
DOCUMENT ME!

render

public void render(java.awt.Graphics g,
                   int ww,
                   int hh)
Render the map.

Specified by:
render in interface Visualizable
Parameters:
g - the graphics context.
ww - the width of the context.
hh - the height of the context.

writeImage

public void writeImage(java.lang.String s,
                       int width,
                       int height)
Write an image of the map.

Specified by:
writeImage in interface Visualizable
Parameters:
s - the filename.
width - the width of the image.
height - the height of the image.