swarm-0.4: data/scenarios/Testing/956-GPS.yaml
version: 1
name: Test GPS receiver device
description: |
Test the `whereami` command and GPS receiver device.
https://github.com/swarm-game/swarm/issues/956
objectives:
- condition: |
loc <- as base {whereami};
return $ loc == (0,0)
goal:
- |
The goal is to move back to the origin after being
unceremoniously teleported to a random location. The only way
to do this is to use a GPS receiver device to learn the
current location and use the result to decide how to move.
solution: |
def x = \n. \c. if (n == 0) {} {c ; x (n-1) c} end;
def abs = \n. if (n<0) {-n} {n} end;
wait 2;
loc <- whereami;
turn (if (fst loc < 0) {east} {west}); x (abs (fst loc)) move;
turn (if (snd loc < 0) {north} {south}); x (abs (snd loc)) move;
robots:
- name: base
dir: [0,1]
loc: [-5,5]
devices:
- clock
- dictionary
- GPS receiver
- treads
- compass
- ADT calculator
- strange loop
- comparator
- calculator
- branch predictor
- logger
- name: teleporter
dir: [0,1]
loc: [0,0]
system: true
display:
invisible: true
program: |
x <- random 11;
y <- random 11;
teleport base (x-5, y-5)
world:
palette:
'.': [grass]
upperleft: [-5, 5]
map: |
...........
...........
...........
...........
...........
...........
...........
...........
...........
...........
...........