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

Use surveil in move tutorial #2064

Merged
merged 9 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
228 changes: 158 additions & 70 deletions data/scenarios/Tutorials/move.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,33 @@ world:
'Z': [blank, null, 3P flower]
# FIRST ROOM
'┌': [blank, upper left corner]
'┐': [blank, upper right corner, 1S down and horizontal wall]
'┐': [blank, upper right corner, 1S down and horizontal]
'└': [blank, lower left corner]
'┘': [blank, lower right corner, 1S up and horizontal wall]
'┘': [blank, lower right corner, 1S up and horizontal]
'─': [blank, horizontal wall]
'│': [blank, vertical wall]
# SECOND ROOM
'1': [blank, vertical wall, 1G]
'-': [blank, null, 1P horizontal wall]
'|': [blank, null, 1P vertical wall]
'c': [blank, null, 1P upper right corner, 2S left and vertical wall]
'-': [blank, null, 1P horizontal]
'|': [blank, null, 1P vertical]
'c': [blank, null, 1P upper right, 1S left and vertical]
'b': [blank, null, 1P lower right corner]
'd': [blank, null, 1P horizontal wall, 2S up and horizontal wall]
'd': [blank, null, 1P horizontal, 2S up and horizontal]
# THIRD ROOM
'2': [blank, null, 1P horizontal wall, 2G]
'~': [blank, null, 2P horizontal wall]
'/': [blank, null, 2P vertical wall]
'R': [blank, null, 2P upper right corner]
'L': [blank, null, 2P upper left corner, 3S down and horizontal wall]
'K': [blank, null, 2P vertical wall, 3S left and vertical wall]
'2': [blank, null, 1P horizontal, 2G]
'~': [blank, null, 2P horizontal]
'/': [blank, null, 2P vertical]
'R': [blank, null, 2P upper right]
'L': [blank, null, 2P upper left, 3S down and horizontal]
'K': [blank, null, 2P vertical, 3S left and vertical]
# FOURTH ROOM
'3': [blank, null, 2P vertical wall, 3G]
'_': [blank, null, 3P horizontal wall]
'\': [blank, null, 3P vertical wall]
'A': [blank, null, 3P lower left corner]
'3': [blank, null, 2P vertical, 3G]
'_': [blank, null, 3P horizontal]
'\': [blank, null, 3P vertical]
'A': [blank, null, 2P lower left corner]
xsebek marked this conversation as resolved.
Show resolved Hide resolved
'B': [blank, null, 3P lower right corner]
'C': [blank, null, 3P upper right corner]
'D': [blank, null, 3P upper left corner]
'C': [blank, null, 3P upper right]
'D': [blank, null, 3P upper left]
upperleft: [-1, 9]
map: |
D_________C
Expand All @@ -132,6 +132,7 @@ world:
# ███████ ██ █ ██ ███████ ██████ ██ ████ ██
# ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██
# ███████ ███ ███ ██ ██ ██ ██ ██ ██
stepsPerTick: 1000
robots:
- name: base
dir: east
Expand Down Expand Up @@ -198,109 +199,184 @@ robots:
#################
## HORIZONTAL ##
#################
- name: 1P horizontal wall
- name: 1P horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P horizontal wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="horizontal wall", room=1]);
m
- name: 2P horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P horizontal wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="horizontal wall", room=2]);
m
- name: 3P horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="horizontal wall", room=3]);
m
#################
## VERTICAL ##
#################
- name: 1P vertical wall
- name: 1P vertical
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P vertical wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="vertical wall", room=1]);
m
- name: 2P vertical
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P vertical wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="vertical wall", room=2]);
m
- name: 3P vertical
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="vertical wall", room=3]);
m
#################
## CORNERS ##
#################
# the order is:
# upleft upright
# up left up right
# D+----+C
# | |
# | |
# A+----+B
# lowleft lowright
# low left low right
#########
## A ##
#########
- name: 1P lower left corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P lower left corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P lower left corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="lower left corner", room=3]);
m
#########
## B ##
#########
- name: 1P lower right corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="lower right corner", room=1]);
m
- name: 2P lower right corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="lower right corner", room=2]);
m
- name: 3P lower right corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="lower right corner", room=3]);
m
#########
## C ##
#########
- name: 1P upper right corner
- name: 1P upper right
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P upper right corner
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="upper right corner", room=1]);
m
- name: 2P upper right
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P upper right corner
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="upper right corner", room=2]);
m
- name: 3P upper right
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="upper right corner", room=3]);
m
#########
## D ##
#########
- name: 1P upper left corner
- name: 2P upper left
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P upper left corner
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P upper left corner
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="upper left corner", room=2]);
m
- name: 3P upper left
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="upper left corner", room=3]);
m
#################
## SEPARATORS ##
#################
# 1
- name: 1S down and horizontal wall
- name: 1S down and horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 1S up and horizontal wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="down and horizontal wall", room=1]);
m
- name: 1S up and horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="up and horizontal wall", room=1]);
m
# 2
- name: 2S left and vertical wall
- name: 1S left and vertical
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 2S up and horizontal wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="left and vertical wall", room=2]);
m
- name: 2S up and horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="up and horizontal wall", room=2]);
m
# 3
- name: 3S left and vertical wall
- name: 3S left and vertical
system: true
program: run "scenarios/Tutorials/move_system.sw"
- name: 3S down and horizontal wall
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="left and vertical wall", room=3]);
m
- name: 3S down and horizontal
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="S", entity="down and horizontal wall", room=3]);
m
#################
## GATES ##
#################
Expand All @@ -322,13 +398,25 @@ robots:
#################
- name: 1P flower
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="flower", room=1]);
m
- name: 2P flower
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="flower", room=2]);
m
- name: 3P flower
system: true
program: run "scenarios/Tutorials/move_system.sw"
program: |
def main = \a. return noop end
m <- instant (run "scenarios/Tutorials/move_surveil.sw";
main [action="P", entity="flower", room=3]);
m
Comment on lines +349 to +351
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byorgey this is how instant has to be used to not pay for tangible run. The result is the rest of the computation which waits and places the wall.

entities:
- name: Win
display:
Expand Down
66 changes: 66 additions & 0 deletions data/scenarios/Tutorials/move_surveil.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
def repeat : Int -> (Int -> Cmd Unit) -> Cmd Unit =
\n. \c. if (n == 0) {} {c n; repeat (n-1) c}
end

def elif = \b.\t.\e. {if b t e} end
def else = \e. e end

def act_lazy: Text -> Text -> Cmd (Cmd Unit) = \a.\e. instant $
if (a == "S") {
if (e != "") { create e } {};
return (swap e; log $ a ++ ": " ++ e)
} $elif (a == "G") {
return (grab; log a)
} $elif (a == "P") {
if (e != "") { create e } {};
return (place e; log $ a ++ ": " ++ e)
} $else {
return (fail $ "Finished waiting for check but I don't know what to do: '" ++ a ++ "'")
}
end

def position: Int -> (Int * Int) = \room.
if (room == 1) {
(3,0)
} $elif (room == 2) {
(7,1)
} $elif (room == 3) {
(6,4)
} $else {
fail $ "unknown room: " ++ format room
}
end

def room_changes = \room. if (room == 1) {1} {2} end

def main: [action: Text, entity: Text, room: Int] -> Cmd (Cmd Unit) = \args.
let pos = position args.room in
log $ format args;
target <- as self {teleport self pos; scan down};
log $ "at position" ++ format pos ++ ": " ++ format target;
act <- act_lazy args.action args.entity;
return (
// first room optimization - actively wait for one tick to see if the change occured
target2 <- as self {teleport self pos; scan down};
if (args.room == 1 && target == target2) {
turn forward
} {};
let changes = room_changes args.room in
has_changed <-
if (target != target2) {
log "changed in first tick - skipping one wait";
return true
} $else {
target3 <- as self {teleport self pos; scan down};
if (target != target3) { log "changed in second tick - skipping one wait" }{};
return $ target != target3
};
let changed = if has_changed {1} {0} in
repeat (changes - changed) (\i.
log $ "sleeping until " ++ format pos ++ " changes (countdown: " ++ format i ++ ")";
surveil pos;
wait 1000000;
);
act
)
end
2 changes: 1 addition & 1 deletion test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ testScenarioSolutions rs ui key =
[ testGroup
"Tutorial"
[ testTutorialSolution Default "Tutorials/backstory"
, testTutorialSolution (Sec 3) "Tutorials/move"
, testTutorialSolution (Sec 10) "Tutorials/move"
, testTutorialSolution Default "Tutorials/craft"
, testTutorialSolution Default "Tutorials/grab"
, testTutorialSolution Default "Tutorials/place"
Expand Down
Loading