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.
- Alphabetic
- By Inheritance
- TribalBot
- 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
- def belongsTo(tribe: Tribe): Boolean
Determines whether this robot is a member of the given tribe.
- val body: RobotBody
- Definition Classes
- RobotBrain
- 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
- 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.
- 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
- 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
, orNone
if the robot is not a tribal bot. - 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.
- 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
, andNone
is returned if there is no robot in the square or if the robot that is there is a friend.- See also
- 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
- 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, andNone
is returned if there is no robot in the square or if the robot that is there is not a friend.- See also
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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).
- 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 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.
- 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.
- 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 longRadar: Vector[RobotBrain]
Returns the brains of all the robots in the same robot world with this one.
- 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
- TribalBot → RobotBrain
- 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:
- 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 methodexecute
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
- TribalBot → RobotBrain
- See also
- 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 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)
- 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 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.
- 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
- def seesFloor: Boolean
Determines whether the square immediately in front of the robot is an empty floor space.
- 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
- def seesWall: Boolean
Determines whether the square immediately in front of the robot is an unpassable obstacle.
- 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
- 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".)
- 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
- def slotValue(slotName: String): Int
Returns the contents of a named memory slot.
- 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
- 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
- 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
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
- 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
- val tribe: Tribe
- 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.