edu.turtlekit2.kernel.agents
Class Turtle

java.lang.Object
  extended by madkit.kernel.AbstractAgent
      extended by edu.turtlekit2.kernel.agents.Turtle
All Implemented Interfaces:
Serializable, madkit.kernel.ReferenceableAgent
Direct Known Subclasses:
Ant, Ant1, Ant2, Ant3, Ant4, Ball, BlackHole, Creator, DumbTurtle, EmitMovingTurtle, Gas, MleAgent, Mosquito, MyTurtle, Ovni, Player, Predator, Prey, Star, Termite, Virus, Virus2, Walker

public class Turtle
extends madkit.kernel.AbstractAgent
implements madkit.kernel.ReferenceableAgent

The Turtle class implements the Turtle commands which are used to move set heading...

Version:
1.4 6/2008
Author:
Fabien MICHEL, Gregory Beurier
See Also:
Serialized Form

Field Summary
 double angle
           
 double angleCos
           
 double angleSin
           
 Color color
           
static int East
          default direction values: setHeading(East) ~ setHeading(0)
 boolean hidden
           
protected  String initMethod
           
static int North
          default direction values: setHeading(East) ~ setHeading(0)
static int NorthEast
          default direction values: setHeading(East) ~ setHeading(0)
static int NorthWest
          default direction values: setHeading(East) ~ setHeading(0)
 Patch position
           
static int South
          default direction values: setHeading(East) ~ setHeading(0)
static int SouthEast
          default direction values: setHeading(East) ~ setHeading(0)
static int SouthWest
          default direction values: setHeading(East) ~ setHeading(0)
static String TURTLE_DEFAULT_ROLE
           
static int West
          default direction values: setHeading(East) ~ setHeading(0)
 double x
           
 double y
           
 
Constructor Summary
Turtle()
          the initMethod is the first action (after setup) that the turtle will do
Turtle(String initMethod)
           
 
Method Summary
 void activate()
          Madkit kernel usage : you must include super.activate() when overriding
 void bk(int nb)
          turtle move backward
 int countTurtlesAt(int a, int b)
          return the number of turtles in the patch situated at (a,b) units away
 int countTurtlesHere()
           
 int createTurtle(Turtle t)
          create a turtle at the creator position (xcor,ycor) returns the ID of the new turtle
 String defaultAction()
           
 void die()
           
 double distance(double a, double b)
          returns the distance from the patch (a,b).
 double distanceNowrap(double a, double b)
          return the "on screen distance" between the turtle and the patch of absolute coordinates (a,b).
 void dropMark(String markName, Object theMark)
          Drop a mark on the patch
 void dropMarkAt(String markName, Object theMark, int a, int b)
           
 int dx()
          return the x-increment if the turtle were to take one step forward in its current heading.
 int dy()
          return the y-increment if the turtle were to take one step forward in its current heading.
 void emit(String variableName, double value)
          set the value of the corresponding patch variable
 void end()
          Madkit kernel usage : you must include super.end() when overriding
 void fd(int nb)
          turtle move forward
 XMLAttributes getAttributes()
           
 Color getColor()
           
 int getCurrentBehaviorCount()
          When the turtle switches its behavior the value of this counter is 0
 double getDirectionOfMax(String patchVariableName)
          Returns the heading toward the patch which has the highest value for patchVariable in the immediate vicinity of the turtle
 double getDirectionOfMaxInMyDirection(String patchVariableName)
           
 double getDirectionOfMin(String patchVariableName)
          Returns the heading toward the patch which has the lowest value for patchVariable in the immediate vicinity of the turtle
 double getDirectionOfMinInMyDirection(String patchVariableName)
           
 double getHeading()
          return the current heading of the turtle
 double getHeadingToMaxOf(String patchVariable, int inRadius, boolean wrap)
          Returns the heading toward the patch which has the highest value for patchVariable considering a radius in the vicinity of the agent.
 boolean getHidden()
           
 Object getMark(String variableName)
          get a mark deposed on the patch
 Object getMarkAt(String variableName, int a, int b)
           
 Patch getPatchAt(int x, int y)
           
 Color getPatchColor()
           
 Color getPatchColorAt(int a, int b)
          get the color of the patch situated at (a,b) units away
 Patch getPatchWithMaxOf(String patchVariable, int inRadius)
          Returns the patch which has the highest value for patchVariable considering a radius in the vicinity of the agent.
 double[] getPerceptPatchVariable(String patchVariableName)
          Returns an array of patchVariable quantity from the Turtle neighbors patches: - index * 180 gives the orientation of each neighbor - 8 is the patch where the turtle is.
 String getSimulationGroup()
          get the MadKit group of the simulation
 ArrayList<Turtle> getTurtlesListWithRole(String role)
           
 Turtle[] getTurtlesWithRole(String role)
           
 Turtle getTurtleWithID(int id)
          return the Turtle with the specified ID, null if not alive
 int getWorldHeight()
           
 int getWorldWidth()
           
 void giveUpRole(String role)
          the turtle will no longer play the specified role
 void home()
          teleport the turtle to the center patch
 void incrementBehaviorCount()
           
 void incrementPatchVariableAt(String variableName, double value, int a, int b)
           
 void initialisation(int a, int b, TurtleEnvironment w, int t, Patch pos)
           
 boolean isMarkPresent(String markName)
          test if the corresponding mark is present on the patch (true or false)
 boolean isMarkPresentAt(String markName, int a, int b)
          test if the corresponding mark is present on the patch situated at (a,b) units away
 boolean isPlayingRole(String role)
           
 void moveTo(double a, double b)
          teleport the turtle to patch (a,b).
 void moveTo(int a, int b)
          teleport the turtle to patch (a,b).
 int mySelf()
          return the turtle ID
 Patch nextPatch()
          Get the next patch given the current heading
 void playRole(String role)
          one way to identify a kind of turtle: give them a Role in the simulation.
 void randomHeading()
           
 double realX()
           
 double realY()
           
 void setAttributes(XMLAttributes a)
           
 void setColor(Color c)
           
 void setHeading(double direction)
          set the turtle heading to the value of direction
 void setHidden(boolean b)
          if true, the turtle hides itself (no draw)
 void setNextAction(Method nextMethod)
           
 void setPatchColor(Color c)
           
 void setPatchColorAt(Color c, int a, int b)
          set the color of the patch situated at (a,b) units away
 void setup()
           
 void setX(double a)
           
 void setXY(double a, double b)
           
 void setY(double b)
           
 double smell(String variableName)
          return the value of the corresponding patch variable
 double smellAt(String variableName, int a, int b)
          return the value of the patch situated at (a,b) units away
 double smellNextPatch(String variableName)
           
 String toString()
           
 double towards(double a, double b)
          returns direction to the patch (a,b).
 double towardsNowrap(double a, double b)
           
 void turnLeft(double a)
           
 void turnRight(double a)
           
 Turtle[] turtlesAt(int a, int b)
          return turtles who are on the patch situated at (a,b) units away
 Turtle[] turtlesHere()
          return other turtles on the current patch
 void wiggle()
           
 int xcor()
           
 int ycor()
           
 
Methods inherited from class madkit.kernel.AbstractAgent
broadcastMessage, broadcastMessage, connectedWithCommunity, createGroup, createGroup, debug, disposeMyGUI, foundGroup, getAddress, getAgentInformation, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getAgentWithRole, getAvailableCommunities, getBean, getController, getCurrentKernelAddress, getDebug, getExistingGroups, getExistingGroups, getExistingRoles, getExistingRoles, getGroups, getGUIObject, getMessageBoxSize, getMyGroups, getMyGroups, getMyRoles, getMyRoles, getName, getRoles, hasGUI, hashCode, initGUI, isBelongingToGroup, isBelongingToGroup, isCommunity, isGroup, isGroup, isMemberOf, isMemberOf, isMessageBoxEmpty, isRole, isRole, joinGroup, killAgent, launchAgent, launchAgent, leaveGroup, leaveGroup, leaveRole, leaveRole, nextMessage, print, println, receiveMessage, redisplayMyGUI, requestRole, requestRole, requestRole, restoreAgent, sendMessage, sendMessage, sendMessage, setBean, setController, setDebug, setGUIObject, setName, setOutput, setOutputWriter, windowClosing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TURTLE_DEFAULT_ROLE

public static final String TURTLE_DEFAULT_ROLE
See Also:
Constant Field Values

East

public static final int East
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

NorthEast

public static final int NorthEast
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

North

public static final int North
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

NorthWest

public static final int NorthWest
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

West

public static final int West
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

SouthWest

public static final int SouthWest
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

South

public static final int South
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

SouthEast

public static final int SouthEast
default direction values: setHeading(East) ~ setHeading(0)

See Also:
Constant Field Values

angle

public double angle

x

public double x

y

public double y

angleCos

public double angleCos

angleSin

public double angleSin

hidden

public boolean hidden

initMethod

protected String initMethod

color

public Color color

position

public Patch position
Constructor Detail

Turtle

public Turtle()
the initMethod is the first action (after setup) that the turtle will do


Turtle

public Turtle(String initMethod)
Method Detail

getCurrentBehaviorCount

public int getCurrentBehaviorCount()
When the turtle switches its behavior the value of this counter is 0

Returns:
returns the number of time the current behavior has been successively activated previously

setNextAction

public final void setNextAction(Method nextMethod)

defaultAction

public String defaultAction()

initialisation

public void initialisation(int a,
                           int b,
                           TurtleEnvironment w,
                           int t,
                           Patch pos)

activate

public void activate()
Madkit kernel usage : you must include super.activate() when overriding

Overrides:
activate in class madkit.kernel.AbstractAgent

end

public void end()
Madkit kernel usage : you must include super.end() when overriding

Overrides:
end in class madkit.kernel.AbstractAgent

setup

public void setup()

die

public void die()

setAttributes

public void setAttributes(XMLAttributes a)

getAttributes

public XMLAttributes getAttributes()

toString

public String toString()
Overrides:
toString in class madkit.kernel.AbstractAgent

getSimulationGroup

public String getSimulationGroup()
get the MadKit group of the simulation


playRole

public void playRole(String role)
one way to identify a kind of turtle: give them a Role in the simulation.


isPlayingRole

public boolean isPlayingRole(String role)

giveUpRole

public void giveUpRole(String role)
the turtle will no longer play the specified role


getHeading

public double getHeading()
return the current heading of the turtle


setHeading

public void setHeading(double direction)
set the turtle heading to the value of direction


setColor

public void setColor(Color c)

getColor

public Color getColor()

setHidden

public void setHidden(boolean b)
if true, the turtle hides itself (no draw)


getHidden

public boolean getHidden()

setPatchColor

public void setPatchColor(Color c)

getPatchColor

public Color getPatchColor()

getPatchColorAt

public Color getPatchColorAt(int a,
                             int b)
get the color of the patch situated at (a,b) units away


getPatchAt

public Patch getPatchAt(int x,
                        int y)

setPatchColorAt

public void setPatchColorAt(Color c,
                            int a,
                            int b)
set the color of the patch situated at (a,b) units away


fd

public void fd(int nb)
turtle move forward


nextPatch

public Patch nextPatch()
Get the next patch given the current heading


bk

public void bk(int nb)
turtle move backward


moveTo

public void moveTo(double a,
                   double b)
teleport the turtle to patch (a,b). Can be used as a jump primitive: MoveTo(xcor()+10,ycor())


moveTo

public void moveTo(int a,
                   int b)
teleport the turtle to patch (a,b). Can be used as a jump primitive: MoveTo(xcor()+10,ycor())


home

public void home()
teleport the turtle to the center patch


setX

public void setX(double a)

setY

public void setY(double b)

setXY

public void setXY(double a,
                  double b)

distanceNowrap

public double distanceNowrap(double a,
                             double b)
return the "on screen distance" between the turtle and the patch of absolute coordinates (a,b).

Returns:
a distance in double

distance

public double distance(double a,
                       double b)
returns the distance from the patch (a,b). The "wrapped distance", when wrap mode is on, (around the edges of the screen) if that distance is shorter than the "onscreen distance."

Parameters:
a - the a
b - the b
Returns:
the distance using double

towardsNowrap

public double towardsNowrap(double a,
                            double b)

towards

public double towards(double a,
                      double b)
returns direction to the patch (a,b). If the "wrapped distance", when wrap mode is on, (around the edges of the screen) is shorter than the "onscreen distance," towards will report the direction of the wrapped path, otherwise it while will report the direction of the onscreen path


randomHeading

public void randomHeading()

createTurtle

public int createTurtle(Turtle t)
create a turtle at the creator position (xcor,ycor) returns the ID of the new turtle


xcor

public int xcor()

ycor

public int ycor()

realX

public double realX()

realY

public double realY()

getTurtleWithID

public Turtle getTurtleWithID(int id)
return the Turtle with the specified ID, null if not alive


dx

public int dx()
return the x-increment if the turtle were to take one step forward in its current heading.


dy

public int dy()
return the y-increment if the turtle were to take one step forward in its current heading.


turnRight

public void turnRight(double a)

turnLeft

public void turnLeft(double a)

turtlesHere

public Turtle[] turtlesHere()
return other turtles on the current patch


turtlesAt

public Turtle[] turtlesAt(int a,
                          int b)
return turtles who are on the patch situated at (a,b) units away


countTurtlesHere

public int countTurtlesHere()

countTurtlesAt

public int countTurtlesAt(int a,
                          int b)
return the number of turtles in the patch situated at (a,b) units away


mySelf

public int mySelf()
return the turtle ID


getWorldWidth

public int getWorldWidth()

getWorldHeight

public int getWorldHeight()

smell

public double smell(String variableName)
return the value of the corresponding patch variable


smellNextPatch

public double smellNextPatch(String variableName)

smellAt

public double smellAt(String variableName,
                      int a,
                      int b)
return the value of the patch situated at (a,b) units away


emit

public void emit(String variableName,
                 double value)
set the value of the corresponding patch variable


incrementPatchVariableAt

public void incrementPatchVariableAt(String variableName,
                                     double value,
                                     int a,
                                     int b)

getMark

public Object getMark(String variableName)
get a mark deposed on the patch

Returns:
the corresponding java object, null if not present

getMarkAt

public Object getMarkAt(String variableName,
                        int a,
                        int b)

dropMark

public void dropMark(String markName,
                     Object theMark)
Drop a mark on the patch

Parameters:
markName: - mark name
theMark: - mark itself, can be any java object

dropMarkAt

public void dropMarkAt(String markName,
                       Object theMark,
                       int a,
                       int b)

isMarkPresent

public boolean isMarkPresent(String markName)
test if the corresponding mark is present on the patch (true or false)


isMarkPresentAt

public boolean isMarkPresentAt(String markName,
                               int a,
                               int b)
test if the corresponding mark is present on the patch situated at (a,b) units away


getTurtlesWithRole

public Turtle[] getTurtlesWithRole(String role)

getTurtlesListWithRole

public ArrayList<Turtle> getTurtlesListWithRole(String role)

wiggle

public void wiggle()

getPerceptPatchVariable

public double[] getPerceptPatchVariable(String patchVariableName)
Returns an array of patchVariable quantity from the Turtle neighbors patches: - index * 180 gives the orientation of each neighbor - 8 is the patch where the turtle is.

Parameters:
patchVariableName -
Returns:
the array of double as percepts.

getDirectionOfMax

public double getDirectionOfMax(String patchVariableName)
Returns the heading toward the patch which has the highest value for patchVariable in the immediate vicinity of the turtle

Parameters:
patchVariableName -
Returns:
the heading toward the patch which has the highest value of the neighbors

getDirectionOfMin

public double getDirectionOfMin(String patchVariableName)
Returns the heading toward the patch which has the lowest value for patchVariable in the immediate vicinity of the turtle

Parameters:
patchVariableName -
Returns:
the heading toward the patch which has the lowest value of the neighbors

getDirectionOfMaxInMyDirection

public double getDirectionOfMaxInMyDirection(String patchVariableName)

getHeadingToMaxOf

public double getHeadingToMaxOf(String patchVariable,
                                int inRadius,
                                boolean wrap)
Returns the heading toward the patch which has the highest value for patchVariable considering a radius in the vicinity of the agent.

Parameters:
patchVariable -
inRadius - the highest distance from the agent which should be considered
wrap - is the heading should be given considering the torus mode ?
Returns:

getPatchWithMaxOf

public Patch getPatchWithMaxOf(String patchVariable,
                               int inRadius)
Returns the patch which has the highest value for patchVariable considering a radius in the vicinity of the agent.

Parameters:
patchVariable -
inRadius - the highest distance from the agent which should be considered
Returns:
the patch which has the highest value for patchVariable

getDirectionOfMinInMyDirection

public double getDirectionOfMinInMyDirection(String patchVariableName)

incrementBehaviorCount

public void incrementBehaviorCount()