Package microsim.space.turtle
Class DigitalTurtle
java.lang.Object
microsim.space.SpacePosition
microsim.space.turtle.AbstractTurtle
microsim.space.turtle.DigitalTurtle
- All Implemented Interfaces:
Serializable,Comparable<SpacePosition>
TO DO Documentation.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class microsim.space.turtle.AbstractTurtle
AbstractTurtle.Direction, AbstractTurtle.MoveMode -
Field Summary
FieldsFields inherited from class microsim.space.turtle.AbstractTurtle
grid, movingFields inherited from class microsim.space.SpacePosition
x, y -
Constructor Summary
ConstructorsConstructorDescriptionCreate a turtle with a given identifier on the given grid at position (0,0).DigitalTurtle(ObjectSpace grid) Create a turtle with a given identifier on the given grid at position (0,0).DigitalTurtle(ObjectSpace grid, int x, int y) Create a turtle with a given identifier on the given grid at the given position. -
Method Summary
Modifier and TypeMethodDescriptionvoidforward(int steps) Make some steps forward, according the current heading.intReturn 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.voidRandomize the turtle's heading.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.AbstractTurtle
forward, getDistanceFrom, getGrid, getMovingType, getNextX, getNextY, getPosition, getWorldHeight, getWorldWidth, getX, getY, leap, setGrid, setIfEmptyXY, setMovingType, setX, setXY, setYMethods inherited from class microsim.space.SpacePosition
compareTo, equals, toString
-
Field Details
-
heading
-
-
Constructor Details
-
DigitalTurtle
public DigitalTurtle()Create a turtle with a given identifier on the given grid at position (0,0). -
DigitalTurtle
Create a turtle with a given identifier on the given grid at position (0,0).- Parameters:
grid- The grid upon the turtle moves.
-
DigitalTurtle
Create a turtle with a given identifier on the given grid at the given position.- Parameters:
x- The initial x coordinate of the turtle.y- The initial y coordinate of the turtle.grid- The grid upon the turtle moves.
-
-
Method Details
-
turnLeft
public void turnLeft(int degrees) Description copied from class:AbstractTurtleChange the current heading rotating it to the left.- Specified by:
turnLeftin classAbstractTurtle- Parameters:
degrees- The number of degrees to rotate the heading.
-
turnCardinalLeft
public void turnCardinalLeft(int steps) - Specified by:
turnCardinalLeftin classAbstractTurtle
-
setRandomHeading
public void setRandomHeading()Description copied from class:AbstractTurtleRandomize 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 classAbstractTurtle
-
getHeading
public int getHeading()Description copied from class:AbstractTurtleReturn the current heading of the turtle.- Specified by:
getHeadingin classAbstractTurtle- Returns:
- The current heading.
-
forward
public void forward(int steps) Description copied from class:AbstractTurtleMake some steps forward, according the current heading.- Specified by:
forwardin classAbstractTurtle- Parameters:
steps- The number of steps the turtle has to make.
-
leap
public boolean leap(int steps) Description copied from class:AbstractTurtleMake some steps forward, but moves only if the target position is empty.- Specified by:
leapin classAbstractTurtle- Parameters:
steps- The number of steps the turtle has to make.- Returns:
- True only if the turtle has moved.
-
turnRight
public void turnRight(int degrees) Description copied from class:AbstractTurtleChange the current heading rotating it to the right.- Specified by:
turnRightin classAbstractTurtle- Parameters:
degrees- The number of degrees to rotate the heading.
-
turnCardinalRight
public void turnCardinalRight(int steps) - Specified by:
turnCardinalRightin classAbstractTurtle
-
getNextX
public int getNextX(int steps) Description copied from class:AbstractTurtleReturn 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 classAbstractTurtle- Parameters:
steps- The number of steps to move forward.- Returns:
- The candidate x coordinate.
-
setHeading
public void setHeading(int heading) Description copied from class:AbstractTurtleSet the current heading.- Specified by:
setHeadingin classAbstractTurtle- Parameters:
heading- The new heading.
-
setCardinalHeading
Description copied from class:AbstractTurtleSet the turtle's heading using a constant for cardinal points.- Specified by:
setCardinalHeadingin classAbstractTurtle- Parameters:
directionType- One of DIR_NORTH, DIR_NORTH_EAST, ... constant.
-
getNextY
public int getNextY(int steps) Description copied from class:AbstractTurtleReturn 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 classAbstractTurtle- Parameters:
steps- The number of steps to move forward.- Returns:
- The candidate y coordinate.
-