Repository navigation
Examples
Adam Clements edited this page Oct 19, 2016
·
6 revisions
# A robot which flips between its starting location
# and 10,-10 squares to the northeast
LET dest
LET orig
# Store original position
GetPos
PopTo orig
# Calculate a new position 10,-10 to the northeast
PushFrom orig
VecAdd (10,10)
PopTo dest
# Now start trying to get to one then back to the other
# in a loop
to-dest:
GetPos
PushFrom dest
JumpEq to-orig
# Still here? Mustn't be there yet, try moving
# then loop back
SetColour 0xff0000
PushFrom dest
MoveTo
Jump to-dest
to-orig:
GetPos
PushFrom orig
JumpEq to-dest
# Still here? Mustn't be there yet, try moving
# then loop back
SetColour 0x00ff00
PushFrom orig
MoveTo
Jump to-orig
# This bot moves randomly
CONST TICKS-TO-CHANGE 10 # How many ticks to wait before changing
# direction
change-direction:
Random 11
Random 11
VecComp
VecSub (5, 5) # Get a random vector between (-5, -5
GetPos
VecAdd # Make it relative to my position
MoveTo # Go there
Push 0 #Initialise the wait count
start:
Add 1 # Increment the wait counter
Clone # Keep a copy for the next loop
Push TICKS-TO-CHANGE
JumpLt start # Jump if waited < TICKS-TO-CHANGE
Pop # Get rid of the counter off the stack
Jump change-direction
LET msgbuffer[3] 0 0 0
CONST OFFSET_ID 0
CONST OFFSET_MAGIC 1
CONST OFFSET_TARGET 2
# Listen for messages on channel 12
MessageSetChannel 12
## Messaging loop, check for new orders
start:
MessageRead msgbuffer 3
JumpZero start
PushFrom msgbuffer[OFFSET_ID]
GetId
JumpNe start
PushFrom msgbuffer[OFFSET_MAGIC]
Push 432 # Magic password number
JumpNe start
move:
PushFrom msgbuffer[OFFSET_TARGET]
MoveTo
Jump start