Packages

c

o1.robots

RobotBrain

abstract class RobotBrain extends AnyRef

The class RobotBrain represents the "brains" (or artificial intelligence, AI) of virtual robots that inhabit two dimensional grid worlds. A robot brain is equipped with an algorithm for determining what a robot should do during its turn in a robot simulation. In other words, a robot brain is capable of controlling the actions of a robot body.

Concrete classes that extend this class need to provide implementations for the abstract moveBody method; each such concrete class can represent a new kind of robot behavior. Some subclasses are also expected to override the mayAdvance method.

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

Instance Constructors

  1. new RobotBrain(initialName: String, body: RobotBody)

    initialName

    the name of the robot

    body

    the body the robot brain will control

Abstract Value Members

  1. abstract def moveBody(): Unit

    Moves the robot: causes it to change its location, turn around, or whatever else the robot does during its turn.

    Moves the robot: causes it to change its location, turn around, or whatever else the robot does during its turn. What this means in practice depends on the type (subclass) of the robot brain.

    moveBody is called by the brain’s controlTurn method every time the robot brain gets a turn, unless the robot is stuck (as defined by isStuck).

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

Concrete 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

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. val body: RobotBody
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  8. 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.

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

    Returns the direction this robot is facing in.

  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. 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.

  16. def location: o1.GridPos

    Returns the location of this robot in its robot world.

  17. def locationInFront: grid.GridPos

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

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

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

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

  21. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  23. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  24. 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.

  25. def squareInFront: Square

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

  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. 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
  28. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  29. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  30. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. def world: RobotWorld

    Returns the world that this robot is located in.

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 AnyRef

Inherited from Any

Ungrouped