cad.simcad.maps
Class CellMap

java.lang.Object
  |
  +--cad.simcad.maps.CellMap
All Implemented Interfaces:
AbstractMap, PathFindable, java.io.Serializable
Direct Known Subclasses:
ClassicCellMap, ToroidalCellMap

public abstract class CellMap
extends java.lang.Object
implements AbstractMap, PathFindable, java.io.Serializable

implementing class for the AbstractMap interface This class is abstract This class family is PathFindable, that is we can find a path on it This implementation represents a point on the Map with a Cell Object

Version:
1.0
Author:
Charles-Philip Bentley
See Also:
Serialized Form

Field Summary
protected  java.util.Vector _abstractMapEventListeners
           
protected  MapUnit[] _art
           
protected  Cell[][] _cell
          The array of cells making up the map
protected  Cell[] _cex
           
protected  PathPlace[] _cgex
           
protected  FillerServer _fillerServer
           
protected  int _h
          height of the map
protected  int _heurFactor
           
protected  int _mapResolution
          resolution of the map. 1 or higher.
protected  java.lang.String _name
          The Name of the Map
protected  java.lang.Object[][] _objects
           
protected  java.util.Vector _pathPlaceEventListeners
           
protected  java.util.Vector _regions
           
protected  StatServer _statServer
           
protected  int _w
          width of the map
 
Constructor Summary
CellMap(int w, int h, int res, FillerServer fs, StatServer ss)
          Creates new CellMap Initialize the array of cells. w*h cell objects are created A FillerServer that will be used to fill the Cell objects The map cells are filled with the DefaultFiller of this FillerServer A StatServer that will return movemodifiers
 
Method Summary
 void addAbstractMapListener(AbstractMapEventListener listener)
           
 void addPathPlaceEventListener(PathPlaceEventListener listener)
           
abstract  boolean areAdjacent(MapUnit mu1, MapUnit mu2)
           
 void clearAll()
          Clear all Map Cells.
abstract  double computeHeuristic(PathPlace origin, PathPlace dest)
          Compute the heuristic for the two PathPlaces.
abstract  double computeHeuristic(PathPlace origin, PathPlace dest, double factor)
          Compute the heuristic for the two PathPlaces
 PathPlaceSet fastFindShortestPath(PathPlace origin, PathPlace dest, PathUser pu)
          Find the best Path with a productive algorithm
 void fillMap(Filler fil, int layer)
          Filler the whole map with the given filler
 PathPlaceSet findShortestPath(PathPlace origin, PathPlace dest, PathUser pu)
          Find the best Path
 PathPlaceSet findShortestPath(PathPlace origin, PathPlace dest, PathUser pu, java.util.Properties ap)
          Find the best Path
 void firePathComputation(PathPlaceSet path)
          Notice the Listeners and the PathUser that a Path has been computed
 void firePathPlaceChange(PathPlace mp)
          Notify all map Place listeners that the state of a cell has changed PRE : A Cell.
 void flushAllObjects()
           
protected  void generateBlankMap(int w, int h, Filler fil)
          Need
 java.util.Vector getAbstractMapListener()
          Returns the vector of AbstractMapListener
abstract  Cell[] getAdjacent(Cell c)
           
abstract  CellGroup[] getAdjacent(CellGroup cg)
          This method typically returns an array cells adjacent to the cell given in argument.
 PathPlace[] getAdjacent(PathPlace pp)
          Returns the PathPlace adjacent to the given PathPlace
abstract  MapUnit[] getAdjacentUnits(MapUnit mu)
           
abstract  MapUnit[] getAdjacentUnits(MapUnit[] mu)
           
 MapUnit[][] getAllMapUnits()
          Return as a double Array all the MapUnits making the Map at coordinate z=0
 Cell getCell(int x, int y)
          Return Cell of absisse X and coordinate y
 double getCostToReach(PathPlace from, PathPlace to, PathUser pu)
          PRE: Two adjacent PathPlace
 Filler getDefaultFiller()
           
 FillerServer getFillerServer()
          Returns the FillerServer of the Map
 Filler[] getFillerTypes()
           
 int getMapHeight()
           
abstract  java.lang.Object[][] getMapObjects(int xcenter, int ycenter, int halfWidth, int halfHeight)
          Return a window of Objects around the (xcenter,ycenter) point.
 int getMapResolution()
           
 MapUnit getMapUnit(int xfactor, int yfactor)
          Return the MapUnit by the coordinate x and y.
abstract  MapUnit[][] getMapUnit(int xcenter, int ycenter, int halfWidth, int halfHeight)
          This method is abstract because you need specific knowledge of the map
 int getMapWidth()
           
 double getMoveStat(PathUser pu, Filler fil, double steepratio)
           
 java.lang.String getName()
          Returns the name of the Map
 java.lang.Object getObject(int x, int y)
          Return the object on the x,y point, null if there no objects
 java.lang.Object[][] getObjects()
           
 java.util.Vector getPathPlaceEventListeners()
          Returns the vector of PathPlaceEventListeners
 int getResolution()
          Return the resolution of the Map.
 StatServer getStatServer()
          Returns the StatServer of the Map
 double getSteepRatio(int from, int to)
           
 double getSteepRatio(MapUnit from, MapUnit to)
          Returns the steepness of the slope as a percentage It is rounded down.
 int getXFactor()
          Return the X factor of the Map, usually it is the width
 int getYFactor()
          Return the Y factor of the Map, usually it is the height
 int getZFactor()
          Return the Z factor of the Map.
abstract  boolean isThereRoom(int x, int y, int xWidth, int yHeight)
          Return true if there is no object in the range specified by the parameters. false if there is one
 void populateMap(Filler fil)
          Populate the Map with the given Filler
 void removeAbstractMapListener(AbstractMapEventListener listener)
          Removes the AbstractMapEventListener
 void removeAllListeners()
          Removes all listeners, usually used for serialization
 void removePathPlaceEventListener(PathPlaceEventListener listener)
          Removes the PathPlaceEventListener
 void resetAllCells()
          Reset all Map Cells.
 void resetAllCellsValue()
          Reset all the cell values
 void resetAllUnits()
          Remove all objects from the Map
 void setHeuristicFactor(int i)
          Set the heuristic factor for this map.
 void setName(java.lang.String name)
           
 void setObject(java.lang.Object obj, int x, int y)
          Put an object at the specified position
 void setValue(PathPlace pp, double value)
          Delegates the work of tagging the given PathPlace with a double value
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_w

protected int _w
width of the map


_h

protected int _h
height of the map


_mapResolution

protected int _mapResolution
resolution of the map. 1 or higher.


_cell

protected Cell[][] _cell
The array of cells making up the map


_objects

protected java.lang.Object[][] _objects

_name

protected java.lang.String _name
The Name of the Map


_abstractMapEventListeners

protected java.util.Vector _abstractMapEventListeners

_pathPlaceEventListeners

protected java.util.Vector _pathPlaceEventListeners

_fillerServer

protected FillerServer _fillerServer

_statServer

protected StatServer _statServer

_art

protected MapUnit[] _art

_cex

protected Cell[] _cex

_cgex

protected PathPlace[] _cgex

_heurFactor

protected int _heurFactor

_regions

protected java.util.Vector _regions
Constructor Detail

CellMap

public CellMap(int w,
               int h,
               int res,
               FillerServer fs,
               StatServer ss)
Creates new CellMap Initialize the array of cells. w*h cell objects are created A FillerServer that will be used to fill the Cell objects The map cells are filled with the DefaultFiller of this FillerServer A StatServer that will return movemodifiers

Method Detail

computeHeuristic

public abstract double computeHeuristic(PathPlace origin,
                                        PathPlace dest,
                                        double factor)
Description copied from interface: AbstractMap
Compute the heuristic for the two PathPlaces

Specified by:
computeHeuristic in interface AbstractMap
Parameters:
origin - The PathPlace origin from which we want to compute the heuristic
dest - The PathPlace origin from which we want to compute the heuristic
factor - the factor by which we want to multiply the heuristic. Typically, more the factor is high, more we want to give weight to the heuristic
Returns:
a double value

computeHeuristic

public abstract double computeHeuristic(PathPlace origin,
                                        PathPlace dest)
Description copied from interface: AbstractMap
Compute the heuristic for the two PathPlaces. Use the built-in heuristic factor. This factor can be change with the setHeuristicFactor method

Specified by:
computeHeuristic in interface AbstractMap
Parameters:
origin - The PathPlace origin from which we want to compute the heuristic
dest - The PathPlace origin from which we want to compute the heuristic
Returns:
a double value

getAdjacent

public abstract CellGroup[] getAdjacent(CellGroup cg)
This method typically returns an array cells adjacent to the cell given in argument.

Pre:
a Cell
Post:
an array of cells. The cells are adjacent to the Cell g. This array might usually have 4 elements in it. But it can be otherwise. Do not assume its length is 4.

getAdjacent

public abstract Cell[] getAdjacent(Cell c)

getAdjacentUnits

public abstract MapUnit[] getAdjacentUnits(MapUnit mu)

getAdjacentUnits

public abstract MapUnit[] getAdjacentUnits(MapUnit[] mu)

areAdjacent

public abstract boolean areAdjacent(MapUnit mu1,
                                    MapUnit mu2)

resetAllUnits

public void resetAllUnits()
Remove all objects from the Map

Specified by:
resetAllUnits in interface AbstractMap
Post:
all cells have a null value

populateMap

public void populateMap(Filler fil)
Description copied from interface: AbstractMap
Populate the Map with the given Filler

Specified by:
populateMap in interface AbstractMap
Parameters:
fil - The Filler

getAdjacent

public PathPlace[] getAdjacent(PathPlace pp)
Description copied from interface: PathFindable
Returns the PathPlace adjacent to the given PathPlace

Specified by:
getAdjacent in interface PathFindable
Parameters:
pp - the PathPlace
Returns:
an array of PathPlace

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object

getMapUnit

public abstract MapUnit[][] getMapUnit(int xcenter,
                                       int ycenter,
                                       int halfWidth,
                                       int halfHeight)
This method is abstract because you need specific knowledge of the map

Specified by:
getMapUnit in interface AbstractMap
Parameters:
xcenter - x coordinate
ycenter - y coordinate
halfWidth - the number of MapUnit we want to include.
halfHeight - the number of MapUnit we want to include
Pre:
a point on the map (xcenter,ycenter), halfWidth = the number of units to considere north/south halfHeight = the number of units to consider west/east
Returns:
a double Array of MapUnits
Post:
the MapUnits contained in the range defined by the arguments

setValue

public void setValue(PathPlace pp,
                     double value)
Description copied from interface: PathFindable
Delegates the work of tagging the given PathPlace with a double value

Specified by:
setValue in interface PathFindable
Parameters:
value -
pp -

getXFactor

public int getXFactor()
Description copied from interface: AbstractMap
Return the X factor of the Map, usually it is the width

Specified by:
getXFactor in interface AbstractMap
Pre:
Returns:
an integer
Post:
the X factor of the map. The width on a classic map

getYFactor

public int getYFactor()
Description copied from interface: AbstractMap
Return the Y factor of the Map, usually it is the height

Specified by:
getYFactor in interface AbstractMap
Pre:
Returns:
an integer
Post:
the Y factor of the map. The height on a classic map

getZFactor

public int getZFactor()
Description copied from interface: AbstractMap
Return the Z factor of the Map. Usually the Altitude

Specified by:
getZFactor in interface AbstractMap
Pre:
Returns:
an integer
Post:
the Z factor of the map. The deepness on a classic map

getMapUnit

public MapUnit getMapUnit(int xfactor,
                          int yfactor)
Description copied from interface: AbstractMap
Return the MapUnit by the coordinate x and y. Since we do not ask for z coordinate, it is taken as 0

Specified by:
getMapUnit in interface AbstractMap
Parameters:
yfactor - y coordinate
xfactor - x coordinate
Pre:
xfactor and y factor, i.e. the coordinates for a classic map
Returns:
a MapUnit
Post:
the corresponding MapUnit

getAllMapUnits

public MapUnit[][] getAllMapUnits()
Description copied from interface: AbstractMap
Return as a double Array all the MapUnits making the Map at coordinate z=0

Specified by:
getAllMapUnits in interface AbstractMap
Pre:
Returns:
All the MapUnits with z coordinate z=0
Post:
all the MapUnits making the Map

generateBlankMap

protected void generateBlankMap(int w,
                                int h,
                                Filler fil)
Need


getSteepRatio

public double getSteepRatio(MapUnit from,
                            MapUnit to)
Returns the steepness of the slope as a percentage It is rounded down. Give in argument the difference of altitude of one cell movement D should rarely be over 1, except for cliffs and steep slopes

Post:
0 if the two cells are at the same altitude. Flat land

getSteepRatio

public double getSteepRatio(int from,
                            int to)

getMoveStat

public double getMoveStat(PathUser pu,
                          Filler fil,
                          double steepratio)

getDefaultFiller

public Filler getDefaultFiller()

getFillerTypes

public Filler[] getFillerTypes()

getMapResolution

public int getMapResolution()

getResolution

public int getResolution()
Description copied from interface: AbstractMap
Return the resolution of the Map. A Resolution of 1 means that the Map use a single MapUnit for the smallest object A Resolution of 2 means that the Map use two MapUnits for the smallest object ...

Specified by:
getResolution in interface AbstractMap
Returns:
a integer

getStatServer

public StatServer getStatServer()
Description copied from interface: AbstractMap
Returns the StatServer of the Map

Specified by:
getStatServer in interface AbstractMap
Pre:
Post:
The StatServer of this Map

getFillerServer

public FillerServer getFillerServer()
Description copied from interface: AbstractMap
Returns the FillerServer of the Map

Specified by:
getFillerServer in interface AbstractMap
Pre:
Post:
the FillerServer of this Map

getMapWidth

public int getMapWidth()
Pre:
Post:
an integer representing the Width of the Map

getMapHeight

public int getMapHeight()
Pre:
Post:
an integer representing the Height of the Map

getCell

public Cell getCell(int x,
                    int y)
Return Cell of absisse X and coordinate y

Pre:
the absisse x and the coordinate y of the wanted cell
Post:
The Cell object of absisse x and coordinate y

fillMap

public void fillMap(Filler fil,
                    int layer)
Filler the whole map with the given filler

Pre:
a Filler, an positive integer representing the level of the Filler
Post:
Every Cell of the CellMap is filled with the given Filler at the given level

findShortestPath

public PathPlaceSet findShortestPath(PathPlace origin,
                                     PathPlace dest,
                                     PathUser pu)
Description copied from interface: AbstractMap
Find the best Path

Specified by:
findShortestPath in interface AbstractMap
Parameters:
origin - The Origin of the Path
dest - The destination of the Path
pu - The PathUser that will use the Path
Returns:
A PathPlaceSet object. The set of PathPlaces that make up the best Path for that PathUser

findShortestPath

public PathPlaceSet findShortestPath(PathPlace origin,
                                     PathPlace dest,
                                     PathUser pu,
                                     java.util.Properties ap)
Description copied from interface: AbstractMap
Find the best Path

Specified by:
findShortestPath in interface AbstractMap
Parameters:
origin - The Origin of the Path
dest - The destination of the Path
pu - The PathUser that will use the Path
ap - The properties relative to the Algorithm
Returns:
A PathPlaceSet object. The set of PathPlaces that make up the best Path for that PathUser

clearAll

public void clearAll()
Clear all Map Cells. Calls the clearCell method on all Map Cells

Pre:
Post:
all the cells do not have fillers anymore

resetAllCells

public void resetAllCells()
Reset all Map Cells. Calls the resetCell method on all Map Cells

Post:
the Cell values are all reseted to 0

resetAllCellsValue

public void resetAllCellsValue()
Reset all the cell values

Specified by:
resetAllCellsValue in interface AbstractMap

setHeuristicFactor

public void setHeuristicFactor(int i)
Description copied from interface: AbstractMap
Set the heuristic factor for this map.

Specified by:
setHeuristicFactor in interface AbstractMap
Parameters:
i - the heuristic factor

addAbstractMapListener

public void addAbstractMapListener(AbstractMapEventListener listener)
Specified by:
addAbstractMapListener in interface AbstractMap

removeAbstractMapListener

public void removeAbstractMapListener(AbstractMapEventListener listener)
Description copied from interface: AbstractMap
Removes the AbstractMapEventListener

Specified by:
removeAbstractMapListener in interface AbstractMap

firePathComputation

public void firePathComputation(PathPlaceSet path)
Notice the Listeners and the PathUser that a Path has been computed

Specified by:
firePathComputation in interface AbstractMap
Parameters:
path - The computed PathPlaceSet

addPathPlaceEventListener

public void addPathPlaceEventListener(PathPlaceEventListener listener)
Specified by:
addPathPlaceEventListener in interface AbstractMap

removePathPlaceEventListener

public void removePathPlaceEventListener(PathPlaceEventListener listener)
Description copied from interface: AbstractMap
Removes the PathPlaceEventListener

Specified by:
removePathPlaceEventListener in interface AbstractMap

firePathPlaceChange

public void firePathPlaceChange(PathPlace mp)
Notify all map Place listeners that the state of a cell has changed PRE : A Cell. The Cell that has been modified POST : All registered listeners have been notified of the event.

Specified by:
firePathPlaceChange in interface AbstractMap
Parameters:
mp - The PathPlace that has been modified

getObjects

public java.lang.Object[][] getObjects()

getCostToReach

public double getCostToReach(PathPlace from,
                             PathPlace to,
                             PathUser pu)
PRE: Two adjacent PathPlace

Specified by:
getCostToReach in interface AbstractMap
Parameters:
from - The origin
to - the destination
pu - The PathUser
Returns:
a double value

getName

public java.lang.String getName()
Description copied from interface: AbstractMap
Returns the name of the Map

Specified by:
getName in interface AbstractMap

setName

public void setName(java.lang.String name)

getMapObjects

public abstract java.lang.Object[][] getMapObjects(int xcenter,
                                                   int ycenter,
                                                   int halfWidth,
                                                   int halfHeight)
Description copied from interface: AbstractMap
Return a window of Objects around the (xcenter,ycenter) point. Radius in width is halfWidth, Radius in height is halfHeight. Please read the @post comment

Specified by:
getMapObjects in interface AbstractMap
Parameters:
xcenter - x coordinate
ycenter - y coordinate
halfWidth - the number of Objects we want to include.
halfHeight - the number of Objects we want to include
Returns:
a double Array of MapUnits

setObject

public void setObject(java.lang.Object obj,
                      int x,
                      int y)
Description copied from interface: AbstractMap
Put an object at the specified position

Specified by:
setObject in interface AbstractMap
Parameters:
obj - The object to put
x - x coordinate
y - y coordinate

getObject

public java.lang.Object getObject(int x,
                                  int y)
Return the object on the x,y point, null if there no objects

Specified by:
getObject in interface AbstractMap
Parameters:
x - x coordinate
y - y coordinate
Returns:
An Object. Null if there is none

isThereRoom

public abstract boolean isThereRoom(int x,
                                    int y,
                                    int xWidth,
                                    int yHeight)
Description copied from interface: AbstractMap
Return true if there is no object in the range specified by the parameters. false if there is one

Specified by:
isThereRoom in interface AbstractMap
Parameters:
x - x coordinate
y - y coordinate
xWidth - length in width of the Object
yHeight - length in height of the Object
Returns:
a boolean
Post:
true if there is no objects in the area defined by the rectangle

flushAllObjects

public void flushAllObjects()

removeAllListeners

public void removeAllListeners()
Description copied from interface: AbstractMap
Removes all listeners, usually used for serialization

Specified by:
removeAllListeners in interface AbstractMap

fastFindShortestPath

public PathPlaceSet fastFindShortestPath(PathPlace origin,
                                         PathPlace dest,
                                         PathUser pu)
Description copied from interface: AbstractMap
Find the best Path with a productive algorithm

Specified by:
fastFindShortestPath in interface AbstractMap
Parameters:
origin - The Origin of the Path
dest - The destination of the Path
pu - The PathUser that will use the Path
Returns:
A PathPlaceSet object. The set of PathPlaces that make up the best Path for that PathUser

getPathPlaceEventListeners

public java.util.Vector getPathPlaceEventListeners()
Description copied from interface: AbstractMap
Returns the vector of PathPlaceEventListeners

Specified by:
getPathPlaceEventListeners in interface AbstractMap

getAbstractMapListener

public java.util.Vector getAbstractMapListener()
Description copied from interface: AbstractMap
Returns the vector of AbstractMapListener

Specified by:
getAbstractMapListener in interface AbstractMap

Logo

With the help of www.sourceforge.net and www.info.ucl.ac.be