RobotWarDoc.tioga
Eric Nickell, July 6, 1985 3:06:50 pm PDT
ROBOT WAR
CEDAR 6.0 — FOR INTERNAL XEROX USE ONLY
Robot War
Creative time-wasting in the Cedar environment
Eric Nickell
© Copyright 1985 Xerox Corporation. All rights reserved.
Abstract: RobotWar is a game, simulating a battle between two programmable robots.
Created by: Eric Nickell
Maintained by: Eric <Nickell.pasa>
Keywords: Game, Robot, Assembler
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
1. Introduction
Two robots are placed in an arena, armed with a laser, mobility, the ability to sense the other's presence, and a small, programmable computer. This implementation is based largely on a game of the same name found on CDC's PlatoTM system.
The robot's computer consists of an ALU and a 256 word memory, each word being 16 bits. The first 16 locations are special locations, including the accumulator, index register, stack pointer, program counter, registers containing the location and damage of the robot and its opponent, and locations which, when written to, set the direction and speed of the robot, and cause the laser to fire.
The direction to turn, and the direction to fire are measured from 0 to 256, where 128=p, and 256=2p.
The robot can move 0, 1, 2, or 3 meters per turn, by storing some value in the speed register. There is a specific opcode to perform this store (or one can do it manually.) Speeds outside the range [-3..3] will cause the robot to move at maximum speed either forward (if the value was positive) or in reverse (if negative). A robot is a meter wide. The arena is 100 meters square. A robot's location may be anywhere in the arena, but can only determine its position to the nearest meter gridmark.
Robot programs (in the robot assembler language) can be created using Tioga, and should have the extension ".robot". The robot assembler will compile these into a file with extension ".robotC". The df file should contain a couple example robots, as well as a couple assembled robots. The sections below describe the RobotTool (in which the competitions take place), the RobotWorkBench (for testing robots), and the assembler
2. RobotTool
Bringover -p /Cedar/CedarChest6.0/Top/RobotWar.df. Then, in your favorite subdirectory, type `RobotTool' into a CommandTool. A Robot War tool should appear on the left side of the display. Enter the names of two robots, like `SlowLineUp', and `Target', and then bug go. The tool will assemble the robots if necessary, and start the competition. Bugging "Stop!" will end the battle. (Useful for inert robots.)
A log is kept throughout the competition, recording each time a robot is hit (1 unit of damage), or bumps a wall (2 units of damage). A robot dies when it sustains 5 units of damage. The numbers in parentheses are the number of compute cycles since the beginning of the competition.
3. RobotWorkBench
Sigh. There is as yet no workbench. Debug your robots by hook, by crook, and by magic, please. Or ask questions.
4. Robot Assembler
The following sections describe the syntax of the assembler, the format for instructions, the opcodes available and their semantics
Grammar
module ::= line ...
line ::= label
| assignment ;
| statement ;
| expression ;
assignment ::=id ← expression
label ::=id :
statement ::=opcode ?# expression ?^ ?(,I)
expression ::= IF condition THEN expression ELSE expression
| expression infix expression
| id
 | number

| ( expression )
| [ statement ]
infix ::= MOD | + | - | * | /
condition ::= condition ( OR | AND ) condition
|( ~ | NOT ) condition
| expression relop expression
relop ::= < | > | = | <= | >= | ~=
Instructions
Instructions have the following form to the assembler:
instruction ::= opcode ?# tag ?^ ?, I
tag ::= expression
The opcode is the operation that will occur, and the tag (along with the three possible modifiers) identify the data to be operated. Note that tag is just an expression that (at assembly) evaluates to an integer in the range [0..256). Roughly, the three modifiers are
# Immediate value — the tag is not an address
^ Indirect — the contents of the tag are used as an address
, I Index — pick the Ith element out of the table at tag
These modifiers may be used in combination. A detailed explanation of the complete desugaring for this notation may be found later in this document. For example,
foobar: LDI #3 --Load a 3 into the index register
LDA 3 --Load the contents of address location 3 into the accumulator
ADD 3^ --Add the contents of the location pointed to by
   --address location 3 into the accumulator
bar: JMP #foobar --Continue execution at assembler label `foobar'
JMP foo --Continue execution at assembler label `bar'
foo: bar
FIR Theta,I--Fire at angle which is ith element of table Theta
TRN PhiTab^,I--Turn to angle, ith element of table pointed to by PhiTab
OpCodes
OpCodeDescription  Desugaring
LDA Load accumulator  ac ← cont
STA Store accumulator  addr^ ← ac
BAZ Branch if ac zero  pc ← IF ac=0 THEN cont ELSE pc+1
BAL Branch if ac < 0  pc ← IF ac<0 THEN cont ELSE pc+1
BAG Branch if ac > 0  pc ← IF ac>0 THEN cont ELSE pc+1
BAN Branch if ac non-zero pc ← IF ac~=0 THEN cont ELSE pc+1
LDA Load index register  ac ← cont
STA Store index register  addr^ ← I
BIZ Branch if I zero  pc ← IF I=0 THEN cont ELSE pc+1
BIL Branch if I < 0  pc ← IF I<0 THEN cont ELSE pc+1
BIG Branch if I > 0  pc ← IF I>0 THEN cont ELSE pc+1
BIN Branch if I non-zero  pc ← IF I~=0 THEN cont ELSE pc+1
JMP Jump to new code  pc ← cont
LUP Dec ind and loop if >= 0 II -1; pc ← IF I>=0 THEN pc+1 ELSE cont
ADD Add to accumulator  ac ← ac + cont
SUB Subtract from accumulator ac ← ac - cont
MUL Multiply by accumulator ac ← ac * cont
SHF Shift accumulator left ac ← ac * 2cont--Bits lost off left or right
FRM Subtract accumulator from ac ← cont - ac
FIR Fire laser   Fire ← cont --And fire it!
TRN Face specified direction Direction ← cont --Doesn't affect speed
SPD Set speed   Speed ← cont
Memory Layout
0 AC Accumulator
1 I Index Register
2 STK Stack Pointer
3 PC Instruction Pointer
4 HX Enemy ordinate
5 MX Own ordinate
6 HY Enemy abcissa
7 MY Own abcissa
8 HDMG Enemy damage
9 MDMG Own damage
10  Currently unused
11 DOWN Address to increment each cycle
12 UP Address to decrement each cycle
13 DIRECT Direction to travel
14 FIRE Direction to fire
15 SPEED Current speed
Instruction Format
Current encoding (and therefore decoding) scheme:
#^Ioooootttttttt, where
#  is the immediate bit
^  is the indirect bit
I  is the index bit
ooooo  is the opcode number
tttttttt  is the tag