-
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.
Implement entity tags and commands (#1635)
Closes #1631 ## Design * Entities have a new property: a `Set` of textual tags. * Two new commands are introduced: * `HasTag` checks whether a single entity has a given tag * `TagMembers` allows cycling through all members with a given tag * `TagMembers` may be considered more powerful than `HasTag`, so has its own separate capability (`CTagmembers`). * A map is computed at scenario initialization to facilitate `TagMembers` lookups. * Tag names are highlighted in yellow in markdown. ## Demo scripts/play.sh -i scenarios/Testing/1631-tags.yaml --autoplay ## Other changes * Incidentally, changed `knownEntities` from a list to a `Set` so that `Set.member` can be used instead of `elem`.
- Loading branch information
Showing
16 changed files
with
222 additions
and
14 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,130 @@ | ||
version: 1 | ||
name: Test tag commands | ||
description: | | ||
Test the `hastag` and `tagmembers` command. | ||
objectives: | ||
- condition: | | ||
as base {has "mushroom"} | ||
prerequisite: | ||
not: got_fruit | ||
goal: | ||
- | | ||
Pick up something `edible`{=tag} that is not a `fruit`{=tag}. | ||
- teaser: "No fruit!" | ||
id: got_fruit | ||
optional: true | ||
condition: | | ||
// Returns true if prohibited item is in inventory. | ||
def checkFruit = \idx. | ||
result <- tagmembers "fruit" idx; | ||
let totalCount = fst result in | ||
let member = snd result in | ||
let nextIdx = idx + 1 in | ||
hasProhibited <- as base {has member}; | ||
if hasProhibited { | ||
return true; | ||
} { | ||
if (nextIdx < totalCount) { | ||
checkFruit nextIdx; | ||
} { | ||
return false; | ||
} | ||
} | ||
end; | ||
checkFruit 0; | ||
goal: | ||
- | | ||
Do not pick up any fruit. | ||
solution: | | ||
def findTarget = | ||
result <- scan down; | ||
isTarget <- case result (\_. return false) (\item. | ||
isEdible <- hastag item "edible"; | ||
isFruit <- hastag item "fruit"; | ||
return $ isEdible && not isFruit; | ||
); | ||
if isTarget { | ||
grab; | ||
return (); | ||
} { | ||
move; | ||
findTarget; | ||
} | ||
end; | ||
findTarget; | ||
robots: | ||
- name: base | ||
dir: [1,0] | ||
devices: | ||
- ADT calculator | ||
- branch predictor | ||
- barcode scanner | ||
- dictionary | ||
- grabber | ||
- lambda | ||
- lodestone | ||
- logger | ||
- scanner | ||
- solar panel | ||
- strange loop | ||
- treads | ||
entities: | ||
- name: barcode scanner | ||
display: | ||
attr: red | ||
char: 'S' | ||
description: | ||
- Reads the 'tag' of an item | ||
properties: [portable] | ||
capabilities: [hastag, tagmembers] | ||
- name: canteloupe | ||
display: | ||
char: 'c' | ||
description: | ||
- Melon | ||
tags: [edible, fruit] | ||
properties: [portable] | ||
- name: mushroom | ||
display: | ||
char: 'm' | ||
description: | ||
- Nature's tiny umbrella. | ||
tags: [edible, fungus] | ||
properties: [portable] | ||
- name: gravel | ||
display: | ||
char: 'g' | ||
description: | ||
- Crushed rock | ||
properties: [portable] | ||
- name: strawberry | ||
display: | ||
char: 's' | ||
description: | ||
- Just ripe | ||
tags: [edible, fruit] | ||
- name: peach | ||
display: | ||
char: 'g' | ||
description: | ||
- Just ripe | ||
tags: [edible, fruit] | ||
properties: [portable] | ||
world: | ||
palette: | ||
'.': [grass] | ||
'B': [grass, null, base] | ||
'a': [grass, canteloupe] | ||
'b': [grass, gravel] | ||
'c': [grass, strawberry] | ||
'd': [grass, mushroom] | ||
'e': [grass, peach] | ||
upperleft: [-5, 5] | ||
map: | | ||
....... | ||
B.abcde | ||
....... |
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 |
---|---|---|
|
@@ -89,6 +89,8 @@ | |
"waypoint" | ||
"structure" | ||
"floorplan" | ||
"hastag" | ||
"tagmembers" | ||
"detect" | ||
"resonate" | ||
"density" | ||
|
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.