class Lovebot extends RobotBrain
The class Lovebot
represents the "brains" (or AI) of robots which have another
robot as their "beloved". A lovebot tries to home in on its beloved.
- Alphabetic
- By Inheritance
- Lovebot
- RobotBrain
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- val beloved: RobotBody
- val body: RobotBody
- Definition Classes
- RobotBrain
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- 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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def facing: o1.CompassDir
Returns the direction this robot is facing in.
Returns the direction this robot is facing in.
- Definition Classes
- RobotBrain
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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
- 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
- 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
- def mayAdvance(direction: o1.CompassDir): Boolean
Checks the the square that neighbors this robot in the given direction to see if it contains something that the robot brain considers an obstacle.
Checks the 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 subclasses) 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).
- Definition Classes
- RobotBrain
- def moveBody(): Unit
Moves the robot.
Moves the robot. A lovebot tries to home in on its beloved unless it already is in an adjacent square (diagonally adjacent is not good enough). The lovebot blindly follows its primitive urges and doesn't know how to avoid obstacles. If there is a wall or another bot in the chosen direction, the lovebot will collide with it (as per the
moveTowards
method of its body, possibly colliding and breaking itself or another robot).The path of movement is chosen as follows. First the lovebot calculates its distance to its target in both the x and y dimensions. It moves one square at a time so that either the horizontal (x) or the vertical (y) distance decreases by one, choosing the one that is greater. In case the distances are equal, the horizontal distance is chosen. The lovebot only moves one square per turn. It turns to face the direction it attempts to move in, even if that attempt fails because of a collision. The bot does not turn or move if it is already close enough to its beloved.
This method assumes that it is called only if the robot is not broken or stuck.
- Definition Classes
- Lovebot → RobotBrain
- 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
- 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
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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
- 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
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- 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
- 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.