JGAP

examples.gp.paintedDesert
Class AntMap

java.lang.Object
  extended by examples.gp.paintedDesert.AntMap

public class AntMap
extends java.lang.Object

Holds the map of the painted desert sand locations

Since:
3.2

Field Summary
static int ANT_AT_POSITION
          Ant at this location
static int BLACK
          Black sand at this location or carried by the ant
static int EMPTY
          No Sand at this location or carried by the ant
static int GRAY
          Gray sand at this location or carried by the ant
static int STRIPED
          Striped sand at this location or carried by the ant
 
Constructor Summary
AntMap(int[][] a_map, Ant[] a_ants)
          Creates the map.
 
Method Summary
 int atLocation(int x, int y)
          Returns the color of sand at the provided location
 void finalize()
          Determine the final position of grains of sand.
 int fitness()
          Calculates how well the sand is moved to the proper columns.
 Ant getAnt()
          Returns the current Ant.
 Ant[] getAnts()
          Returns this list of ants
 int getHeight()
          Returns the height of the map
 int[][] getInitialMap()
          Returns a representation of the initial map
 int[][] getMap()
          Returns a representation of the current map
 int getMoveCount()
          Asks each ant for the number of moves and sums up the result.
 int getWidth()
          Returns the width of the map
 void init()
           
 boolean mayDropSand(int x, int y)
          Identifies that sand may be placed here
 Ant nextAnt()
          Increments the index to the next ant.
 void placeSand(int sandColor, int x, int y)
          Places sand or identifies an empty spot at the current position
 int removeSand(int x, int y)
          Removes the sand from the current position
 void resetMap()
          Resets the sand and ant back to their positions before the program was applied
 boolean sandAtLocation(int x, int y)
          Identifies whether there is sand at the provided location
 boolean sandBelongsHere(int sandColor, int x)
          Identifies that sand is at that location
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final int EMPTY
No Sand at this location or carried by the ant

See Also:
Constant Field Values

BLACK

public static final int BLACK
Black sand at this location or carried by the ant

See Also:
Constant Field Values

GRAY

public static final int GRAY
Gray sand at this location or carried by the ant

See Also:
Constant Field Values

STRIPED

public static final int STRIPED
Striped sand at this location or carried by the ant

See Also:
Constant Field Values

ANT_AT_POSITION

public static final int ANT_AT_POSITION
Ant at this location

See Also:
Constant Field Values
Constructor Detail

AntMap

public AntMap(int[][] a_map,
              Ant[] a_ants)
Creates the map.

Parameters:
a_map - the map itself
a_ants - the list of ants
Method Detail

placeSand

public void placeSand(int sandColor,
                      int x,
                      int y)
Places sand or identifies an empty spot at the current position

Parameters:
sandColor -
x -
y -

atLocation

public int atLocation(int x,
                      int y)
Returns the color of sand at the provided location

Parameters:
x -
y -
Returns:

getMap

public int[][] getMap()
Returns a representation of the current map

Returns:

getInitialMap

public int[][] getInitialMap()
Returns a representation of the initial map

Returns:

sandAtLocation

public boolean sandAtLocation(int x,
                              int y)
Identifies whether there is sand at the provided location

Parameters:
x -
y -
Returns:

sandBelongsHere

public boolean sandBelongsHere(int sandColor,
                               int x)
Identifies that sand is at that location

Parameters:
sandColor -
x -
Returns:

mayDropSand

public boolean mayDropSand(int x,
                           int y)
Identifies that sand may be placed here

Parameters:
x -
y -
Returns:

removeSand

public int removeSand(int x,
                      int y)
Removes the sand from the current position

Parameters:
x -
y -
Returns:

getAnt

public Ant getAnt()
Returns the current Ant. The current ant is incremented by the NextAnt method.

Returns:

finalize

public void finalize()
Determine the final position of grains of sand. If an ant is carrying sand and there is no sand at the current position, drop the sand at this position. If there is sand, rubberband the sand back to where the ant picked up the sand. If both locations are full, then pick the nearest open spot

Overrides:
finalize in class java.lang.Object
See Also:
Object.finalize()

fitness

public int fitness()
Calculates how well the sand is moved to the proper columns.

Returns:

nextAnt

public Ant nextAnt()
Increments the index to the next ant.

Returns:

getMoveCount

public int getMoveCount()
Asks each ant for the number of moves and sums up the result.

Returns:

getWidth

public int getWidth()
Returns the width of the map

Returns:

getHeight

public int getHeight()
Returns the height of the map

Returns:

getAnts

public Ant[] getAnts()
Returns this list of ants

Returns:

init

public void init()

resetMap

public void resetMap()
Resets the sand and ant back to their positions before the program was applied


JGAP