Class DigitalTurtle

All Implemented Interfaces:
Serializable, Comparable<SpacePosition>

@MappedSuperclass public class DigitalTurtle extends AbstractTurtle
See Also:
  • Field Details

  • Constructor Details

    • DigitalTurtle

      public DigitalTurtle()
      Create a turtle at position (0,0).
    • DigitalTurtle

      public DigitalTurtle(@NonNull @NonNull ObjectSpace grid)
      Create a turtle on the given grid at position (0,0).
      Parameters:
      grid - The grid upon the turtle moves.
    • DigitalTurtle

      public DigitalTurtle(@NonNull @NonNull ObjectSpace grid, int x, int y)
      Create a turtle 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: AbstractTurtle
      Changes the current heading rotating it to the left.
      Specified by:
      turnLeft in class AbstractTurtle
      Parameters:
      degrees - The number of degrees to rotate the heading.
    • turnCardinalLeft

      public void turnCardinalLeft(int steps)
      Specified by:
      turnCardinalLeft in class AbstractTurtle
    • setRandomHeading

      public void setRandomHeading()
      Description copied from class: AbstractTurtle
      Randomizes the turtle's heading. It gets a random number from 0 to 359 degrees. The random generator is synchronized with JAS randomizer.
      Specified by:
      setRandomHeading in class AbstractTurtle
    • getHeading

      public int getHeading()
      Description copied from class: AbstractTurtle
      Returns the current heading of the turtle.
      Specified by:
      getHeading in class AbstractTurtle
      Returns:
      The current heading.
    • setHeading

      public void setHeading(int heading)
      Description copied from class: AbstractTurtle
      Sets the current heading.
      Specified by:
      setHeading in class AbstractTurtle
      Parameters:
      heading - The new heading.
    • forward

      public void forward(int steps)
      Description copied from class: AbstractTurtle
      Makes some steps forward, according the current heading.
      Specified by:
      forward in class AbstractTurtle
      Parameters:
      steps - The number of steps the turtle has to make.
    • leap

      public boolean leap(int steps)
      Description copied from class: AbstractTurtle
      Makes some steps forward, but moves only if the target position is empty.
      Specified by:
      leap in class AbstractTurtle
      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: AbstractTurtle
      Changes the current heading rotating it to the right.
      Specified by:
      turnRight in class AbstractTurtle
      Parameters:
      degrees - The number of degrees to rotate the heading.
    • turnCardinalRight

      public void turnCardinalRight(int steps)
      Specified by:
      turnCardinalRight in class AbstractTurtle
    • getNextX

      public int getNextX(int steps)
      Description copied from class: AbstractTurtle
      Returns 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:
      getNextX in class AbstractTurtle
      Parameters:
      steps - The number of steps to move forward.
      Returns:
      The candidate x coordinate.
    • setCardinalHeading

      public void setCardinalHeading(@NonNull @NonNull AbstractTurtle.Direction directionType)
      Description copied from class: AbstractTurtle
      Sets the turtle's heading using a constant for cardinal points.
      Specified by:
      setCardinalHeading in class AbstractTurtle
      Parameters:
      directionType - One of DIR_NORTH, DIR_NORTH_EAST, ... constant.
    • getNextY

      public int getNextY(int steps)
      Description copied from class: AbstractTurtle
      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:
      getNextY in class AbstractTurtle
      Parameters:
      steps - The number of steps to move forward.
      Returns:
      The candidate y coordinate.