active trapdoor demo (#976)

Towards #1088
![image](https://github.com/swarm-game/swarm/assets/261693/c48bd24b-23b8-4165-8670-c105301f04c4)
This commit is contained in:
Karl Ostmo 2023-06-17 16:11:08 -07:00 committed by GitHub
parent adcb2c75fc
commit 8b46979abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 0 deletions

View File

@ -7,3 +7,4 @@ Fun
Speedruns
Testing
Vignettes
Mechanics

View File

@ -0,0 +1 @@
active-trapdoor.yaml

View File

@ -0,0 +1,31 @@
/**
This mechanic operates by polling.
Note that the polling is not naturally "throttled" since
the 'whereami' command is intangible (has zero duration).
So we insert 'wait' commands to be performance-friendly.
*/
def waitAndGate = \myCoords. \armed.
basePos <- as base {whereami};
if (basePos == myCoords) {
if armed {} {
// Warn the player that they have tripped the trap
say "ka-chunk"
};
// The trapdoor is now armed. Wait to spring it.
wait 1; // Throttle the polling
waitAndGate myCoords true;
} {
if (armed) {
place "boulder";
// recursion ends
} {
// Wait to arm the trapdoor
wait 1; // Throttle the polling
waitAndGate myCoords false
};
};
end;
myPos <- whereami;
waitAndGate myPos false;

View File

@ -0,0 +1,4 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
doN 10 move;
grab;

View File

@ -0,0 +1,81 @@
version: 1
name: Active trapdoor
author: Karl Ostmo
description: |
This gate closes once you have passed.
This is an "active" trapdoor in the sense that a system robot
continuously monitors its status and operates it.
It is in contrast with a sokoban-style trapdoor
that is "passive" in its operation.
creative: false
objectives:
- goal:
- Grab the flower.
condition: |
as base {has "flower"}
robots:
- name: base
display:
char: 'ω'
attr: robot
dir: [0, 1]
devices:
- treads
- 3D printer
- ADT calculator
- branch predictor
- clock
- comparator
- counter
- dictionary
- grabber
- hearing aid
- lambda
- logger
- mirror
- net
- scanner
- strange loop
- string
- workbench
inventory:
- [1, treads]
- name: gate
system: true
dir: [0, 1]
display:
invisible: true
inventory:
- [1, boulder]
program: |
run "scenarios/Mechanics/_active-trapdoor/gate.sw"
solution: |
run "scenarios/Mechanics/_active-trapdoor/solution.sw"
known: [water, boulder, flower]
seed: 0
world:
default: [stone, water]
upperleft: [0, 0]
offset: false
palette:
'@': [stone, boulder]
'.': [grass]
G: [stone, null, gate]
Ω: [grass, null, base]
f: [grass, flower]
map: |
.....
..f..
.....
@@.@@
.@.@.
.@.@.
.@G@.
.@.@.
.@.@.
@@.@@
.....
..Ω..
.....

View File

@ -217,6 +217,10 @@ testScenarioSolution _ci _em =
, testSolution Default "Challenges/Sokoban/Gadgets/one-way.yaml"
, testSolution Default "Challenges/Sokoban/Simple/trapdoor.yaml"
]
, testGroup
"Mechanics"
[ testSolution Default "Mechanics/active-trapdoor.yaml"
]
]
, testGroup
"Regression tests"