Skip to content

Commit

Permalink
Watch for lodestone (#2146)
Browse files Browse the repository at this point in the history
* use `watch` to avoid busy-waiting for the bit seed to grow

Prompted by #2140, which shows hundreds of `ishere` calls.

| Before | After |
|--------|--------|
| <img width="143" alt="Screenshot 2024-09-15 at 10 02 51 PM" src="https://github.com/user-attachments/assets/174827e4-9371-4405-a6c2-dd20233e4588"> | <img width="143" alt="Screenshot 2024-09-15 at 10 01 32 PM" src="https://github.com/user-attachments/assets/a1d02d16-487c-46d0-b5f1-5aaf4da111cb"> |

This should make the testing scenario take 0.1s from previous 0.5s. You can test it with:
```sh
cabal run swarm-integration -O0 -- -p '/Testing\/562-lodestone/
```
  • Loading branch information
xsebek authored Sep 15, 2024
1 parent 746be8f commit c37334f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions data/scenarios/Testing/562-lodestone.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ def ifC = \p.\t.\e.
if b t e
end;

def until = \p.\t.
ifC p t {until p t}
def waitFor = \e.\t.
watch down;
wait 100;
ifC (ishere e) t {waitFor e t}
end;

def repeat = \c.
Expand All @@ -29,18 +31,18 @@ end;

// get one lodestone
build {log "Hey!"; turn north; m2; l <- grab; turn back; m2; place l};
until (ishere "lodestone") {grab};
waitFor "lodestone" {grab};

// get two bit (0)
build {
log "Hi!";
repeat (
log "I am going for a bit";
turn east; m2; x <- until (ishere "bit (0)") {harvest}; turn back; m2; place x;
turn east; m2; x <- waitFor "bit (0)" {harvest}; turn back; m2; place x;
log "I brought a bit";
)};
until (ishere "bit (0)") {grab};
until (ishere "bit (0)") {grab};
waitFor "bit (0)" {grab};
waitFor "bit (0)" {grab};

make "bit (1)";
make "drill bit"
2 changes: 2 additions & 0 deletions data/scenarios/Testing/562-lodestone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ robots:
- workbench
- 3D printer
- branch predictor
- rolex
inventory:
- [10, drill]
- [10, lambda]
Expand All @@ -37,6 +38,7 @@ robots:
- [10, strange loop]
- [10, branch predictor]
- [10, toolkit]
- [10, rolex]
- [0, drill bit]
- [0, bit (0)]
- [0, bit (1)]
Expand Down

0 comments on commit c37334f

Please sign in to comment.