-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better transparency handling for structure recognizer (#2115)
Some recognizable structures have "transparent" cells. However, the Aho-Corasick algorithm doesn't support "wildcards", which is essentially what transparent cells are, for the purpose of matching. So, for a structure template that contains transparent cells to be recognized, the cells of the world must also have "empty" cells in the same place. Despite this, we can accommodate certain instances of structure recognition when the transparent cells are "overlapped" (or "incurred upon") by some other entity. We do this by "masking out" entities from the world that don't participate in the set of structures we're trying to match against. This often works well, except when the set of structures to be recognized contains: * one structure `S1` with transparent cells * another structure `S2` with some additional type of entity `E` not participating in `S1` * The entity `E` occupies a transparent cell of `S1`. `E` can't be masked out since we're trying to simultaneously recognize structures of type `S2` in the same Aho-Corasick pass. So a legitimate instance of `S1` will fail to be recognized. ## Workaround We can make multiple Aho-Corasick passes: one pass for each distinct set of "masked entities". Notably: * If no structures have transparent cells, we don't need to mask at all * If all of the structures that contain transparent cells have an identical set of participating entities, they can all be handled in the same pass * **Not implemented:** A structure with no transparency (i.e. with an empty "mask set") can be handled in the same pass as a a transparent structure, if they have an identical participating entity set. ## Caveats Note that this fundamental limitation of Aho-Corasick still exists for "incurring entities" of the **same type** as the entity participants in the structure to be recognized. E.g., if we have a structure defined as: ``` X XX ``` then, depending on the order of entity placement, the following occurrence in the world will **not** be recognized: ``` XX XX ``` ## Testing ``` scripts/test/run-tests.sh --test-options '--pattern "structure-recognizer"' ``` ## Also in this PR * improved docs/logging
- Loading branch information
Showing
10 changed files
with
305 additions
and
73 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
77 changes: 77 additions & 0 deletions
77
...s/Testing/1575-structure-recognizer/2115-encroaching-upon-exterior-transparent-cells.yaml
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,77 @@ | ||
version: 1 | ||
name: Structure recognition - exterior transparency | ||
description: | | ||
Incursion of an entity of a foreign type | ||
upon a "transparent" cell within the bounding box | ||
of a recognizable structure shall not prevent | ||
the structure from being recognized. | ||
If the incurring entity is the *same* type as | ||
a participating entity in that structure, however, | ||
it will prevent recognition. | ||
creative: false | ||
objectives: | ||
- teaser: Recognize structure | ||
goal: | ||
- | | ||
`chevron`{=structure} structure should be recognized upon completion, | ||
even with an extraneous entity within its bounds. | ||
condition: | | ||
def isRight = \x. case x (\_. false) (\_. true); end; | ||
foundBox <- structure "chevron" 0; | ||
return $ isRight foundBox; | ||
robots: | ||
- name: base | ||
dir: east | ||
devices: | ||
- ADT calculator | ||
- blueprint | ||
- fast grabber | ||
- logger | ||
- treads | ||
inventory: | ||
- [1, board] | ||
- name: judge | ||
dir: east | ||
system: true | ||
display: | ||
invisible: true | ||
solution: | | ||
move; move; move; | ||
swap "board"; | ||
structures: | ||
- name: chevron | ||
recognize: [north] | ||
structure: | ||
palette: | ||
'b': [stone, board] | ||
mask: '.' | ||
map: | | ||
.b | ||
bb | ||
- name: stripe | ||
recognize: [north] | ||
structure: | ||
palette: | ||
't': [grass, tree] | ||
'b': [grass, board] | ||
map: | | ||
btb | ||
known: [board, mountain, tree] | ||
world: | ||
dsl: | | ||
{blank} | ||
palette: | ||
'.': [grass, erase] | ||
'B': [grass, erase, base] | ||
'j': [grass, erase, judge] | ||
't': [grass, tree] | ||
'b': [grass, board] | ||
upperleft: [-7, 3] | ||
map: | | ||
j..... | ||
...... | ||
.B.ttt | ||
...bb. | ||
...... |
85 changes: 85 additions & 0 deletions
85
...s/Testing/1575-structure-recognizer/2115-encroaching-upon-interior-transparent-cells.yaml
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,85 @@ | ||
version: 1 | ||
name: Structure recognition - interior transparency | ||
description: | | ||
Incursion of an entity of a foreign type | ||
upon a "transparent" cell within the bounding box | ||
of a recognizable structure shall not prevent | ||
the structure from being recognized. | ||
If the incurring entity is the *same* type as | ||
a participating entity in that structure, however, | ||
it will prevent recognition. | ||
creative: false | ||
objectives: | ||
- teaser: Recognize structure | ||
goal: | ||
- | | ||
`pigpen`{=structure} structure should be recognized upon completion, | ||
even with an extraneous entity within its bounds. | ||
condition: | | ||
def isRight = \x. case x (\_. false) (\_. true); end; | ||
foundBox <- structure "pigpen" 0; | ||
return $ isRight foundBox; | ||
robots: | ||
- name: base | ||
dir: east | ||
devices: | ||
- ADT calculator | ||
- blueprint | ||
- fast grabber | ||
- logger | ||
- treads | ||
inventory: | ||
- [1, board] | ||
- name: judge | ||
dir: east | ||
system: true | ||
display: | ||
invisible: true | ||
solution: | | ||
move; move; move; move; | ||
swap "board"; | ||
structures: | ||
- name: pigpen | ||
recognize: [north] | ||
structure: | ||
palette: | ||
'b': [stone, board] | ||
mask: '.' | ||
map: | | ||
bbbb | ||
b..b | ||
b..b | ||
bbbb | ||
- name: obstruction | ||
recognize: [north] | ||
structure: | ||
palette: | ||
't': [grass, tree] | ||
'b': [grass, board] | ||
map: | | ||
tttb | ||
known: [board, mountain, tree] | ||
world: | ||
dsl: | | ||
{blank} | ||
palette: | ||
'.': [grass, erase] | ||
'B': [grass, erase, base] | ||
'r': [grass, mountain] | ||
'j': [grass, erase, judge] | ||
'p': | ||
structure: | ||
name: pigpen | ||
cell: [grass] | ||
'b': | ||
structure: | ||
name: obstruction | ||
cell: [grass] | ||
upperleft: [-7, 3] | ||
map: | | ||
j..... | ||
.p.... | ||
...r.. | ||
B..b.. | ||
...... |
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.