Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waypoints and portals #1356

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/scenarios/Testing/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
1234-push-command.yaml
1256-halt-command.yaml
1295-density-command.yaml
1138-structures
1138-structures
1356-portals
3 changes: 3 additions & 0 deletions data/scenarios/Testing/1356-portals/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
automatic-waypoint-patrol.yaml
portals-and-waypoints.yaml
portals-flip-and-rotate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
def abs = \n. if (n < 0) {-n} {n} end;

def mapTuple = \f. \t.
(f $ fst t, f $ snd t)
end;

def sumTuples = \t1. \t2.
(fst t1 + fst t2, snd t1 + snd t2);
end;

def negateTuple = \t.
mapTuple (\x. -x) t;
end;

def getRelativeLocation = \absCurrentLoc. \absDestLoc.
let negatedLoc = negateTuple absCurrentLoc in
return $ sumTuples negatedLoc absDestLoc;
end;

def moveTuple = \tup.
let x = fst tup in
let y = snd tup in
turn $ if (x > 0) {east} {west};
doN (abs x) move;
turn $ if (y > 0) {north} {south};
doN (abs y) move;
end;

def goToLocation = \currentLoc. \absoluteDestination.
relativeDestination <- getRelativeLocation currentLoc absoluteDestination;
moveTuple relativeDestination;
end;

def visitNextWaypoint = \nextWpIdx.
loc <- whereami;
nextWaypointQuery <- waypoint "wp" nextWpIdx;
goToLocation loc $ snd nextWaypointQuery;

visitNextWaypoint $ nextWpIdx + 1;
end;

def go =
waypointQuery <- waypoint "wp" 0;
teleport self $ snd waypointQuery;
visitNextWaypoint 1;
end;

go;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def abs = \n. if (n < 0) {-n} {n} end;

def mapTuple = \f. \t.
(f $ fst t, f $ snd t)
end;

def sumTuples = \t1. \t2.
(fst t1 + fst t2, snd t1 + snd t2);
end;

def negateTuple = \t.
mapTuple (\x. -x) t;
end;

def getRelativeLocation = \absCurrentLoc. \absDestLoc.
let negatedLoc = negateTuple absCurrentLoc in
return $ sumTuples negatedLoc absDestLoc;
end;

def moveTuple = \tup.
let x = fst tup in
let y = snd tup in
turn $ if (x > 0) {east} {west};
doN (abs x) move;
turn $ if (y > 0) {north} {south};
doN (abs y) move;
end;

def goToLocation = \currentLoc. \absoluteDestination.
relativeDestination <- getRelativeLocation currentLoc absoluteDestination;
moveTuple relativeDestination;
end;

def goToBottom =
turn south; doN 14 move;
end;

def go =
goToLocation (0, 0) (3, -2);
goToLocation (0, 0) (12, -2);
goToLocation (0, 0) (18, -5);
goToLocation (0, 0) (23, -3);

goToBottom;
goToLocation (0, -14) (3, -12);
goToBottom;
goToLocation (0, -14) (9, -9);
goToBottom;
goToLocation (0, -14) (18, -9);
goToBottom;
goToLocation (0, -14) (26, -10);

turn east;
doN 29 move;
goToBottom;
grab;
end;

go;
73 changes: 73 additions & 0 deletions data/scenarios/Testing/1356-portals/automatic-waypoint-patrol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
version: 1
name: Querying waypoints
description: |
Demonstrate patrolling between waypoints
creative: true
robots:
- name: base
loc: [0, 0]
dir: [1, 0]
- name: patroller
loc: [5, -4]
dir: [1, 0]
display:
invisible: false
attr: robot
program: |
run "scenarios/Testing/1356-portals/_automatic-waypoint-patrol/program.sw"
known: [flower, boulder]
world:
upperleft: [-1, 1]
default: [blank]
palette:
'.': [grass]
'*': [stone, flower]
'': [stone, upper left corner]
'': [stone, upper right corner]
'': [stone, lower left corner]
'': [stone, lower right corner]
'': [stone, horizontal wall]
'': [stone, vertical wall]
structures:
- name: bigbox
structure:
palette:
'.': [dirt]
'@': [dirt, boulder]
'w':
cell: [dirt]
waypoint:
name: wp
map: |
@@@
@w.
@.@
placements:
kostmo marked this conversation as resolved.
Show resolved Hide resolved
- src: bigbox
offset: [2, -2]
orient:
up: "DNorth"
- src: bigbox
offset: [8, -2]
orient:
up: "DEast"
- src: bigbox
offset: [8, -6]
orient:
up: "DSouth"
- src: bigbox
offset: [2, -6]
orient:
up: "DWest"
map: |
┌───────────┐
│*..*..*..*.│
│.*..*..*..*│
│..*..*..*..│
│*..*..*..*.│
│.*..*..*..*│
│..*..*..*..│
│*..*..*..*.│
│.*..*..*..*│
│..*..*..*..│
└───────────┘
115 changes: 115 additions & 0 deletions data/scenarios/Testing/1356-portals/portals-and-waypoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
version: 1
name: Waypoints for nested structures
description: |
Demonstrate behavior of waypoints across structure overlays
creative: true
attrs:
- name: portal_in
fg: "#ff9a00"
bg: "#ff5d00"
- name: portal_out
fg: "#00a2ff"
bg: "#0065ff"
entities:
- name: telepad entrance
display:
attr: portal_in
char: "o"
description:
- Portal entrance
properties: [known]
- name: telepad exit
display:
attr: portal_out
char: "o"
description:
- Portal exit
properties: [known]
robots:
- name: base
loc: [0, 4]
dir: [1, 0]
known: [tree, flower, sand, bit (0), bit (1)]
world:
upperleft: [-4, 7]
default: [blank]
palette:
'.': [grass]
'*': [stone, flower]
'P': [grass, telepad entrance]
'p': [grass, telepad exit]
'': [stone, upper left corner]
'': [stone, upper right corner]
'': [stone, lower left corner]
'': [stone, lower right corner]
'': [stone, horizontal wall]
'': [stone, vertical wall]
structures:
- name: bitpair
structure:
palette:
'p': [stone, telepad exit]
'1': [stone, bit (1)]
map: |
1
p
waypoints:
- name: bitpair_bottom
loc: [0, -1]
- name: minibox
structure:
palette:
'.': [stone]
's': [stone, sand]
'P': [stone, telepad entrance]
placements:
- src: bitpair
offset: [1, 0]
waypoints:
- name: minibox_corner
loc: [0, 0]
map: |
P.s
s.s
- name: bigbox
structure:
palette:
'.': [stone]
'T': [stone, tree]
'w':
cell: [dirt, telepad entrance]
waypoint:
name: bigbox_middle
map: |
TTTTTT
T.TwT.
.T.T.T
TTTTTT
placements:
- src: bigbox
offset: [1, -1]
- src: bigbox
offset: [7, -5]
- src: minibox
offset: [1, -7]
waypoints:
- name: meadow
loc: [12, -1]
portals:
- entrance: bigbox_middle
exitInfo:
exit: bitpair_bottom
- entrance: minibox_corner
exitInfo:
exit: meadow
map: |
┌────────────┐
│*..*..*..*.p│
│.*..*..*..*.│
│..*..*..*..*│
│*..*..*..*..│
│.*..*..*..*.│
│..*..*..*..*│
│*..*..*..*..│
│.*..*..*..*.│
└────────────┘
Loading