diff --git a/data/scenarios/Challenges/_hackman/ghost.sw b/data/scenarios/Challenges/_hackman/ghost.sw index 9f01f351f..387515dc0 100644 --- a/data/scenarios/Challenges/_hackman/ghost.sw +++ b/data/scenarios/Challenges/_hackman/ghost.sw @@ -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 = @@ -138,7 +125,6 @@ def go = teleport self startPos; } { move; - checkNeedsTeleport 11; newDirection <- chooseDirection; turn newDirection; go; diff --git a/data/scenarios/Challenges/_hackman/solution.sw b/data/scenarios/Challenges/_hackman/solution.sw index 94b73e2b7..1242c01ec 100644 --- a/data/scenarios/Challenges/_hackman/solution.sw +++ b/data/scenarios/Challenges/_hackman/solution.sw @@ -126,7 +126,7 @@ def returnToCenter = end; def invadeDen = - doN 14 move; + doN 13 move; turn right; doN 2 move; turn left; diff --git a/data/scenarios/Challenges/_hackman/teleport_monitor.sw b/data/scenarios/Challenges/_hackman/teleport_monitor.sw new file mode 100644 index 000000000..84b5e637d --- /dev/null +++ b/data/scenarios/Challenges/_hackman/teleport_monitor.sw @@ -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; \ No newline at end of file diff --git a/data/scenarios/Challenges/_hackman/teleporter.sw b/data/scenarios/Challenges/_hackman/teleporter.sw deleted file mode 100644 index ef7b44104..000000000 --- a/data/scenarios/Challenges/_hackman/teleporter.sw +++ /dev/null @@ -1,41 +0,0 @@ -/* Algorithm: -If the player was previously on one side of me upon last inspection -and is now on top of me or on the other side, teleport them across -the map. -*/ - -def isBeyond = \func. - basePos <- as base { - whereami; - }; - return $ func $ fst basePos; - end; - -def observeAndTeleport = \criteriaFunc. \telporterPos. \wasExceeded. - currentlyExceeded <- isBeyond criteriaFunc; - - // Boundary was crossed - if (currentlyExceeded && not wasExceeded) { - teleport base (-(fst telporterPos), snd telporterPos); - create "bit (0)"; - } {}; - - observeAndTeleport criteriaFunc telporterPos currentlyExceeded; - end; - -def init = - telporterPos <- whereami; - let teleX = fst telporterPos in - let isWesternTeleporter = teleX < 0 in - - criteriaFunc <- if isWesternTeleporter { - return $ \baseX. baseX < teleX; - } { - return $ \baseX. baseX > teleX; - }; - - initiallyBeyond <- isBeyond criteriaFunc; - observeAndTeleport criteriaFunc telporterPos initiallyBeyond; - end; - -init; \ No newline at end of file diff --git a/data/scenarios/Challenges/hackman.yaml b/data/scenarios/Challenges/hackman.yaml index 1e3ca95cb..d5987d772 100644 --- a/data/scenarios/Challenges/hackman.yaml +++ b/data/scenarios/Challenges/hackman.yaml @@ -76,7 +76,7 @@ objectives: - | Be teleported condition: | - r <- robotnamed "teleporter"; + r <- robotnamed "teleport_monitor"; loc <- as r { has "bit (0)" }; @@ -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 @@ -272,10 +272,10 @@ 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] @@ -283,27 +283,50 @@ world: '┘': [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