Packages

c

o1.robots.tribal

TribalBot

class TribalBot extends RobotBrain

The class TribalBot represents the “brains” of robots that belong to a “robot tribe” and behave according to the rules of that tribe. Tribal robots consider other tribal robots of the same tribe their friends and all other robots their enemies.

A tribal robot is capable of attacking enemies and thereby converting them to their own tribe. As a consequence, tribes can be quite aggressive as they compete for survival in a robot world.

Robot Actions

Each tribal robot is capable of doing one (but only one) of the following things during its turn:

  • Moving one square forward into an empty floor space.
  • Spinning 90 degrees without moving.
  • Spinning 180 degrees without moving.
  • Attacking --- “hacking” --- an enemy robot immediately in front of it. (See below.)

Hacking is automatic whenever a tribal robot sees an enemy, but how a tribal robot moves about and spins depends on its tribe. Each tribe has its own program, written in the RoboSpeak language. All members of the tribe follow this program, which defines the sequences of actions that those robots take. See the documentation of class Tribe for details about RoboSpeak.

Hacking

A tribal robot starts its turn by looking at whether there is an enemy robot in front of it. An enemy robot is any robot that is not a member of the same tribe. If there is an enemy robot in the square right in front of the acting tribal bot, then the tribal bot attacks it by "hacking". Hacking is a kind of brainwashing: it converts the enemy robot into a member of the acting robot's tribe. The victim will begin executing its new tribe's RoboSpeak program from a line determined by the hacking robot.

Memory

Each tribal bot has some limited memory resources available, which it draws on when it executes the tribe's RoboSpeak program. A tribal bot remembers the following information:

  • Where it is: a tribal bot knows which robot body it is controlling, just like any other RobotBrain does, and can therefore determine its location and facing.
  • Where its allegiances lie: a tribal bot knows which tribe it belongs to.
  • What it's supposed to do next: a tribal bot knows which instruction in its tribe's RoboSpeak program it is supposed to execute next once it gets its next turn. (This allows the tribal bot to save the program position it is at when it ends a turn. It can later resume program execution where it left off the previous turn.)
  • Which way it's turning: A tribal bot remembers if it's supposed to be turning clockwise or counterclockwise when it next makes a turn.
  • Which subprogram calls have been made: A tribal bot has a call stack where it stores frames representing calls to RoboSpeak subprograms. Each such frame is represented by a Frame object. This enables the tribal bot to execute subprograms and return to the correct line in the tribe's RoboSpeak program whenever the end of a subprogram is reached.
  • The contents of four memory slots (or “registers”) called mem, mem2, radar and hackline. The mem and mem2 slots can be used for any purpose. The intended use of radar is to store the readings produced by the robot's radar. The hackline slot is meant for configuring hacked robots. See the text below and class Tribe for more details.

Sensors

A tribal bot is (only) capable of seeing the single square directly in front of it. It can determine what there is in that square, but no further.

A tribal bot also has a radar that it can use either short-range to determine how many enemies or friends are located within exactly two steps of the acting robot, or long-range to count the memberships of entire tribes in the robot world. Again, more details can be found in the documentation for class Tribe.

Initial state

When a tribal bot is created, it starts executing its tribal program from the beginning (unless otherwise specified by a hacking robot). Its call stack is initially empty, its memory slots all contain the value 1, and it is considered to be turning clockwise.

As a new tribal bot brain “plugs into” a robot body, it changes the robot's name. Each new member of a tribe receives a new, rather impersonal name of the form "Tribe#number", e.g., "Tiger#123". The ID number that comes after the hash (#) is unique for every member of a tribe.

See also

Tribe

Frame

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

Instance Constructors

  1. new TribalBot(body: RobotBody, tribe: Tribe)

    body

    the robot body that the tribal bot brain will control

    tribe

    the tribe that this brain belongs to

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 belongsTo(tribe: Tribe): Boolean

    Determines whether this robot is a member of the given tribe.

  7. val body: RobotBody
    Definition Classes
    RobotBrain
  8. def boot(startLine: Int): Unit

    Resets the robot's state.

    Resets the robot's state. All the robot's memory slots are set to the initial value of 1. When it next gets a turn, the robot starts executing its tribal program from the given line onwards with an empty call stack.

    startLine

    a line number in the robot's tribe's RoboSpeak program; the robot will execute the instruction on this line next

  9. def callSubprogram(callingLine: Int): Unit

    Starts the execution of a subprogram.

    Starts the execution of a subprogram. That is to say, creates a new stack frame and places ("pushes") it on top of the robot's call stack.

    callingLine

    the line number of the call site. This number is to be stored on the stack so that program execution can resume at the correct location once the robot returns from the subprogram.

  10. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  11. 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
  12. def determineTribe(another: RobotBrain): Option[Tribe]

    Determines the tribe of a robot.

    Determines the tribe of a robot. Returns the tribe of the given robot wrapped in an Option, or None if the robot is not a tribal bot.

  13. def directedRadar(dirNumber: Int): Vector[RobotBrain]

    Returns the brains of all the robots near this one in a specific direction.

    Returns the brains of all the robots near this one in a specific direction. More specifically, if D is the target direction and S is the square right next to this brain in direction D, this method returns all the robot brains that are either in S or right next to S (orthogonally, not diagonally). That list will always include this robot brain itself. (A total of one to five robot brains will thus be returned.)

    dirNumber

    a number between 0 and 3 that indicates the target direction relative to this robot's current facing: 0 means the direction the robot is now facing; 1 means 90 degrees clockwise from that facing; 2 means the direction behind the robot, and 3 means 90 degrees counterclockwise from the facing.

  14. def enemyInFront: Option[RobotBrain]

    Returns the brains of the enemy robot immediately in front of this robot, if there is one.

    Returns the brains of the enemy robot immediately in front of this robot, if there is one. Any robot that is not a friend is an enemy. The brains are wrapped in an Option, and None is returned if there is no robot in the square or if the robot that is there is a friend.

    See also

    isFriend

  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  17. def facing: o1.CompassDir

    Returns the direction this robot is facing in.

    Returns the direction this robot is facing in.

    Definition Classes
    RobotBrain
  18. def friendInFront: Option[TribalBot]

    Returns the brains of the friendly robot immediately in front of this robot, if there is one.

    Returns the brains of the friendly robot immediately in front of this robot, if there is one. The brains returned in an Option wrapper, and None is returned if there is no robot in the square or if the robot that is there is not a friend.

    See also

    isFriend

  19. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. def hack(): Unit

    "Brainwashes" an enemy robot that is currently right in front of the acting robot, assuming there is one there.

    "Brainwashes" an enemy robot that is currently right in front of the acting robot, assuming there is one there. The victim of the hack will receive a new tribal bot brain of the enemy tribe, which replaces its old brain. Consequently, it will receive a new name and will start behaving differently than before.

    When its next turn comes, the victim will start executing the tribal RoboSpeak program of the attacker's tribe, using its fresh brain. Anything that the victim's old brain had in memory (stack frames, memory slot values, etc.) is lost; the victim is now considered to be turning clockwise.

    The victim will start executing its new RoboSpeak program from the line indicated by the hacking robot's hackline memory slot. The default value for this memory slot is 1, so unless the hacking robot's tribal program specifies otherwise, the victim starts from the first line of RoboSpeak. (See the description of RoboSpeak in class Tribe for more details about how to affect hackline.)

    If there is no enemy in front of the acting robot, this method does nothing.

    See also

    enemyInFront

  21. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  22. def isFriend(robot: RobotBrain): Boolean

    Determines if the given robot is a friend of this robot.

    Determines if the given robot is a friend of this robot. That is, determines if the given robot is a tribal robot of the same tribe (but is not this robot itself).

  23. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  24. 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
  25. def isThreatenedBy(robot: RobotBrain): Boolean

    Determines whether this robot considers the given robot to be a threat.

    Determines whether this robot considers the given robot to be a threat. A tribal bot considers all members of all non-pacifist tribes except its own to be threats. Non-tribal bots are never considered to be threats.

  26. def isThreatenedBy(tribe: Tribe): Boolean

    Determines whether this robot considers the given robot tribe a threat.

    Determines whether this robot considers the given robot tribe a threat. A tribal bot considers all non-pacifist tribes threats except its own.

  27. 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
  28. 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
  29. def longRadar: Vector[RobotBrain]

    Returns the brains of all the robots in the same robot world with this one.

  30. def mayAdvance(direction: o1.CompassDir): Boolean

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

    Checks the the square that neighbors the tribal bot in the given direction to see if it contains something that the bot considers an obstacle. To tribal bots, walls are obstacles but other robots aren’t. This behavior overrides the default implementation from class RobotBrain.

    Definition Classes
    TribalBotRobotBrain
  31. def moveBody(): Unit

    A tribal robot prioritizes hacking: if there is an enemy present directly in front, the acting bot spends its turn hacking it.

    A tribal robot prioritizes hacking: if there is an enemy present directly in front, the acting bot spends its turn hacking it. (Exception: there are "pacifist" tribes that don't hack.)

    If no enemy is present, or if the tribal bot is a pacifist, the bot executes its tribe's RoboSpeak program until it performs one of the actions that end its turn (or at least tries to perform such an action).

    Essentially, this method is responsible for the tribal bot's equivalent of a fetch-execute cycle during the robot's turns. This involves these two steps:

    1. Execute an instruction.

    2. Fetch the instruction that is to be executed next.

    The cycle is repeated until the robot's turn is over. The turn is over when the robot executes one of the instructions that ends its turn or when the end of the tribe's program is reached.

    Instructions are represented by Instruction objects. The tribal bot object's job is made easy by the fact that the method execute in class Instruction not only executes the instruction (Step 1 above), but also returns the instruction that is to be executed next (Step 2 above).

    Unless otherwise specified, a robot will resume execution where it left off the previous turn.

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

    Definition Classes
    TribalBotRobotBrain
    See also

    Instruction

  32. 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
  33. 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
  34. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  35. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  36. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  37. def returnFromSubprogram(): Int

    Ends the execution of a subprogram.

    Ends the execution of a subprogram. This means that the topmost stack frame is removed ("popped") from the robot's call stack.

    This method fails with an IllegalStateException in case there are no frames on the stack.

    returns

    a line number that indicates where the subprogram call (whose execution ended) had been called from (and where execution should therefore resume)

  38. 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
  39. def seesAsFodder(robot: RobotBrain): Boolean

    Determines whether this robot considers the given robot to be "fodder", that is, an unthreatening resource.

    Determines whether this robot considers the given robot to be "fodder", that is, an unthreatening resource. A tribal bot never sees itself as fodder, but does see all other pacifist robots (including ones from its own tribe if it's a pacifist) as fodder. All non-tribal bots are considered fodder by all tribal bots.

  40. def seesEnemy: Boolean

    Determines whether the square immediately in front of the robot contains an enemy robot.

    Determines whether the square immediately in front of the robot contains an enemy robot.

    See also

    enemyInFront

  41. def seesFloor: Boolean

    Determines whether the square immediately in front of the robot is an empty floor space.

  42. def seesFriend: Boolean

    Determines whether the square immediately in front of the robot contains an friendly robot.

    Determines whether the square immediately in front of the robot contains an friendly robot.

    See also

    friendInFront

  43. def seesWall: Boolean

    Determines whether the square immediately in front of the robot is an unpassable obstacle.

  44. def setSlotValue(slotName: String, newValue: Int): Map[String, Int]

    Sets the contents of a named memory slot.

    Sets the contents of a named memory slot. The new value replaces the old value stored in the slot

  45. def shortRadar: Vector[RobotBrain]

    Returns the brains of all the robots within two steps of this one.

    Returns the brains of all the robots within two steps of this one. (See Tribe for a definition of "steps".)

  46. def shout(lineNumber: Int): Unit

    "Shouts" to all friendly robots nearby.

    "Shouts" to all friendly robots nearby. The message reaches all the friendly robots that are within the robot’s short radar: this is equivalent to talking to each of those other robots.

    lineNumber

    a new line number for the recipients (see talk)

    See also

    shortRadar, isFriend, talk

  47. def slotValue(slotName: String): Int

    Returns the contents of a named memory slot.

  48. def spin(): Unit

    Spins the robot 90 degrees in whichever direction it is currently turning.

    Spins the robot 90 degrees in whichever direction it is currently turning.

    See also

    switchDirection

  49. 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
  50. def switchDirection(): Unit

    Switches the spinning direction of the tribal bot.

    Switches the spinning direction of the tribal bot. If it was previously set to turn clockwise, it now turns counterclockwise, and vice versa. This method does not actually turn the robot, it only affects future spins.

    See also

    spin

  51. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  52. def talk(lineNumber: Int): Unit

    "Talks" to a friendly robot that is currently right in front of the acting robot, if there is a friendly robot there.

    "Talks" to a friendly robot that is currently right in front of the acting robot, if there is a friendly robot there. In practice, this means that the talking robot gives an order to its friendly "listener", causing the listener to move to the given line number in the two robots' shared tribal program. The listener is "rebooted" and starts at the given line number with a clean slate, as if it had just been created.

    If there is no friendly robot in front of the acting robot, this method does nothing.

    lineNumber

    a line number referencing the RoboSpeak program of the two friends' shared tribe

    See also

    isFriend

  53. 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
  54. val tribe: Tribe
  55. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  56. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  57. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  58. 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