License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Swarm.Game.Scenario.Topography.Structure.Recognition.Precompute
Description
Precomputation for structure recognizer.
Search process overview
2D structures may be defined at the
toplevel of a scenario file.
Upon scenario load, all of the predefined structures that are marked
as "recognize"
are compiled into searcher state machines.
When an entity is placed on any cell in the world, the
entityModified
function is called, which looks up a customized searcher based
on the type of placed entity.
The first searching stage looks for any member row of all participating structure definitions that contains the placed entity. The value returned by the searcher is a second-stage searcher state machine, which this time searches for complete structures of which the found row may be a member.
Both the first stage and second stage searcher know to start the search at a certain offset horizontally or vertically from the placed entity, based on where within a structure that entity (or row) may occur.
Upon locating a complete structure, it is added to a registry
(see FoundRegistry
), which
supports lookups by either name or by location (using two different
maps maintained in parallel). The map by location is used to remove
a structure from the registry if a member entity is changed.
Synopsis
- mkAutomatons :: [SymmetryAnnotatedGrid StructureCells] -> RecognizerAutomatons StructureCells Entity
- populateStaticFoundStructures :: [FoundStructure b a] -> FoundRegistry b a
- getEntityGrid :: StructureCells -> [SymbolSequence Entity]
- lookupStaticPlacements :: StaticStructureInfo -> [FoundStructure StructureCells Entity]
Main external interface
mkAutomatons :: [SymmetryAnnotatedGrid StructureCells] -> RecognizerAutomatons StructureCells Entity Source #
Create Aho-Corasick matchers that will recognize all of the provided structure definitions
Helper functions
populateStaticFoundStructures :: [FoundStructure b a] -> FoundRegistry b a #
getEntityGrid :: StructureCells -> [SymbolSequence Entity] Source #
lookupStaticPlacements :: StaticStructureInfo -> [FoundStructure StructureCells Entity] Source #
The output list of FoundStructure
records is not yet
vetted; the ensureStructureIntact
function will subsequently
filter this list.