This page contains pieces of code that could be useful when making robots
of your own. Please email me
any pieces of code that could go here.
I'm not sure if all of these work properly, but at least it's better
than nothing! Obviously, changes will need to be made before they will
work so at least some experience in ATRA is required...
; Zero-cycle JMPs
jeq 10 ; Takes 0 cycles \ same as JMP
jne 10 ; Takes 0 cycles / (JMP takes 1 cycle)
; Shoots in a wavey line
opo 15
opo 15, 1
opo 15, -1
; Shoots if not too hot
#def maxheat
#def curheat
mov maxheat, 300 ; heat = max heat to fire with
ipo 2, curheat ; find current heat level
cmp curheat, maxheat ; compare current heat and max heat
jge 10 ; if heat => max heat then don't fire
[FIRE SUB]
:10
; Rotates turret depending on position of target
#def accuracy
mov accuracy, @3 ; accuracy = accuracy of last scan
cmp accuracy, 0 ; compare accuracy to 0
jls 10 ; accuracy < 0 go to 10
jgr 20 ; accuracy > 0 go to 20
jmp 30 ; jump to 30
:10
opo 12, -1 ; rotate turret 1 degree to left
jmp 30 ; jump to 30
:20
opo 12, 1 ; rotate turret 1 degree to right
jmp 30 ; jump to 30
:30
OR
opo 12, @3 ; Rotates turret to accuracy of
; last scan
OR
#def acc
ipo 8, acc ; get accuracy
shl acc, 1 ; acc = acc * 2
opo 12, acc ; rotate turret depending on accuracy
(thanks to Tycho for this last one!)
; Goes somewhere if close to wall
#def nearness
#def max
#def min
mov nearness, 100 ; nearness = max nearness to wall
mov max, 1000
sub max, nearness ; max = 1000 - nearness
mov min, nearness ; min = nearness
int 2 ; fx & ex = position
cmp ex, max ;
jge 10 ; jump to 10 if ex => max
cmp fx, max ;
jge 20 ; jump to 20 if fx => max
cmp ex, min ;
jle 30 ; jump to 30 if ex <= min
cmp fx, min ;
jle 40 ; jump to 40 if fx <= min
jmp 50 ; jump to 50
:10
[NEAR EAST WALL]
jmp 50 ; jump to 50
:20
[NEAR SOUTH WALL]
jmp 50 ; jump to 50
:30
[NEAR WEST WALL]
jmp 50 ; jump to 50
:40
[NEAR NORTH WALL]
jmp 50 ; jump to 50
:50
; Reverse direction if collision occurs
#def collisions
#def speed
mov collisions, @8 ; collisions = number of collisions
cmp collisions, 0 ; compare collisions to 0
jne 10 ; jump to 10 it collisions <> 0
jmp 20
:10
mov @8, 0 ; collisions = 0
mov speed, @0 ; speed = desired speed
neg speed ; reverse speed
opo 11, speed ; change throttle
:20
|