Robots Docs
Fall 2025
API

# Nosebot

o1.robots.Nosebot
class Nosebot(`name`: String, `body`: RobotBody) extends RobotBrain

The class `Nosebot` represents the “brains” of robots that move in the direction their nose points, in straight lines, only turning when they have to. They always turn right.

## Parameters

body

  the robot body whose actions the nosebot brain will control

name

  the name of the nosebot

## Attributes

Graph
Supertypes
  trait RobotBrain
  class Object
  trait Matchable
  class Any

## Members list

### Value members

#### Concrete methods

def attemptMove(): Boolean

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

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

## Attributes

Returns

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

override def mayMove(`direction`: 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. Nosebots are careful: they consider every square that isn’t empty to be an obstacle. This behavior overrides the default implementation from class `RobotBrain`.

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.)

## Attributes

Definition Classes
  RobotBrain

def moveBody(): Unit

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. If the robot completes a 360-degree turnabout without finding a suitable square to move in, it ends its turn without changing location.

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. If 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 cannot move more than a single square per turn.

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

## Attributes

#### Inherited methods

def advanceCarefully(): Boolean

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.

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.

(Note: This method only moves the robot if the square in front of it is completely empty. This method does not call mayMove and is not affected by that other method’s implementation in any way.)

## Attributes

Returns

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

Inherited from:
  RobotBrain

def controlTurn(): Unit

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.

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.

## Attributes

Inherited from:
  RobotBrain

def facing: `CompassDir`

Returns the direction this robot is facing in.

Returns the direction this robot is facing in.

## Attributes

Inherited from:
  RobotBrain

def isStuck: Boolean

Determines whether 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 obstacles, as defined by the mayMove method. Only four squares are considered: the nearest square in each of the four main compass directions.

Determines whether 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 obstacles, as defined by the mayMove method. Only four squares are considered: the nearest square in each of the four main compass directions.

## Attributes

Inherited from:
  RobotBrain

def location: `GridPos`

Returns the coordinates of this robot within its robot world.

Returns the coordinates of this robot within its robot world.

## Attributes

Inherited from:
  RobotBrain

def locationInFront: `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.

## Attributes

Inherited from:
  RobotBrain

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_=("Suzy")` or simply with an assignment statement: `bot.name = "Suzy"`. You won’t find many uses for this in O1, but it’s nice to know nonetheless.

## Attributes

Inherited from:
  RobotBrain

def robotInFront: Option[RobotBrain]

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.

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.

## Attributes

Inherited from:
  RobotBrain

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.

## Attributes

Inherited from:
  RobotBrain

override 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).

## Attributes

Definition Classes
  RobotBrain -> Any
Inherited from:
  RobotBrain

def world: RobotWorld

Returns the world that this robot is located in.

Returns the world that this robot is located in.

## Attributes

Inherited from:
  RobotBrain