Packages

c

o1.robots

Nosebot

class Nosebot extends RobotBrain

The class Nosebot represents the "brains" (or AI) of robots that move in the direction their nose points, in straight lines, only turning when they have to. They always turn right.

Linear Supertypes
RobotBrain, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Nosebot
  2. RobotBrain
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Nosebot(name: String, body: RobotBody)

    name

    the name of the nosebot

    body

    the robot body whose actions the nosebot brain will control

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def advanceCarefully(): Boolean

    Moves the robot one square forwards, if there is nothing there.

    Moves the robot one square forwards, if there is nothing there. If that square isn’t empty, the robot does not move, so this method never causes a collision.

    returns

    true if the move was successful and the robot is now in the next square, false if it was blocked

    Definition Classes
    RobotBrain
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def attemptMove(): Boolean

    Attempts to move the robot one step forward in its current heading (as per advanceCarefully).

    Attempts to move the robot one step forward in its current heading (as per advanceCarefully). Failing that, turns the robot 90 degrees clockwise instead.

    returns

    true if the robot moved forward, false if the route was blocked and the robot turned instead

  7. val body: RobotBody
    Definition Classes
    RobotBrain
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  9. def controlTurn(): Unit

    Controls the robot body’s actions for a single turn.

    Controls the robot body’s actions for a single turn. If the brain considers the robot to be stuck (see isStuck), this method does nothing. If not stuck, the brain calls its own moveBody method, which carries out the actual robot actions.

    Definition Classes
    RobotBrain
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  12. def facing: o1.CompassDir

    Returns the direction this robot is facing in.

    Returns the direction this robot is facing in.

    Definition Classes
    RobotBrain
  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. def isStuck: Boolean

    Determines whether or not the robot brain considers the robot to be stuck.

    Determines whether or not the robot brain considers the robot to be stuck. A brain considers the robot stuck if and only if all the squares surrounding the robot contain unpassable obstacles, as defined by the mayAdvance method. Only the four nearest squares in the main compass directions are considered.

    Definition Classes
    RobotBrain
  17. def location: o1.GridPos

    Returns the location of this robot in its robot world.

    Returns the location of this robot in its robot world.

    Definition Classes
    RobotBrain
  18. def locationInFront: grid.GridPos

    Returns the coordinates that point at the square that is immediately in front of this robot.

    Returns the coordinates that point at the square that is immediately in front of this robot.

    Definition Classes
    RobotBrain
  19. def mayAdvance(direction: o1.CompassDir): Boolean

    Checks the square that neighbors the nosebot in the given direction to see if it contains something that the nosebot considers an obstacle.

    Checks the square that neighbors the nosebot in the given direction to see if it contains something that the nosebot considers an obstacle. Nosebots are careful: they consider every square that isn’t empty to be an obstacle. This behavior overrides the default implementation from class RobotBrain.

    (A consequence of this is that a nosebot will consider itself stuck unless there is at least one empty square next to it. See isStuck and controlTurn.)

    Definition Classes
    NosebotRobotBrain
  20. def moveBody(): Unit

    Moves the robot.

    Moves the robot. A nosebot first looks at the next square in the direction it is currently facing. If that square is empty, it moves there and ends its turn. If the square was not empty, the bot turns 90 degrees clockwise and immediately tries again (during the same turn): it again moves a step forward if possible, and turns to check the next direction if necessary. In case the robot completes a 360-degree turnabout without finding a suitable square to move in, it ends its turn without changing location.

    If other words, a nosebot uses its turn to call attemptMove up to four times.

    As a nosebot always looks where it's going, so it can never collide with anything during its own turn. A nosebot only ever moves a single square per turn.

    This method assumes that it is not called if the robot is broken or stuck.

    Definition Classes
    NosebotRobotBrain
  21. def name: String

    Returns the robot’s name.

    Returns the robot’s name. If the name has been set to the empty string or contains only whitespace, returns "Incognito" instead.

    Definition Classes
    RobotBrain
  22. def name_=(newName: String): Unit

    Changes the robot's name to the given one.

    Changes the robot's name to the given one.

    Note to students: In Scala, a method whose name ends in an underscore and an equals sign -- like this one's -- can be called using a special syntax. For instance, this method can be called either with the statement bot.name_=("Bob") or simply with an assignment statement: bot.name = "Bob". You won't find many uses for this in O1, but it's nice to know nonetheless.

    Definition Classes
    RobotBrain
  23. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  24. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  25. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. def robotInFront: Option[RobotBrain]

    Returns the brain of the robot immediately in front of this robot.

    Returns the brain of the robot immediately in front of this robot. The brain is returned in an Option wrapper; None is returned if there is no robot in that square or if the robot that is there has no brain.

    Definition Classes
    RobotBrain
  27. def squareInFront: Square

    Returns the square that is immediately in front of this robot.

    Returns the square that is immediately in front of this robot.

    Definition Classes
    RobotBrain
  28. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  29. def toString: String

    Returns a textual representation of the robot (which is the robot's name).

    Returns a textual representation of the robot (which is the robot's name).

    Definition Classes
    RobotBrain → AnyRef → Any
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  32. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  33. def world: RobotWorld

    Returns the world that this robot is located in.

    Returns the world that this robot is located in.

    Definition Classes
    RobotBrain

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from RobotBrain

Inherited from AnyRef

Inherited from Any

Ungrouped