JGAP

examples.gp.paintedDesert
Class Ant

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

public class Ant
extends java.lang.Object

Represents the Ant. Contains the rules about how an Ant behaves.

Since:
3.2

Constructor Summary
Ant(int x, int y)
          Constructs the Ant at an initial location.
 
Method Summary
 int drop(AntMap antmap)
          Drops the sand at the current location if possible.
 int getCarrying()
          Returns the grain of sand the ant is carrying.
 int getMoves()
          Identifies the number of moves the ant has performed
 int getPickedUpFromXLoc()
          Returns the x location where the sand was picked up.
 int getPickedUpFromYLoc()
          Returns the Y locaiton where the sand was picked up.
 int getXpos()
          Returns the x location of the ant.
 int getYpos()
          Returns the y location of the ant.
 int goE(AntMap map)
          Instructs the ant to go east, if possible.
 int goN(AntMap map)
          Instructs the ant to go north, if possible
 int goS(AntMap map)
          Instructs the ant to go south, if possible
 int goW(AntMap map)
          Instructs the ant to go west, if possible
 void incrementMoveCounter()
          Increments the move counter for the ant
 boolean isCarrying()
          Identifies if the ant is carrying any sand.
 boolean mayPickup(AntMap map)
          Identifies whether the ant could pickup sand
 int moveRandom(AntMap map)
          Randomly moves the ant.
 int pickup(AntMap antmap)
          Picks up the sand at the current location, if the ant is not carrying any sand and there is sand at the location
 void reset()
          Resets the ant to its original location on the map.
 boolean sandAtLocation(AntMap map)
          Identifies whether there is sand at the location
 boolean sandBelongsHere(AntMap map)
          Identifies that sand the ant is carrying, belongs in this column
 int sandColor(AntMap map)
          Identifies the color of the sand at the ant's location
 void setPickedUpFromXLoc(int pickedUpFromXLoc)
          Stores the x location where the sand was picked up.
 void setPickedUpFromYLoc(int pickedUpFromYLoc)
          Sets the y location where the sand was picked up.
 void setXpos(int m_xpos)
          Sets the x location of the ant.
 void setYpos(int m_ypos)
          Sets the y location of the ant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ant

public Ant(int x,
           int y)
Constructs the Ant at an initial location.

Parameters:
x - Initial x location
y - Initial y locaiton
Method Detail

setXpos

public void setXpos(int m_xpos)
Sets the x location of the ant.

Parameters:
m_xpos -

getXpos

public int getXpos()
Returns the x location of the ant.

Returns:
The x location.

setYpos

public void setYpos(int m_ypos)
Sets the y location of the ant.

Parameters:
m_ypos - The y location

getYpos

public int getYpos()
Returns the y location of the ant.

Returns:
The y location

getCarrying

public int getCarrying()
Returns the grain of sand the ant is carrying. Returns EMPTY if no sand is being carried.

Returns:
The color of sand

isCarrying

public boolean isCarrying()
Identifies if the ant is carrying any sand.

Returns:
The color of sand

setPickedUpFromXLoc

public void setPickedUpFromXLoc(int pickedUpFromXLoc)
Stores the x location where the sand was picked up.


getPickedUpFromXLoc

public int getPickedUpFromXLoc()
Returns the x location where the sand was picked up.

Returns:

setPickedUpFromYLoc

public void setPickedUpFromYLoc(int pickedUpFromYLoc)
Sets the y location where the sand was picked up.

Parameters:
pickedUpFromYLoc - The y location

getPickedUpFromYLoc

public int getPickedUpFromYLoc()
Returns the Y locaiton where the sand was picked up.

Returns:
The Y location

drop

public int drop(AntMap antmap)
Drops the sand at the current location if possible.

Returns:
the color of sand the ant is carrying whether or not it could be dropped at the current location.

pickup

public int pickup(AntMap antmap)
Picks up the sand at the current location, if the ant is not carrying any sand and there is sand at the location

Parameters:
antmap - The map of locations of sand
Returns:
The sand color at the location whether or not the Ant could pick up the sand.

moveRandom

public int moveRandom(AntMap map)
Randomly moves the ant.

Parameters:
map - The map of locations of sand
Returns:
The sand at the new location of the Ant.

goE

public int goE(AntMap map)
Instructs the ant to go east, if possible.


goW

public int goW(AntMap map)
Instructs the ant to go west, if possible

Parameters:
map -
Returns:
The color of the sand at the new location

goN

public int goN(AntMap map)
Instructs the ant to go north, if possible

Parameters:
map -
Returns:
The color of the sand at the new location

goS

public int goS(AntMap map)
Instructs the ant to go south, if possible

Parameters:
map -
Returns:
The color of the sand at the new location

mayPickup

public boolean mayPickup(AntMap map)
Identifies whether the ant could pickup sand

Parameters:
map -
Returns:

sandAtLocation

public boolean sandAtLocation(AntMap map)
Identifies whether there is sand at the location

Parameters:
map -
Returns:
true if sand at location

sandBelongsHere

public boolean sandBelongsHere(AntMap map)
Identifies that sand the ant is carrying, belongs in this column

Parameters:
map -
Returns:

sandColor

public int sandColor(AntMap map)
Identifies the color of the sand at the ant's location

Parameters:
map -
Returns:

incrementMoveCounter

public void incrementMoveCounter()
Increments the move counter for the ant


getMoves

public int getMoves()
Identifies the number of moves the ant has performed

Returns:

reset

public void reset()
Resets the ant to its original location on the map.


JGAP