2013-08-20 16:21:09 +00:00
|
|
|
(ns robotwar.source-programs)
|
2013-08-10 02:01:56 +00:00
|
|
|
|
2013-08-14 03:50:12 +00:00
|
|
|
(def programs
|
|
|
|
{:multi-use
|
2013-08-10 02:01:56 +00:00
|
|
|
" START
|
|
|
|
0 TO A
|
|
|
|
TEST
|
|
|
|
IF A > 2 GOTO START
|
|
|
|
GOSUB INCREMENT
|
|
|
|
GOTO TEST
|
|
|
|
100 TO A
|
|
|
|
INCREMENT
|
|
|
|
A + 1 TO A
|
|
|
|
ENDSUB
|
2013-08-14 03:50:12 +00:00
|
|
|
200 TO A "
|
|
|
|
|
|
|
|
:index-data
|
2013-08-10 02:01:56 +00:00
|
|
|
; to test the INDEX/DATA pair of registers
|
|
|
|
" 300 TO A
|
|
|
|
1 TO INDEX
|
2013-08-14 03:50:12 +00:00
|
|
|
DATA TO B"
|
|
|
|
|
|
|
|
:random
|
2013-08-10 02:01:56 +00:00
|
|
|
; to test the RANDOM register
|
|
|
|
" 1000 TO RANDOM
|
|
|
|
RANDOM TO A
|
|
|
|
RANDOM TO A
|
|
|
|
RANDOM TO A
|
|
|
|
RANDOM TO A
|
2013-08-14 03:50:12 +00:00
|
|
|
RANDOM TO A "
|
|
|
|
|
|
|
|
:speedy
|
|
|
|
" 140 TO SPEEDX
|
|
|
|
250 TO SPEEDY "
|
2013-08-12 20:20:45 +00:00
|
|
|
|
2013-08-24 01:23:01 +00:00
|
|
|
:mover
|
2013-08-15 20:20:11 +00:00
|
|
|
"
|
|
|
|
; Note: # means !=
|
|
|
|
|
2013-08-20 18:32:15 +00:00
|
|
|
360 TO RANDOM
|
|
|
|
RANDOM TO AIM ; Set a random direction to aim the gun
|
|
|
|
|
2013-08-15 20:20:11 +00:00
|
|
|
256 TO RANDOM ; All random numbers will now have as their maximum
|
|
|
|
; the width and height of the arena (in meters).
|
2013-08-14 03:50:12 +00:00
|
|
|
|
|
|
|
LOOP
|
2013-08-22 18:50:27 +00:00
|
|
|
0 TO SPEEDX ; STOP THE ROBOT!
|
|
|
|
0 TO SPEEDY
|
2013-08-15 20:20:11 +00:00
|
|
|
RANDOM TO A ; Store a random X-coordinate in the arena.
|
|
|
|
RANDOM TO B ; Store a random Y-coordinate in the arena.
|
2013-08-14 03:50:12 +00:00
|
|
|
|
|
|
|
MOVE
|
2013-08-22 18:50:27 +00:00
|
|
|
AIM + 5 TO AIM
|
2013-08-16 22:09:44 +00:00
|
|
|
IF A # X GOSUB MOVEX ; If we're moving in the X direction, recalibrate SPEEDX.
|
|
|
|
TO N ; N is for no-op. (needed because there's no ELSE command).
|
|
|
|
IF B # Y GOSUB MOVEY ; If we're moving in the Y direction, recalibrate SPEEDY.
|
2013-08-15 20:20:11 +00:00
|
|
|
IF A = X GOTO LOOP ; A = X and B = Y, so we've stopped moving, so start over.
|
|
|
|
GOTO MOVE ; Continue to move.
|
2013-08-14 03:50:12 +00:00
|
|
|
|
|
|
|
MOVEX
|
2013-08-16 22:09:44 +00:00
|
|
|
A - X TO SPEEDX ; Take distance from destination in meters and use
|
2013-08-15 20:20:11 +00:00
|
|
|
; it to set SPEEDX, which is measured in decimeters/second.
|
2013-08-14 03:50:12 +00:00
|
|
|
ENDSUB
|
|
|
|
|
|
|
|
MOVEY
|
2013-08-16 22:09:44 +00:00
|
|
|
B - Y TO SPEEDY ; Take distance from destination in meters and use
|
2013-08-15 20:20:11 +00:00
|
|
|
; it to set SPEEDY, which is measured in decimeters/second.
|
2013-08-21 23:33:01 +00:00
|
|
|
ENDSUB "
|
2013-08-22 18:50:27 +00:00
|
|
|
|
2013-08-24 01:23:01 +00:00
|
|
|
:left-shooter
|
2013-08-22 18:50:27 +00:00
|
|
|
"
|
|
|
|
; Note: # means !=
|
|
|
|
|
|
|
|
90 TO AIM ; Set the gun to shoot right
|
|
|
|
|
|
|
|
15 TO A ; Set the coordinates for the left side.
|
|
|
|
128 TO B
|
|
|
|
|
|
|
|
MOVE
|
|
|
|
IF A # X GOSUB MOVEX ; If we're moving in the X direction, recalibrate SPEEDX.
|
|
|
|
TO N ; N is for no-op. (needed because there's no ELSE command).
|
|
|
|
IF B # Y GOSUB MOVEY ; If we're moving in the Y direction, recalibrate SPEEDY.
|
|
|
|
IF A = X GOTO SHOOT ; A = X and B = Y, so we've stopped moving, so shoot.
|
|
|
|
GOTO MOVE ; Continue to move.
|
|
|
|
|
|
|
|
MOVEX
|
|
|
|
A - X TO SPEEDX ; Take distance from destination in meters and use
|
|
|
|
; it to set SPEEDX, which is measured in decimeters/second.
|
|
|
|
ENDSUB
|
|
|
|
|
|
|
|
MOVEY
|
|
|
|
B - Y TO SPEEDY ; Take distance from destination in meters and use
|
|
|
|
; it to set SPEEDY, which is measured in decimeters/second.
|
|
|
|
ENDSUB
|
|
|
|
|
|
|
|
SHOOT
|
|
|
|
200 TO SHOT
|
|
|
|
GOTO MOVE "
|
|
|
|
|
2013-08-24 04:55:09 +00:00
|
|
|
:top-shooter
|
2013-08-22 18:50:27 +00:00
|
|
|
"
|
|
|
|
; Note: # means !=
|
|
|
|
|
|
|
|
180 TO AIM ; Set the gun to shoot down
|
|
|
|
|
|
|
|
128 TO A ; Set the coordinates for the top.
|
|
|
|
15 TO B
|
|
|
|
|
|
|
|
MOVE
|
|
|
|
IF A # X GOSUB MOVEX ; If we're moving in the X direction, recalibrate SPEEDX.
|
|
|
|
TO N ; N is for no-op. (needed because there's no ELSE command).
|
|
|
|
IF B # Y GOSUB MOVEY ; If we're moving in the Y direction, recalibrate SPEEDY.
|
|
|
|
IF A = X GOTO SHOOT ; A = X and B = Y, so we've stopped moving, so shoot.
|
|
|
|
GOTO MOVE ; Continue to move.
|
|
|
|
|
|
|
|
MOVEX
|
|
|
|
A - X TO SPEEDX ; Take distance from destination in meters and use
|
|
|
|
; it to set SPEEDX, which is measured in decimeters/second.
|
|
|
|
ENDSUB
|
|
|
|
|
|
|
|
MOVEY
|
|
|
|
B - Y TO SPEEDY ; Take distance from destination in meters and use
|
|
|
|
; it to set SPEEDY, which is measured in decimeters/second.
|
|
|
|
ENDSUB
|
|
|
|
|
|
|
|
SHOOT
|
|
|
|
200 TO SHOT
|
|
|
|
GOTO MOVE "
|
|
|
|
|
2013-08-21 23:33:01 +00:00
|
|
|
:shooter
|
|
|
|
"
|
|
|
|
90 TO AIM
|
2013-08-22 01:47:07 +00:00
|
|
|
200 - Y TO S
|
2013-08-21 23:33:01 +00:00
|
|
|
SHOOT
|
2013-08-22 01:46:47 +00:00
|
|
|
S TO SHOT
|
2013-08-21 23:33:01 +00:00
|
|
|
GOTO SHOOT "
|
|
|
|
})
|