-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
towards #1171 ## New tests Unit tests: scripts/run-tests.sh --test-arguments '--pattern "Relative direction"' Integration tests for `sniff` and `chirp` demonstrate how to home in on an item using distance and orientation, respectively. ## Efficiency For the sake of execution time, I have capped the max "diameter" (`N`) of both commands to `200` cells. In the worst case (the entity is not present), `O(N^2)` cells are inspected, which manifests as a perceptible delay when the command is run. I came across the `getElemsInArea` function that seems to suggest that an `O(N * log N)` search may be possible. Is that the case? Otherwise we may be able to add some new data structures to the game state for efficient entity location querying.
- Loading branch information
Showing
15 changed files
with
264 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
version: 1 | ||
name: Chirp test | ||
creative: true | ||
description: Locate a tree using chirp | ||
objectives: | ||
- goal: | ||
- grab a tree. | ||
condition: | | ||
as base {has "tree"} | ||
solution: | | ||
def takeStep = \item. | ||
direction <- chirp item; | ||
if (direction == down) { | ||
grab; | ||
} { | ||
turn direction; | ||
move; | ||
takeStep item; | ||
} | ||
end; | ||
takeStep "tree"; | ||
robots: | ||
- name: base | ||
dir: [0,-1] | ||
display: | ||
char: Ω | ||
attr: robot | ||
devices: | ||
- logger | ||
- string | ||
- grabber | ||
- treads | ||
known: [] | ||
world: | ||
default: [blank] | ||
palette: | ||
'Ω': [grass, null, base] | ||
'.': [grass] | ||
'T': [grass, tree] | ||
upperleft: [0, 0] | ||
map: | | ||
......... | ||
......T.. | ||
......... | ||
......... | ||
.Ω....... | ||
......... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
version: 1 | ||
name: Sniff test | ||
creative: true | ||
description: Locate a tree using sniff | ||
objectives: | ||
- goal: | ||
- grab a tree. | ||
condition: | | ||
as base {has "tree"} | ||
solution: | | ||
def homeIn = \item. \oldDistance. | ||
if (oldDistance > 0) { | ||
move; | ||
newDistance <- sniff item; | ||
d <- if (newDistance > oldDistance) { | ||
turn back; | ||
move; | ||
turn left; | ||
return oldDistance; | ||
} { | ||
return newDistance; | ||
}; | ||
homeIn item d; | ||
} { | ||
grab; | ||
} | ||
end; | ||
let item = "tree" in | ||
initialDistance <- sniff item; | ||
homeIn item initialDistance; | ||
robots: | ||
- name: base | ||
dir: [0,-1] | ||
display: | ||
char: Ω | ||
attr: robot | ||
devices: | ||
- logger | ||
- string | ||
- grabber | ||
- treads | ||
known: [] | ||
world: | ||
default: [blank] | ||
palette: | ||
'Ω': [grass, null, base] | ||
'.': [grass] | ||
'T': [grass, tree] | ||
upperleft: [0, 0] | ||
map: | | ||
......... | ||
......T.. | ||
......... | ||
......... | ||
.Ω....... | ||
......... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.