Robots Docs
Fall 2025
API

# Slaybot

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

The class `Slaybot` represents the “brains” of robots which stand still until they see another unbroken robot. When this happens, they ram the victim with incredible speed.

## Parameters

body

  the robot body whose actions the slaybot brain will control

name

  the name of the slaybot

## Attributes

Graph
Supertypes
  trait RobotBrain
  class Object
  trait Matchable
  class Any

## Members list

### Value members

#### Concrete methods

def moveBody(): Unit

Moves the robot. During its turn, a slaybot scans the four main compass directions, always starting with north and continuing clockwise until it finds a victim or has scanned all four directions without finding one. (The slaybot does not change facing while scanning.)

Moves the robot. During its turn, a slaybot scans the four main compass directions, always starting with north and continuing clockwise until it finds a victim or has scanned all four directions without finding one. (The slaybot does not change facing while scanning.)

To scan a direction, the slaybot first examines the neighboring square in that direction, then the next square in the same direction, and so forth, until it arrives at a non-empty square. If that square has an intact robot, the slaybot has found a victim; if there is no intect robot there, the slaybot has failed to find a victim in that compass direction and switches to the next compass direction.

When the slaybot notices an intact robot, it turns to face it, instantly moves an unlimited number of squares towards the robot, and rams into it, causing the victim to break. After the collision, the slaybot remains in the square adjacent to its victim, and stops scanning for the rest of the turn.

If there are no victims in any of the four main directions, the slaybot waits still. During its next turn, it will start over by scanning northward; this is not affected by whether the slaybot found a victim this turn.

Slaybots do not attack broken robots. A slaybot can not scan through walls, and it can never collide with a wall. It also does not see through robots, not even broken ones.

## 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 mayMove(`direction`: `CompassDir`): Boolean

Checks the square that neighbors this robot in the given direction to see if it contains something that the robot brain considers an obstacle. This method is abstract; different kinds of robot brains will have different definitions of what counts as an obstacle.

Checks the square that neighbors this robot in the given direction to see if it contains something that the robot brain considers an obstacle. This method is abstract; different kinds of robot brains will have different definitions of what counts as an obstacle.

This default implementation (which may be overriden by subtypes) does not consider anything to be an obstacle. Robots that rely on this default implementation are willing to move in any direction and never consider themselves to be stuck (see isStuck).

## 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