SPEEDING UP YOUR ROBOT
by Richard Fowell
An understanding of how the robot battle is actually handled by the
Robotwar program can help you improve your robot. By observing
robots on the test bench, we have deduced the following rules.
During a battle, the program cycles through the robots. It executes
your robot's assembled instructions one at a time, until it has
executed ten instructions, or has executed a statement which is a
GOTO, GOSUB, or refers to the X, Y, SPEEDX, SPEEDY, DAMAGE, RADAR,
RANDOM, AIM or SHOT registers. The program then updates your robot's
position and goes on to the next robot. When it returns to yours, it
continues where it left off.
The lesson here is that one should avoid unnecessary GOTOs, GOSUBs,
references to X, Y, etc.
Example: consider this code segment:
AIM +5 TO AIM ; SWIVEL GUN BARREL.
AIM TO RADAR ; LOOK DOWN BARREL.
IF RADAR <0 ; IF ROBOT SEEN,
0 -RADAR TO SHOT ; SHOOT IT.
By using registers A and R to store the gun angle and the range,
one can avoid "losing one's turn" so often.
Thus: A + 5 TO A ; PREPARE TO SWIVEL GUN
A TO AIM ; SWIVEL GUN
A TO RADAR ; SIGHT ALONG BARREL
RADAR TO R ; STORE RANGE
IF R <0 ; IF ROBOT SEEN,
0-R TO SHOT ; SHOOT IT.
The first example takes 7 turns to complete. The second takes only
4. Incidentally, the gun barrel takes nine turns to cool down after
firing. The distance a robot moves in one turn is SPEEDX/50
horizontally and SPEEDY/50 vertically.
Space can be saved by remembering that your robot is an
ACCUMULATOR-BASED machine. The most obvious consequence is that one
can string "TO" statements together. Hence:
A + 5 TO A TO AIM TO RADAR ; SWIVEL GUN AND LOOK
can replace the first three lines of the second example. The manual
discussion of the assembled statements and tests shows that "IFs" are
meaningless--comparisons test the accumulator without changing its
value. So the last three lines of the second example becomes:
0 - RADAR > 0 TO SHOT ; IF ROBOT, SHOOT.
The final version takes 4 turns to complete.
A + 5 TO A TO AIM TO RADAR
0 - RADAR > 0 TO SHOT