edu.udo.cs.ie.cowbots.util
Class DistanceMap

Package class diagram package DistanceMap
java.lang.Object
  extended by edu.udo.cs.ie.cowbots.util.DistanceMap

public class DistanceMap
extends java.lang.Object

this class models a distance map that is used to evaluate the distance between cells on a tileworld.


Nested Class Summary
(package private)  class DistanceMap.FillStart
          internal used helper class for next fill point
 
Field Summary
(package private)  int[][] attrib
           
(package private)  int[] bestSearches
           
(package private) static byte BIT_ATSWITCH
           
(package private) static byte BIT_OBSTACLE
           
(package private)  int borderGuard
           
(package private)  int fillX
           
(package private)  int fillY
           
(package private)  int height
           
(package private)  int[][] map
           
(package private)  int[][] penalty
           
(package private)  int[] penSearches
           
(package private) static java.lang.String[] relDir
           
(package private) static int[] relX
           
(package private) static int[] relY
           
(package private)  int width
           
 
Constructor Summary
DistanceMap(int x, int y)
          creates a distance map
 
Method Summary
 void debugPrint()
          debug output to console
 int distance(int x, int y)
          returns the distance from a point to the distance maps reference point. the meaning of the return values is: 0 : no path exists to the fill point 1 : same field >1 : distance to fill point
 void fill(int sx, int sy)
          creates distances from a starting point
 java.util.LinkedList<java.awt.Point> getPath(int fromX, int fromY)
          this method returns a path to the fill position. if no path exists, null is returned. if the distance is already zero, an empty list is returned. otherwise, the next cells are returned. if no path exists, null is returned.
protected  char i2c(int i)
          helper method, converts an integer to a character between 0..9, a..z. wraps around z if input value is to high.
protected  void preFill()
          initializes the map with initial distances (0 for every cell)
 void setAtSwitch(int x, int y)
          marks a cell as adjacent to a switch
 void setAttrib(int x, int y, byte attr)
          sets an attribute for a cell. a cell is a byte value, where 0 indicating an empty cell.
 void setObstacle(int x, int y)
          marks a cell as an obstacle (unpassable)
 void setPenalty(int x, int y, int pen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

int[][] map

penalty

int[][] penalty

attrib

int[][] attrib

width

int width

height

int height

borderGuard

int borderGuard

fillX

int fillX

fillY

int fillY

BIT_OBSTACLE

static final byte BIT_OBSTACLE
See Also:
Constant Field Values

BIT_ATSWITCH

static final byte BIT_ATSWITCH
See Also:
Constant Field Values

relX

static int[] relX

relY

static int[] relY

relDir

static java.lang.String[] relDir

bestSearches

int[] bestSearches

penSearches

int[] penSearches
Constructor Detail

DistanceMap

public DistanceMap(int x,
                   int y)
creates a distance map

Parameters:
x - width of map
y - height of map
Method Detail

fill

public void fill(int sx,
                 int sy)
creates distances from a starting point

Parameters:
sx - start x
sy - start y

preFill

protected void preFill()
initializes the map with initial distances (0 for every cell)


getPath

public java.util.LinkedList<java.awt.Point> getPath(int fromX,
                                                    int fromY)
this method returns a path to the fill position. if no path exists, null is returned. if the distance is already zero, an empty list is returned. otherwise, the next cells are returned. if no path exists, null is returned.

Parameters:
fromX - from start x
fromY - from start y
Returns:
null - no path avail or list with cells to go to

distance

public int distance(int x,
                    int y)
returns the distance from a point to the distance maps reference point. the meaning of the return values is: 0 : no path exists to the fill point 1 : same field >1 : distance to fill point

Parameters:
x - point to query distance for (x)
y - point to query distance for (y)
Returns:
distance of (x,y) to reference point

setAttrib

public void setAttrib(int x,
                      int y,
                      byte attr)
sets an attribute for a cell. a cell is a byte value, where 0 indicating an empty cell.

Parameters:
x - x coordinate part
y - y coordinate part
attr - cell attribute to set

setPenalty

public void setPenalty(int x,
                       int y,
                       int pen)

setObstacle

public void setObstacle(int x,
                        int y)
marks a cell as an obstacle (unpassable)

Parameters:
x -
y -

setAtSwitch

public void setAtSwitch(int x,
                        int y)
marks a cell as adjacent to a switch

Parameters:
x -
y -

debugPrint

public void debugPrint()
debug output to console


i2c

protected char i2c(int i)
helper method, converts an integer to a character between 0..9, a..z. wraps around z if input value is to high.

Parameters:
i - positive integer
Returns:
character value for input