Skip to content

Commit

Permalink
use built-in portal functionality for Hackman scenario (#1651)
Browse files Browse the repository at this point in the history
Previously, the logic to wrap horizontally was hand-coded, both for the player (using a dedicated monitor robot) and for ghosts (who, as system robots, implemented the teleportation themselves).

Now that we can use built-in portal functionality (#1356), no custom logic is needed to handle the teleportation.  A (much-simplified) monitor robot still observes the base robot to award the hidden "World wrap" goal.

## Demo

    scripts/play.sh -i data/scenarios/Challenges/hackman.yaml --autoplay --speed 6
  • Loading branch information
kostmo authored Nov 22, 2023
1 parent 3c970c1 commit 40f26df
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 83 deletions.
14 changes: 0 additions & 14 deletions data/scenarios/Challenges/_hackman/ghost.sw
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ def chooseDirection : cmd dir =
}
end;

// Ghosts must implement teleporting logic themselves.
// Hard-codes location of the teleporter.
def checkNeedsTeleport = \offset.
currentLoc <- whereami;
if (fst currentLoc < -offset) {
teleport self (offset, snd currentLoc)
} {
if (fst currentLoc > offset) {
teleport self (-offset, snd currentLoc)
} {}
}
end;

startPos <- whereami;

def go =
Expand All @@ -138,7 +125,6 @@ def go =
teleport self startPos;
} {
move;
checkNeedsTeleport 11;
newDirection <- chooseDirection;
turn newDirection;
go;
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Challenges/_hackman/solution.sw
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def returnToCenter =
end;

def invadeDen =
doN 14 move;
doN 13 move;
turn right;
doN 2 move;
turn left;
Expand Down
22 changes: 22 additions & 0 deletions data/scenarios/Challenges/_hackman/teleport_monitor.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Algorithm:
If, at any point, the base is more than two cells from its previous location,
it must have teleported.
*/

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

def getBasePos =
as base {whereami};
end;

def go = \lastBasePos.
wait 1;
curBasePos <- getBasePos;
let deltaX = abs(fst curBasePos - fst lastBasePos) in
if (deltaX > 1) {
create "bit (0)";
} {go curBasePos};
end;

curBasePos <- getBasePos;
go curBasePos;
41 changes: 0 additions & 41 deletions data/scenarios/Challenges/_hackman/teleporter.sw

This file was deleted.

77 changes: 50 additions & 27 deletions data/scenarios/Challenges/hackman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ objectives:
- |
Be teleported
condition: |
r <- robotnamed "teleporter";
r <- robotnamed "teleport_monitor";
loc <- as r {
has "bit (0)"
};
Expand Down Expand Up @@ -149,14 +149,14 @@ robots:
- strange loop
- treads
- workbench
- name: teleporter
- name: teleport_monitor
dir: [0, 1]
system: true
display:
invisible: true
char: 'T'
program: |
run "scenarios/Challenges/_hackman/teleporter.sw"
run "scenarios/Challenges/_hackman/teleport_monitor.sw"
- name: ghost1
dir: [0, 1]
system: true
Expand Down Expand Up @@ -272,38 +272,61 @@ world:
'b': [blank, null, ghost2]
'c': [blank, null, ghost3]
'd': [blank, null, ghost4]
'T': [blank, null, teleporter]
'.': [blank, pellet]
'*': [blank, donut]
'x': [blank, wall]
'T': [blank, null, teleport_monitor]
'=': [blank, gate]
'': [stone, upper left corner]
'': [stone, upper right corner]
'': [stone, lower left corner]
'': [stone, lower right corner]
'': [stone, horizontal wall]
'': [stone, vertical wall]
upperleft: [-11, 10]
'W':
cell: [blank]
waypoint:
name: western_exit
'X':
cell: [blank]
waypoint:
name: western_entrance
'Y':
cell: [blank]
waypoint:
name: eastern_exit
'Z':
cell: [blank]
waypoint:
name: eastern_entrance
portals:
- entrance: eastern_entrance
exitInfo:
exit: western_exit
- entrance: western_entrance
exitInfo:
exit: eastern_exit
upperleft: [-12, 10]
map: |-
xxxxxxxxxxxxxxxxxxxxxxx
x..........x..........x
x*xxx.xxxx.x.xxxx.xxx*x
x.xxx.xxxx.x.xxxx.xxx.x
x.....................x
x.xxx.x.xxxxxxx.x.xxx.x
x.....x....x....x.....x
xxxxx.xxxxBxBxxxx.xxxxx
BBBBx.xBBBBBBBBBx.xBBBB
xxxxx.xB┌──=──┐Bx.xxxxx
TBBBB.BB│abBcd│BB.BBBBT
xxxxx.xB└─────┘Bx.xxxxx
BBBBx.xBBBfΩBBBBx.xBBBB
xxxxx.xBxxxxxxxBx.xxxxx
x..........x..........x
x.xxx.xxxx.x.xxxx.xxx.x
x*..x.............x..*x
xxx.x.x.xxxxxxx.x.x.xxx
x.....x....x....x.....x
x.xxxxxxxx.x.xxxxxxxx.x
x.....................x
xxxxxxxxxxxxxxxxxxxxxxx
BxxxxxxxxxxxxxxxxxxxxxxxT
Bx..........x..........xB
Bx*xxx.xxxx.x.xxxx.xxx*xB
Bx.xxx.xxxx.x.xxxx.xxx.xB
Bx.....................xB
Bx.xxx.x.xxxxxxx.x.xxx.xB
Bx.....x....x....x.....xB
Bxxxxx.xxxxBxBxxxx.xxxxxB
BBBBBx.xBBBBBBBBBx.xBBBBB
Bxxxxx.xB┌──=──┐Bx.xxxxxB
ZYBBBB.BB│abBcd│BB.BBBBWX
Bxxxxx.xB└─────┘Bx.xxxxxB
BBBBBx.xBBBfΩBBBBx.xBBBBB
Bxxxxx.xBxxxxxxxBx.xxxxxB
Bx..........x..........xB
Bx.xxx.xxxx.x.xxxx.xxx.xB
Bx*..x.............x..*xB
Bxxx.x.x.xxxxxxx.x.x.xxxB
Bx.....x....x....x.....xB
Bx.xxxxxxxx.x.xxxxxxxx.xB
Bx.....................xB
BxxxxxxxxxxxxxxxxxxxxxxxB

0 comments on commit 40f26df

Please sign in to comment.