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

robot wave scenario #1556

Merged
merged 4 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions data/scenarios/Challenges/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ hanoi.yaml
hackman.yaml
lights-out.yaml
bucket-brigade.yaml
wave.yaml
wolf-goat-cabbage.yaml
blender.yaml
friend.yaml
Expand Down
15 changes: 15 additions & 0 deletions data/scenarios/Challenges/_wave/solution.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def go =
move;
go;
end;

def start =
turn right;
wait 5;
try {
go;
} {};
grab;
end;

start;
20 changes: 20 additions & 0 deletions data/scenarios/Challenges/_wave/wavebot.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def crossPath =
doN 6 move;
Copy link
Member

@xsebek xsebek Sep 30, 2023

Choose a reason for hiding this comment

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

I suspect this is needlessly slow because we do not inline it.

Suggested change
doN 6 move;
// doN 6 move;
move; move; move; move; move; move;

I also tried replacing wait with turn forward. But do not do this, I measured it and wait is better!

Subjectively, the simulation seemed to keep playing better without lag on my computer once inlined.

EDIT: I will try to rebuild with profiling enabled and see if the difference is measurable.

Copy link
Member

Choose a reason for hiding this comment

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

Just following a blog post about profiling with cabal, I can see some difference in the graphs:

Non-Inlined Inlined
swarm_noninlined swarm_inlined

Copy link
Member

Choose a reason for hiding this comment

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

@xsebek Great work looking at performance, memory profiling, etc.! We haven't paid much attention to it so far but I'm sure there is tons of low-hanging fruit to improve performance.

I'm not sure inlining things in scenario programs is the right way to go, though. Ideally we should be able to encourage nice, modular code and work hard to make that nice, abstracted, modular code run fast.

Copy link
Member

@xsebek xsebek Sep 30, 2023

Choose a reason for hiding this comment

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

@byorgey it’s definitely not ideal to do it manually, thats why I made an issue to do it automatically. 🙂

@kostmo I would suggest inlining and adding a TODO linking the inline issue, but up to you.

turn back;
wait 5;
end;

def go =
crossPath;
go;
end;

def start =
pos <- whereami;
wait $ fst pos;
go;
end;

start;
74 changes: 74 additions & 0 deletions data/scenarios/Challenges/wave.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: 1
name: Wave
author: Karl Ostmo
description: |
Ride the wave
creative: false
objectives:
- goal:
- |
Grab the `bitcoin`{=entity} at the east end of the path.
Don't let the patrolling robots catch you!
prerequisite:
not: got_caught
condition: |
as base {has "bitcoin"};
- id: got_caught
teaser: Got caught
optional: true
hidden: true
goal:
- |
The robots caught you!
condition: |
as base {x <- meet; return $ case x (\_. false) (\_. true)};
robots:
- name: base
dir: [0, 1]
devices:
- branch predictor
- comparator
- dictionary
- grabber
- hourglass
kostmo marked this conversation as resolved.
Show resolved Hide resolved
- lambda
- logger
- net
- scanner
- strange loop
- treads
- name: wavebot
system: true
dir: [0, 1]
display:
invisible: false
attr: 'plant'
program: |
run "scenarios/Challenges/_wave/wavebot.sw"
kostmo marked this conversation as resolved.
Show resolved Hide resolved
solution: |
run "scenarios/Challenges/_wave/solution.sw"
entities: []
known: [wavy water, water, bitcoin]
world:
dsl: |
overlay
[ {dirt, water}
, if x % 7 + y % 5 == 0 then {dirt, wavy water} else {blank}
Copy link
Member

Choose a reason for hiding this comment

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

Nice, I like the repeating pattern, it looks like old school games. 🎮

]
upperleft: [-3, 6]
offset: false
palette:
'B': [grass, erase, base]
'w': [grass, erase, wavebot]
'x': [dirt, water]
'z': [grass, bitcoin]
'.': [grass, erase]
map: |
xxxxxx..................................................................................................................................................................................................................................................xxxxxx
xxx........................................................................................................................................................................................................................................................xxx
x............................................................................................................................................................................................................................................................x
B............................................................................................................................................................................................................................................................z
x............................................................................................................................................................................................................................................................x
xxx........................................................................................................................................................................................................................................................xxx
xxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxx

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be a bit shorter? Though it does work well as a performance test. 😅

1 change: 1 addition & 0 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ testScenarioSolutions rs ui =
, testSolution (Sec 3) "Challenges/word-search"
, testSolution (Sec 10) "Challenges/bridge-building"
, testSolution (Sec 5) "Challenges/ice-cream"
, testSolution (Sec 15) "Challenges/wave"
, testSolution (Sec 3) "Challenges/arbitrage"
, testSolution (Sec 10) "Challenges/gopher"
, testSolution (Sec 5) "Challenges/hackman"
Expand Down
Loading