public class Turtle extends AbstractAgent
AbstractAgent.ReturnCode, AbstractAgent.State
Modifier and Type | Field and Description |
---|---|
protected Color |
color
The turtle's color.
|
protected static Random |
generator
The turtle's PRNG //TODO have a real model
|
logger
Modifier and Type | Method and Description |
---|---|
protected void |
activate() |
int |
createTurtle(Turtle t)
Launch a turtle with a random location.
|
int |
createTurtle(Turtle t,
double x,
double y)
Launch a turtle with predefined coordinates
|
int |
createTurtleHere(Turtle t)
launch a turtle at the creator position (xcor,ycor)
and returns the given ID to the new turtle
|
String |
defaultBehavior() |
double |
distance(double a,
double b)
returns the distance from the patch (a,b).
|
double |
distance(Turtle t) |
double |
distanceNoWrap(double xCoordinate,
double yCoordinate)
return the "on screen distance" between the turtle
and the coordinates (a,b).
|
int |
dx()
return the x-increment if the turtle were to take one
step forward in its current heading.
|
int |
dy()
return the int y-increment if the turtle were to take one
step forward in its current heading.
|
protected void |
emit(String pheromone,
float value)
Shortcut for
getPheromone(pheromone).incValue(xcor(), ycor(), value); |
protected static TurtleKit |
executeThisTurtle(int nbOfInstances,
String... args)
This offers a convenient way to create a main method
that launches a simulation containing the turtle
class under development.
|
void |
fd(double nb)
Makes turtle moves forward of nb space units
|
int |
get1DIndex() |
int |
get1DIndex(int x,
int y) |
Color |
getColor() |
String |
getCommunity() |
int |
getCurrentBehaviorCount()
When the turtle switches its behavior the value of this counter is 0
|
TKEnvironment |
getEnvironment() |
float |
getFieldValue(Pheromone p) |
double |
getHeading()
return the current heading of the turtle
|
int |
getID()
the id of this turtle
|
int |
getMaxDirection(Pheromone p) |
int |
getMinDirection(Pheromone p) |
<T extends Turtle> |
getNearestTurtle(double realRadius,
Class<T> turtleType)
Returns the nearest turtle of type T from this one
according to its real distance.
|
Turtle |
getNearestTurtle(int inRadius)
Returns the nearest turtle from this one
within the inRadius-vicinity as a patch distance.
|
<T extends Turtle> |
getNearestTurtle(int patchRadius,
Class<T> turtleType)
Returns the nearest turtle of type T from this one
according to its patch distance.
|
Turtle |
getNearestTurtleWithRole(int patchRadius,
String role)
Returns the nearest turtle of type T from this one
according to its patch distance.
|
<T extends Turtle> |
getNearestTurtleWithRole(int patchRadius,
String role,
Class<T> turtleType)
Returns the nearest turtle of type T from this one
according to its patch distance.
|
Patch |
getNextPatch() |
List<Turtle> |
getOtherTurtles(int inRadius,
boolean includeThisPatch) |
<T extends Turtle> |
getOtherTurtles(int inRadius,
boolean includeThisPatch,
Class<T> turtleType) |
List<Turtle> |
getOtherTurtlesWithRole(int inRadius,
boolean includeThisPatch,
String role) |
<T extends Turtle> |
getOtherTurtlesWithRole(int inRadius,
boolean includeThisPatch,
String role,
Class<T> turtleType) |
Patch |
getPatch() |
Patch |
getPatchAt(int a,
int b)
Get the patch situated at (a,b) units away
|
Color |
getPatchColor() |
List<Turtle> |
getPatchOtherTurtles() |
double |
getPheroMaxDirection(Pheromone phero)
Gets the direction where there is a maximum of this pheromone
|
double |
getPheroMinDirection(Pheromone phero)
Gets the direction where there is a minimum of this pheromone
|
Pheromone |
getPheromone(String name)
Gets the corresponding pheromone or create a new one using defaults
parameters : 50% for both the evaporation rate and
the diffusion rate.
|
Collection<Pheromone> |
getPheromones() |
int |
getWorldHeight() |
int |
getWorldWidth() |
double |
getX() |
double |
getY() |
void |
giveUpRole(String role)
the turtle will no longer play the specified role
|
void |
home()
Teleports the turtle to the center patch
|
void |
incrementBehaviorCount() |
boolean |
isPatchChanged()
Check if this is true and reset the property.
|
boolean |
isPlayingRole(String role)
Tells if the turtle is currently playing this role
|
void |
moveTo(double a,
double b)
teleport the turtle to patch (a,b).
|
int |
mySelf()
Deprecated.
replaced by
AbstractAgent.hashCode()
return the turtle ID |
double |
normalizeX(double x)
Returns the normalized value of x, so that
it is inside the environment's boundaries
|
double |
normalizeX(int x)
Returns the normalized value of x, so that
it is inside the environment's boundaries
|
double |
normalizeY(double y)
Returns the normalized value of y, so that
it is inside the environment's boundaries
|
double |
normalizeY(int y)
Returns the normalized value of y, so that
it is inside the environment's boundaries
|
void |
playRole(String role)
one way to identify a kind of turtle: give them a Role in the simulation.
|
void |
randomHeading() |
void |
randomHeading(int range) |
void |
randomLocation()
Teleports the turtle to a random location
|
void |
setColor(Color c) |
void |
setCurrentBehaviorCount(int i) |
void |
setHeading(double direction)
set the turtle heading to the value of direction
|
void |
setHeadingTowards(Turtle t)
Set the heading toward the turtle t.
|
void |
setHeadingTowards(Turtle t,
double offset)
Set the heading toward the turtle t.
|
void |
setHeadingTowardsNoWrap(Turtle t) |
void |
setNextAction(String methodName) |
void |
setPatchColor(Color c) |
void |
setup()
Deprecated.
activate() should be overridden instead, beginning by super.activate(); |
void |
setX(double a) |
void |
setXY(double a,
double b) |
void |
setY(double b) |
float |
smell(String pheromone) |
float |
smellAt(Pheromone pheromone,
int xOffset,
int yOffset) |
float |
smellAt(String pheromoneName,
int xOffset,
int yOffset) |
void |
step()
Shortcut for fd(1)
|
String |
toString() |
double |
towards(double a,
double b)
returns direction to the patch (a,b).
|
double |
towards(Turtle t) |
void |
towardsMaxGradientField(Pheromone p) |
void |
towardsMinGradientField(Pheromone p) |
double |
towardsNoWrap(double a,
double b) |
double |
towardsNoWrap(Turtle t) |
void |
turnLeft(double a) |
void |
turnRight(double a) |
void |
wiggle()
shortcut for
wiggle(45) |
void |
wiggle(int range) |
int |
xcor() |
int |
ycor() |
broadcastMessage, broadcastMessageWithRole, bucketModeCreateGroup, bucketModeRequestRole, checkAgentAddress, compareTo, createGroup, createGroup, createGroup, createGroupIfAbsent, createGroupIfAbsent, createGroupIfAbsent, createGUIOnStartUp, destroyCommunity, destroyGroup, destroyRole, end, executeThisAgent, executeThisAgent, executeThisAgent, getAgentAddressIn, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getDistantAgentWithRole, getExistingCommunities, getExistingGroups, getExistingRoles, getKernelAddress, getLogger, getMadkitConfig, getMadkitProperty, getMadkitProperty, getMyGroups, getMyRoles, getName, getNetworkID, getOrganizationSnapShot, getReplyTo, getServerInfo, getSimpleNetworkID, getState, hasGUI, hashCode, hasRole, isAlive, isCommunity, isGroup, isKernelOnline, isMadkitPropertyTrue, isMessageBoxEmpty, isRole, killAgent, killAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchNode, launchXmlAgents, leaveGroup, leaveRole, nextMessage, nextMessage, nextMessages, proceedEnumMessage, purgeMailbox, receiveMessage, reload, requestRole, requestRole, sendMessage, sendMessage, sendMessageWithRole, sendMessageWithRole, sendReply, sendReplyWithRole, setLogLevel, setMadkitProperty, setMadkitProperty, setName, setupFrame
protected Color color
protected static Random generator
public Turtle(String initMethod)
public Turtle()
protected void activate()
activate
in class AbstractAgent
public void playRole(String role)
public void giveUpRole(String role)
public int getMinDirection(Pheromone p)
public int getMaxDirection(Pheromone p)
public void towardsMinGradientField(Pheromone p)
public void towardsMaxGradientField(Pheromone p)
public boolean isPlayingRole(String role)
role
- true
if the turtle is playing this rolepublic int get1DIndex()
public int get1DIndex(int x, int y)
public int getWorldWidth()
public int getWorldHeight()
public final void home()
public void setPatchColor(Color c)
public Color getPatchColor()
public Patch getNextPatch()
null
otherwisepublic float getFieldValue(Pheromone p)
public void randomLocation()
public Patch getPatchAt(int a, int b)
public Pheromone getPheromone(String name)
name
- the pheromone's nameTKEnvironment.getPheromone(String, int, int)
public Collection<Pheromone> getPheromones()
public double getPheroMinDirection(Pheromone phero)
name
- the pheromone's nameTKEnvironment.getPheromone(String, int, int)
public double getPheroMaxDirection(Pheromone phero)
name
- the pheromone's nameTKEnvironment.getPheromone(String, int, int)
public void setNextAction(String methodName)
public int mySelf()
AbstractAgent.hashCode()
return the turtle IDpublic String defaultBehavior()
public void incrementBehaviorCount()
public void setX(double a)
public void setY(double b)
public void setXY(double a, double b)
public int createTurtleHere(Turtle t)
t
- public int createTurtle(Turtle t, double x, double y)
t
- x
- y
- public int createTurtle(Turtle t)
t
- public int getID()
public int dx()
public int dy()
public void setColor(Color c)
public Color getColor()
public float smell(String pheromone)
public String toString()
toString
in class AbstractAgent
protected void emit(String pheromone, float value)
getPheromone(pheromone).incValue(xcor(), ycor(), value);
pheromone
- the name of the targeted pheromonevalue
- how much to droppublic int xcor()
public int ycor()
public void wiggle()
wiggle(45)
public void wiggle(int range)
public void randomHeading(int range)
range
- public void turnRight(double a)
public void turnLeft(double a)
public void setHeading(double direction)
public void fd(double nb)
nb
- number of space unitspublic void step()
public void moveTo(double a, double b)
public boolean isPatchChanged()
true
if the last move has changed
the patch the turtle is onpublic List<Turtle> getOtherTurtlesWithRole(int inRadius, boolean includeThisPatch, String role)
public <T extends Turtle> List<T> getOtherTurtlesWithRole(int inRadius, boolean includeThisPatch, String role, Class<T> turtleType)
public <T extends Turtle> List<T> getOtherTurtles(int inRadius, boolean includeThisPatch, Class<T> turtleType)
public Turtle getNearestTurtle(int inRadius)
inRadius
- null
there is no turtle around. In case of equality between
turtles (same patch distance or same patch), the first found is returned.public <T extends Turtle> T getNearestTurtle(int patchRadius, Class<T> turtleType)
patchRadius
- the side length of the square of patches
to look intonull
if
there is no turtle of this type around. In case of equality between
turtles (same patch distance or same patch), the first found is returned.public <T extends Turtle> T getNearestTurtleWithRole(int patchRadius, String role, Class<T> turtleType)
patchRadius
- the side length of the square of patches
to look intonull
if
there is no turtle of this type around. In case of equality between
turtles (same patch distance or same patch), the first found is returned.public Turtle getNearestTurtleWithRole(int patchRadius, String role)
patchRadius
- the side length of the square of patches
to look intonull
if
there is no turtle of this type around. In case of equality between
turtles (same patch distance or same patch), the first found is returned.public <T extends Turtle> T getNearestTurtle(double realRadius, Class<T> turtleType)
realRadius
- the maximum distance of the returned turtleturtleType
- the type of turtle to seeknull
if
there is no turtle of this type around. In case of equality between
turtles (same patch distance or same patch), the first found is returned.public void setHeadingTowardsNoWrap(Turtle t)
public void setHeadingTowards(Turtle t)
t
- a turtlepublic void setHeadingTowards(Turtle t, double offset)
t
- a turtleoffset
- the angle to add to the corresponding directionpublic double towards(Turtle t)
public double towardsNoWrap(Turtle t)
public double towardsNoWrap(double a, double b)
public double towards(double a, double b)
public double distanceNoWrap(double xCoordinate, double yCoordinate)
public double distance(double a, double b)
a
- the ab
- the bpublic double distance(Turtle t)
public final double normalizeX(double x)
x
- x-coordinatepublic final double normalizeY(double y)
y
- y-coordinatepublic final double normalizeX(int x)
x
- x-coordinatepublic final double normalizeY(int y)
y
- y-coordinatepublic double getHeading()
public float smellAt(String pheromoneName, int xOffset, int yOffset)
public float smellAt(Pheromone pheromone, int xOffset, int yOffset)
public Patch getPatch()
public void randomHeading()
public int getCurrentBehaviorCount()
public void setCurrentBehaviorCount(int i)
protected static TurtleKit executeThisTurtle(int nbOfInstances, String... args)
args
- MaDKit or TurtleKit optionsAbstractAgent.executeThisAgent(int, boolean, String...)
public TKEnvironment getEnvironment()
public double getX()
public double getY()
public String getCommunity()
public void setup()
activate()
should be overridden instead, beginning by super.activate();