org.nlogo.agent
Class Turtle

java.lang.Object
  extended by java.util.Observable
      extended by org.nlogo.agent.Agent
          extended by org.nlogo.agent.Turtle
All Implemented Interfaces:
Comparable<Agent>, Agent, Turtle
Direct Known Subclasses:
Turtle3D

public class Turtle
extends Agent
implements Turtle


Field Summary
static int BIT
           
 int LAST_PREDEFINED_VAR
           
 int NUMBER_PREDEFINED_VARS
           
static String PEN_DOWN
           
static String PEN_ERASE
           
static String PEN_UP
           
static int VAR_COLOR
           
static int VAR_HEADING
           
static int VAR_LABEL
           
static int VAR_WHO
           
static int VAR_XCOR
           
static int VAR_YCOR
           
 
Fields inherited from class org.nlogo.agent.Agent
id, variables
 
Constructor Summary
Turtle(World world, AgentSet breed, Double xcor, Double ycor)
           
 
Method Summary
 Shape cachedShape()
           
 void cachedShape(Shape newShape)
           
 String classDisplayName()
          Returns a displayable name of this type of agent (Turtle, Link, Patch, Observer)
 Object color()
          Returns the value of the color variable
 void color(LogoList rgb, int varIndex)
           
 void colorDouble(Double boxedColor)
           
 void colorDoubleUnchecked(Double boxedColor)
           
 void die()
           
 double dx()
           
 double dy()
           
 void face(Agent agent, boolean wrap)
           
 void face(double x, double y, boolean wrap)
           
 int getAgentBit()
           
 Class<Turtle> getAgentClass()
           
 AgentSet getBreed()
          Returns the breed AgentSet of this turtle, all turtles if the turtle is unbreeded
 int getBreedIndex()
          Returns the index of this turtle's breed
 Object getBreedVariable(String name)
           
 Object getLinkBreedVariable(String name)
           
 Object getLinkVariable(int vn)
           
 Object getObserverVariable(int vn)
           
 Patch getPatchAtHeadingAndDistance(double delta, double distance)
           
 Patch getPatchAtOffsets(double dx, double dy)
           
 Patch getPatchHere()
          Returns the patch that this turtle is on
 Object getPatchVariable(int vn)
           
 Object getTurtleOrLinkVariable(String varName)
           
 Object getTurtleVariable(int vn)
           
 double getTurtleVariableDouble(int vn)
           
 Object getVariable(int vn)
          Returns the value of the variable in the given position of the agent variable array
 Object getVariable(String name)
           
 boolean hasLabel()
          Returns true if the label variable has a non-empty string value
 Turtle hatch()
           
 double heading()
          Returns the value of the heading variable
 void heading(double heading)
          Sets the value of the heading variable
 void heading(Double heading)
           
 void heading(double heading, Set<Turtle> seenTurtles)
           
 boolean hidden()
          Returns the value of the hidden?
 void hidden(boolean hidden)
           
 void home()
           
 void jump(double distance)
          Moves the turtle forward distance as if the command jump were used
 Object label()
           
 void label(Object label)
           
 Object labelColor()
          Returns the value of the label-color variable
 void labelColor(double labelColor)
           
 void labelColor(LogoList rgb, int valueIndex)
           
 String labelString()
          Returns the value of the label variable
 double lineThickness()
          Returns the line-thickness
 void moveTo(Agent otherAgent)
           
 void moveToPatchCenter()
           
 boolean ownsVariable(String name)
           
 String penMode()
           
 void penMode(String penMode)
           
 double penSize()
           
 void penSize(double penSize)
           
 void setBreed(AgentSet breed)
          This version of setBreed properly resets the global breed AgentSets Caller should ensure that the turtle isn't a link (links aren't allowed to change breed).
 void setBreedVariable(String name, Object value)
           
 void setLinkBreedVariable(String name, Object value)
           
 void setLinkVariable(int vn, double value)
           
 void setLinkVariable(int vn, Object value)
           
 void setObserverVariable(int vn, Object value)
           
 void setPatchVariable(int vn, double value)
           
 void setPatchVariable(int vn, Object value)
           
 void setTurtleOrLinkVariable(String varName, Object value)
           
 void setTurtleVariable(int vn, double value)
           
 void setTurtleVariable(int vn, Object value)
           
 void setVariable(int vn, Object value)
          Sets the variable in the position vn of the agent variable array to value
 String shape()
          Returns the name of the current shape, empty string in the case of patches.
 void shape(String shape)
           
 double shortestPathX(double x)
           
 double shortestPathY(double y)
           
 double size()
          Returns the size of this agent
 void size(double size)
           
static double subtractHeadings(double h1, double h2)
           
 String toString()
           
 void turnRight(double delta)
           
 void xandycor(double xcor, double ycor)
           
 void xandycor(Double xcor, Double ycor)
           
 void xandycor(double xcor, double ycor, Set<Turtle> seenTurtles)
           
 void xandycorHelper(double xcor, double ycor)
           
 double xcor()
          Returns the value of the xcor variable
 void xcor(double xcor)
           
 void xcor(Double xcor)
           
 double ycor()
          Returns the value of the ycor variable
 void ycor(double ycor)
           
 void ycor(Double ycor)
           
 
Methods inherited from class org.nlogo.agent.Agent
compareTo, getVariableCount, id, variableConstraint, variableConstraint, world
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.nlogo.api.Agent
id, world
 

Field Detail

VAR_WHO

public static final int VAR_WHO
See Also:
Constant Field Values

VAR_COLOR

public static final int VAR_COLOR
See Also:
Constant Field Values

VAR_HEADING

public static final int VAR_HEADING
See Also:
Constant Field Values

VAR_XCOR

public static final int VAR_XCOR
See Also:
Constant Field Values

VAR_YCOR

public static final int VAR_YCOR
See Also:
Constant Field Values

VAR_LABEL

public static final int VAR_LABEL
See Also:
Constant Field Values

LAST_PREDEFINED_VAR

public int LAST_PREDEFINED_VAR

NUMBER_PREDEFINED_VARS

public int NUMBER_PREDEFINED_VARS

PEN_UP

public static final String PEN_UP
See Also:
Constant Field Values

PEN_DOWN

public static final String PEN_DOWN
See Also:
Constant Field Values

PEN_ERASE

public static final String PEN_ERASE
See Also:
Constant Field Values

BIT

public static final int BIT
See Also:
Constant Field Values
Constructor Detail

Turtle

public Turtle(World world,
              AgentSet breed,
              Double xcor,
              Double ycor)
Method Detail

hatch

public Turtle hatch()

die

public void die()

lineThickness

public double lineThickness()
Description copied from interface: Turtle
Returns the line-thickness

Specified by:
lineThickness in interface Turtle

getPatchAtOffsets

public Patch getPatchAtOffsets(double dx,
                               double dy)
                        throws AgentException
Specified by:
getPatchAtOffsets in class Agent
Throws:
AgentException

jump

public void jump(double distance)
          throws AgentException
Description copied from interface: Turtle
Moves the turtle forward distance as if the command jump were used

Specified by:
jump in interface Turtle
Parameters:
distance - this amount to jump
Throws:
AgentException

getPatchAtHeadingAndDistance

public Patch getPatchAtHeadingAndDistance(double delta,
                                          double distance)
                                   throws AgentException
Throws:
AgentException

getPatchHere

public Patch getPatchHere()
Description copied from interface: Turtle
Returns the patch that this turtle is on

Specified by:
getPatchHere in interface Turtle

getVariable

public Object getVariable(int vn)
Description copied from interface: Agent
Returns the value of the variable in the given position of the agent variable array

Specified by:
getVariable in interface Agent
Specified by:
getVariable in class Agent
Parameters:
vn - the index into the agent variable array

setVariable

public void setVariable(int vn,
                        Object value)
                 throws AgentException
Description copied from interface: Agent
Sets the variable in the position vn of the agent variable array to value

Specified by:
setVariable in interface Agent
Specified by:
setVariable in class Agent
Parameters:
vn - the index into the agent variable array
value - the new value for the variable
Throws:
AgentException - If value is the wrong type for the given variable or if you try to change variables that cannot be changed

getObserverVariable

public Object getObserverVariable(int vn)
Specified by:
getObserverVariable in class Agent

getTurtleOrLinkVariable

public Object getTurtleOrLinkVariable(String varName)
Specified by:
getTurtleOrLinkVariable in class Agent

getTurtleVariable

public Object getTurtleVariable(int vn)
Specified by:
getTurtleVariable in class Agent

getTurtleVariableDouble

public double getTurtleVariableDouble(int vn)

getLinkBreedVariable

public Object getLinkBreedVariable(String name)
                            throws AgentException
Specified by:
getLinkBreedVariable in class Agent
Throws:
AgentException

getBreedVariable

public Object getBreedVariable(String name)
                        throws AgentException
Specified by:
getBreedVariable in class Agent
Throws:
AgentException

ownsVariable

public boolean ownsVariable(String name)

getVariable

public Object getVariable(String name)
                   throws AgentException
Throws:
AgentException

getLinkVariable

public Object getLinkVariable(int vn)
                       throws AgentException
Specified by:
getLinkVariable in class Agent
Throws:
AgentException

getPatchVariable

public Object getPatchVariable(int vn)
Specified by:
getPatchVariable in class Agent

setObserverVariable

public void setObserverVariable(int vn,
                                Object value)
                         throws AgentException,
                                LogoException
Specified by:
setObserverVariable in class Agent
Throws:
AgentException
LogoException

setTurtleOrLinkVariable

public void setTurtleOrLinkVariable(String varName,
                                    Object value)
                             throws AgentException
Specified by:
setTurtleOrLinkVariable in class Agent
Throws:
AgentException

setTurtleVariable

public void setTurtleVariable(int vn,
                              double value)
                       throws AgentException
Specified by:
setTurtleVariable in class Agent
Throws:
AgentException

setTurtleVariable

public void setTurtleVariable(int vn,
                              Object value)
                       throws AgentException
Specified by:
setTurtleVariable in class Agent
Throws:
AgentException

setBreedVariable

public void setBreedVariable(String name,
                             Object value)
                      throws AgentException
Specified by:
setBreedVariable in class Agent
Throws:
AgentException

setPatchVariable

public void setPatchVariable(int vn,
                             Object value)
                      throws AgentException
Specified by:
setPatchVariable in class Agent
Throws:
AgentException

setPatchVariable

public void setPatchVariable(int vn,
                             double value)
                      throws AgentException
Specified by:
setPatchVariable in class Agent
Throws:
AgentException

setLinkVariable

public void setLinkVariable(int vn,
                            Object value)
                     throws AgentException
Specified by:
setLinkVariable in class Agent
Throws:
AgentException

setLinkVariable

public void setLinkVariable(int vn,
                            double value)
                     throws AgentException
Specified by:
setLinkVariable in class Agent
Throws:
AgentException

setLinkBreedVariable

public void setLinkBreedVariable(String name,
                                 Object value)
                          throws AgentException
Specified by:
setLinkBreedVariable in class Agent
Throws:
AgentException

color

public Object color()
Description copied from interface: Turtle
Returns the value of the color variable

Specified by:
color in interface Turtle

colorDouble

public void colorDouble(Double boxedColor)

colorDoubleUnchecked

public void colorDoubleUnchecked(Double boxedColor)

color

public void color(LogoList rgb,
                  int varIndex)
           throws AgentException
Throws:
AgentException

turnRight

public void turnRight(double delta)

heading

public double heading()
Description copied from interface: Turtle
Returns the value of the heading variable

Specified by:
heading in interface Turtle

heading

public void heading(double heading)
Description copied from interface: Turtle
Sets the value of the heading variable

Specified by:
heading in interface Turtle
Parameters:
heading - the new heading

heading

public void heading(double heading,
                    Set<Turtle> seenTurtles)

heading

public void heading(Double heading)

moveTo

public void moveTo(Agent otherAgent)
            throws AgentException
Throws:
AgentException

shortestPathY

public double shortestPathY(double y)
                     throws AgentException
Throws:
AgentException

shortestPathX

public double shortestPathX(double x)
                     throws AgentException
Throws:
AgentException

xcor

public double xcor()
Description copied from interface: Turtle
Returns the value of the xcor variable

Specified by:
xcor in interface Turtle

xcor

public void xcor(double xcor)
          throws AgentException
Throws:
AgentException

xcor

public void xcor(Double xcor)
          throws AgentException
Throws:
AgentException

ycor

public double ycor()
Description copied from interface: Turtle
Returns the value of the ycor variable

Specified by:
ycor in interface Turtle

ycor

public void ycor(double ycor)
          throws AgentException
Throws:
AgentException

ycor

public void ycor(Double ycor)
          throws AgentException
Throws:
AgentException

xandycor

public void xandycor(double xcor,
                     double ycor)
              throws AgentException
Throws:
AgentException

xandycor

public void xandycor(double xcor,
                     double ycor,
                     Set<Turtle> seenTurtles)
              throws AgentException
Throws:
AgentException

xandycorHelper

public void xandycorHelper(double xcor,
                           double ycor)
                    throws AgentException
Throws:
AgentException

xandycor

public void xandycor(Double xcor,
                     Double ycor)
              throws AgentException
Throws:
AgentException

moveToPatchCenter

public void moveToPatchCenter()

face

public void face(Agent agent,
                 boolean wrap)

face

public void face(double x,
                 double y,
                 boolean wrap)

subtractHeadings

public static double subtractHeadings(double h1,
                                      double h2)

home

public void home()

dx

public double dx()

dy

public double dy()

shape

public String shape()
Description copied from interface: Agent
Returns the name of the current shape, empty string in the case of patches.

Specified by:
shape in interface Agent

shape

public void shape(String shape)

label

public Object label()

hasLabel

public boolean hasLabel()
Description copied from interface: Turtle
Returns true if the label variable has a non-empty string value

Specified by:
hasLabel in interface Turtle

labelString

public String labelString()
Description copied from interface: Turtle
Returns the value of the label variable

Specified by:
labelString in interface Turtle

label

public void label(Object label)

labelColor

public Object labelColor()
Description copied from interface: Turtle
Returns the value of the label-color variable

Specified by:
labelColor in interface Turtle

labelColor

public void labelColor(double labelColor)

labelColor

public void labelColor(LogoList rgb,
                       int valueIndex)
                throws AgentException
Throws:
AgentException

getBreed

public AgentSet getBreed()
Description copied from interface: Turtle
Returns the breed AgentSet of this turtle, all turtles if the turtle is unbreeded

Specified by:
getBreed in interface Turtle

getBreedIndex

public int getBreedIndex()
Description copied from interface: Turtle
Returns the index of this turtle's breed

Specified by:
getBreedIndex in interface Turtle

setBreed

public void setBreed(AgentSet breed)
This version of setBreed properly resets the global breed AgentSets Caller should ensure that the turtle isn't a link (links aren't allowed to change breed).


cachedShape

public Shape cachedShape()
Specified by:
cachedShape in interface Turtle

cachedShape

public void cachedShape(Shape newShape)
Specified by:
cachedShape in interface Turtle

hidden

public boolean hidden()
Description copied from interface: Turtle
Returns the value of the hidden? variable

Specified by:
hidden in interface Turtle

hidden

public void hidden(boolean hidden)

size

public double size()
Description copied from interface: Agent
Returns the size of this agent

Specified by:
size in interface Agent

size

public void size(double size)

penSize

public double penSize()

penSize

public void penSize(double penSize)

penMode

public String penMode()

penMode

public void penMode(String penMode)

toString

public String toString()
Overrides:
toString in class Object

classDisplayName

public String classDisplayName()
Description copied from interface: Agent
Returns a displayable name of this type of agent (Turtle, Link, Patch, Observer)

Specified by:
classDisplayName in interface Agent
Specified by:
classDisplayName in class Agent

getAgentClass

public Class<Turtle> getAgentClass()
Specified by:
getAgentClass in class Agent

getAgentBit

public int getAgentBit()
Specified by:
getAgentBit in class Agent