gecco.server.automaton
Class AutomatonMap

java.lang.Object
  extended bygecco.server.automaton.AutomatonMap

public class AutomatonMap
extends Object

This class manages the map of automatons. It can create a map given an image.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström

Field Summary
 byte[] initialMapRGB
          The size of this array is 3*xsize*ysize.
 Automaton[][] theMap
          The map
 
Constructor Summary
AutomatonMap(Class automatonClass, int width, int height)
          Constructor for the AutomatonMap object
AutomatonMap(Class automatonClass, int width, int height, byte[] map, HashMap colorToState)
          Constructor for the AutomatonMap object
AutomatonMap(Class automatonClass, int width, int height, Image map, HashMap colorToState)
          Constructor for the AutomatonMap object
AutomatonMap(Class automatonClass, int width, int height, Reader map)
          Constructor for the AutomatonMap object
AutomatonMap(Class automatonClass, int width, int height, String imageFileName, HashMap colorToState)
          Constructor for the AutomatonMap object
AutomatonMap(Class automatonClass, int width, int height, URL map, HashMap colorToState)
          Constructor for the AutomatonMap object
 
Method Summary
 boolean areValidCoordinates(int x, int y)
          Returns true if the given coordinates exist on the map.
 Automaton getAutomaton(int x, int y)
          Gets an automaton at a given location.
 int getHeight()
          The height of the automaton grid.
 byte[] getInitialMap()
          Gets the InitialMap attribute of the AutomatonMap object
protected  Color getNearestColor(HashMap colorToState, Color color)
          Gets the nearest color that exists on the map, given a certain color.
 int[][] getNeighbourStates(int centerX, int centerY)
          Gets the states of the automatons at a 3x3 region around a given location.
 int getWidth()
          The width of the automaton grid.
protected  void initMap(Image map, HashMap colorToState)
          Allocates all automatons on the map.
protected  void initMap(String map)
          Allocates all automatons on the map.
 void setImage(byte[] map, HashMap colorToState)
          Sets the Image attribute of the AutomatonMap object
 void setImage(Image map, HashMap colorToState)
          Sets the Image attribute of the AutomatonMap object
 void setImage(Reader stream)
          Sets the Image attribute of the AutomatonMap object, by reading characters from a stream.
 void setImage(String imageFileName, HashMap colorToState)
          Sets the Image attribute of the AutomatonMap object
 void setImage(URL mapURL, HashMap colorToState)
          Sets the Image attribute of the AutomatonMap object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theMap

public Automaton[][] theMap
The map


initialMapRGB

public byte[] initialMapRGB
The size of this array is 3*xsize*ysize. It holds the red, green and blue values for the pixels in the original map in sequential order. (North-west -> south-east, row by row)

Constructor Detail

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
automatonClass - The implemented automaton class.

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height,
                    URL map,
                    HashMap colorToState)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
map - The map image.
colorToState - The color conversion function.

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height,
                    Image map,
                    HashMap colorToState)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
map - The map image.
colorToState - The color conversion function.
automatonClass - The implemented automaton class.

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height,
                    Reader map)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
map - The map image.
automatonClass - The implemented automaton class.

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height,
                    byte[] map,
                    HashMap colorToState)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
map - The map image.
colorToState - The color conversion function.
automatonClass - The implemented automaton class.

AutomatonMap

public AutomatonMap(Class automatonClass,
                    int width,
                    int height,
                    String imageFileName,
                    HashMap colorToState)
Constructor for the AutomatonMap object

Parameters:
width - The width of the map.
height - The height of the map.
imageFileName - The map image.
colorToState - The color conversion function.
automatonClass - The implemented automaton class.
Method Detail

setImage

public void setImage(URL mapURL,
                     HashMap colorToState)
Sets the Image attribute of the AutomatonMap object

Parameters:
mapURL - The new Image value
colorToState - The color conversion function.

setImage

public void setImage(Image map,
                     HashMap colorToState)
Sets the Image attribute of the AutomatonMap object

Parameters:
map - The new Image value
colorToState - The color conversion function.

setImage

public void setImage(byte[] map,
                     HashMap colorToState)
Sets the Image attribute of the AutomatonMap object

Parameters:
map - The new Image value
colorToState - The color conversion function.

setImage

public void setImage(String imageFileName,
                     HashMap colorToState)
Sets the Image attribute of the AutomatonMap object

Parameters:
imageFileName - The new Image value
colorToState - The color conversion function.

setImage

public void setImage(Reader stream)
Sets the Image attribute of the AutomatonMap object, by reading characters from a stream. This is an alternative method for creating a map, if a real image is not available.

Parameters:
stream - The stream to get characters from

getInitialMap

public byte[] getInitialMap()
Gets the InitialMap attribute of the AutomatonMap object

Returns:
The InitialMap

getAutomaton

public Automaton getAutomaton(int x,
                              int y)
                       throws IllegalArgumentException
Gets an automaton at a given location.

Parameters:
x - The x coordinate.
y - The y coordinate.
Returns:
The Automaton
Throws:
IllegalArgumentException - if the location does not exist.

getNeighbourStates

public int[][] getNeighbourStates(int centerX,
                                  int centerY)
Gets the states of the automatons at a 3x3 region around a given location.

Parameters:
centerX - The x coordinate of the center automaton.
centerY - The x coordinate of the center automaton.
Returns:
The NeighbourStates

getWidth

public int getWidth()
The width of the automaton grid.

Returns:
The width.

getHeight

public int getHeight()
The height of the automaton grid.

Returns:
The height.

areValidCoordinates

public boolean areValidCoordinates(int x,
                                   int y)
Returns true if the given coordinates exist on the map.

Parameters:
x - The x coordinate to check.
y - The x coordinate to check.
Returns:
true if the location exist on the map, false otherwise

getNearestColor

protected Color getNearestColor(HashMap colorToState,
                                Color color)
Gets the nearest color that exists on the map, given a certain color.

Parameters:
colorToState - The color conversion function.
color - The color to check.
Returns:
The nearest color on the map.

initMap

protected void initMap(Image map,
                       HashMap colorToState)
Allocates all automatons on the map.

Parameters:
map - The map image.
colorToState - The color conversion function.

initMap

protected void initMap(String map)
Allocates all automatons on the map. This is the alternative way if the map has been read from a stream.

Parameters:
map - The map.