Package microsim.space.turtle
Class Turtle
- java.lang.Object
- 
- microsim.space.SpacePosition
- 
- microsim.space.turtle.AbstractTurtle
- 
- microsim.space.turtle.Turtle
 
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Comparable<SpacePosition>
 
 @MappedSuperclass public class Turtle extends AbstractTurtle An agent able to move itself upon an object grid. It has got some specific instruction for movement. Each turtle has an heading expressed in degrees. It can make steps, turn right or left, measure the distance from another position on the grid. Each turtle has a color and it is able to draw itself on a grid drawing layer.Title: JAS Description: Java Agent-based Simulation library Copyright (C) 2002 Michele Sonnessa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.- Author:
- Michele Sonnessa
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class microsim.space.turtle.AbstractTurtleAbstractTurtle.Direction, AbstractTurtle.MoveMode
 
- 
 - 
Constructor SummaryConstructors Constructor Description Turtle()Turtle(ObjectSpace grid)Create a turtle with a given identifier on the given grid at position (0,0).Turtle(ObjectSpace grid, int x, int y)Create a turtle with a given identifier on the given grid at the given position.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidforward(int steps)Make some steps forward, according the current heading.intgetHeading()Return the current heading of the turtle.intgetNextX(int steps)Return the new x coordinate walking the current heading direction for given steps.intgetNextY(int steps)Return the new y coordinate walking the current heading direction for given steps.booleanleap(int steps)Make some steps forward, but moves only if the target position is empty.voidsetCardinalHeading(AbstractTurtle.Direction directionType)Set the turtle's heading using a constant for cardinal points.voidsetHeading(int heading)Set the current heading.voidsetRandomHeading()Randomize the turtle's heading.voidsetXY(int x, int y)Set a new position.voidturnCardinalLeft(int steps)voidturnCardinalRight(int steps)voidturnLeft(int degrees)Change the current heading rotating it to the left.voidturnRight(int degrees)Change the current heading rotating it to the right.- 
Methods inherited from class microsim.space.turtle.AbstractTurtleforward, getDistanceFrom, getGrid, getMovingType, getNextX, getNextY, getPosition, getWorldHeight, getWorldWidth, getX, getY, leap, setGrid, setIfEmptyXY, setMovingType, setX, setY
 - 
Methods inherited from class microsim.space.SpacePositioncompareTo, equals, toString
 
- 
 
- 
- 
- 
Constructor Detail- 
Turtlepublic Turtle() 
 - 
Turtlepublic Turtle(ObjectSpace grid) Create a turtle with a given identifier on the given grid at position (0,0).- Parameters:
- id- The identifier for turtle.
- grid- The grid upon the turtle moves.
 
 - 
Turtlepublic Turtle(ObjectSpace grid, int x, int y) Create a turtle with a given identifier on the given grid at the given position.- Parameters:
- id- The identifier for turtle.
- x- The initial x coordinate of the turtle.
- y- The initial y coordinate of the turtle.
- grid- The grid upon the turtle moves.
 
 
- 
 - 
Method Detail- 
getHeadingpublic int getHeading() Description copied from class:AbstractTurtleReturn the current heading of the turtle.- Specified by:
- getHeadingin class- AbstractTurtle
- Returns:
- The current heading.
 
 - 
setRandomHeadingpublic void setRandomHeading() Randomize the turtle's heading. It gets a random number from 0 to 359 degrees. The random generator is synchronized with JAS randomizer.- Specified by:
- setRandomHeadingin class- AbstractTurtle
 
 - 
setCardinalHeadingpublic void setCardinalHeading(AbstractTurtle.Direction directionType) Set the turtle's heading using a constant for cardinal points.- Specified by:
- setCardinalHeadingin class- AbstractTurtle
- Parameters:
- directionType- One of DIR_NORTH, DIR_NORTH_EAST, ... constant.
 
 - 
setHeadingpublic void setHeading(int heading) Set the current heading.- Specified by:
- setHeadingin class- AbstractTurtle
- Parameters:
- heading- The new heading.
 
 - 
turnCardinalLeftpublic void turnCardinalLeft(int steps) - Specified by:
- turnCardinalLeftin class- AbstractTurtle
 
 - 
turnCardinalRightpublic void turnCardinalRight(int steps) - Specified by:
- turnCardinalRightin class- AbstractTurtle
 
 - 
turnRightpublic void turnRight(int degrees) Change the current heading rotating it to the right.- Specified by:
- turnRightin class- AbstractTurtle
- Parameters:
- degrees- The number of degrees to rotate the heading.
 
 - 
turnLeftpublic void turnLeft(int degrees) Change the current heading rotating it to the left.- Specified by:
- turnLeftin class- AbstractTurtle
- Parameters:
- degrees- The number of degrees to rotate the heading.
 
 - 
forwardpublic void forward(int steps) Make some steps forward, according the current heading.- Specified by:
- forwardin class- AbstractTurtle
- Parameters:
- steps- The number of steps the turtle has to make.
 
 - 
leappublic boolean leap(int steps) Make some steps forward, but moves only if the target position is empty.- Specified by:
- leapin class- AbstractTurtle
- Parameters:
- steps- The number of steps the turtle has to make.
- Returns:
- True only if the turtle has moved.
 
 - 
setXYpublic void setXY(int x, int y)Set a new position.- Overrides:
- setXYin class- AbstractTurtle
- Parameters:
- x- The new x coordinate.
- y- The new y coordinate.
 
 - 
getNextXpublic int getNextX(int steps) Return the new x coordinate walking the current heading direction for given steps. It uses the grid bound checking methods according to the turtle's current moving type.- Specified by:
- getNextXin class- AbstractTurtle
- Parameters:
- steps- The number of steps to move forward.
- Returns:
- The candidate x coordinate.
 
 - 
getNextYpublic int getNextY(int steps) Return the new y coordinate walking the current heading direction for given steps. It uses the grid bound checking methods according to the turtle's current moving type.- Specified by:
- getNextYin class- AbstractTurtle
- Parameters:
- steps- The number of steps to move forward.
- Returns:
- The candidate y coordinate.
 
 
- 
 
-