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

better transparency handling for structure recognizer #2115

Merged
merged 3 commits into from
Aug 16, 2024

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Aug 13, 2024

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

@kostmo kostmo changed the title [WIP] more logging for structure recognizer better transparency handling for structure recognizer Aug 14, 2024
@kostmo kostmo requested review from xsebek and byorgey August 16, 2024 06:48
@kostmo kostmo marked this pull request as ready for review August 16, 2024 06:48
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

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

LGTM. 👍 Is there a playable challenge/tutorial where this would make it easier for the player to build the structure?

@kostmo
Copy link
Member Author

kostmo commented Aug 16, 2024

Is there a playable challenge/tutorial where this would make it easier for the player to build the structure?

Not specifically. So far, the scenarios with structure recognition have been crafted to avoid this kind of issue.

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Aug 16, 2024
@mergify mergify bot merged commit d1791a1 into main Aug 16, 2024
14 checks passed
@mergify mergify bot deleted the dev/more-structure-logging branch August 16, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants