Skip to content

Commit

Permalink
rename constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Nov 24, 2024
1 parent c82150e commit c2061c3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/swarm-engine/Swarm/Game/State/Initialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ pureScenarioToGameState scenario theSeed now toRun gsc =
-- we don't actually have to "search" for these structures since we are
-- explicitly given their location; we only need to validate that each
-- structure remains intact given other, potentially overlapping static placements.
--
mkRecognizer ::
(Has (State GameState) sig m) =>
StaticStructureInfo Cell ->
Expand All @@ -206,7 +205,7 @@ mkRecognizer structInfo@(StaticStructureInfo structDefs _) = do
mkLogEntry (x, intact) =
IntactPlacementLog
intact
$ FoundStructure (upperLeftCorner x) ((distillLabel . structureWithGrid) x)
$ PositionedStructure (upperLeftCorner x) ((distillLabel . structureWithGrid) x)

buildTagMap :: EntityMap -> Map Text (NonEmpty EntityName)
buildTagMap em =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ lookupStaticPlacements extractor (StaticStructureInfo structDefs thePlacements)
g (LocatedStructure (OrientedStructure theName d) loc) = do
sGrid <- M.lookup theName definitionMap
x <- extractOrientedGrid extractor sGrid d
return $ FoundStructure (Cosmic subworldName loc) x
return $ PositionedStructure (Cosmic subworldName loc) x

-- | Matches definitions against the placements.
-- Fails fast (short-circuits) if a non-matching
Expand All @@ -171,7 +171,7 @@ ensureStructureIntact ::
GenericEntLocator s a ->
FoundStructure b a ->
s (Maybe (StructureIntactnessFailure a))
ensureStructureIntact registry entLoader (FoundStructure upperLeft (StructureWithGrid _ _ _ grid)) = do
ensureStructureIntact registry entLoader (PositionedStructure upperLeft (StructureWithGrid _ _ _ grid)) = do
fmap leftToMaybe . runExceptT $ mapM checkLoc allLocPairs
where
gridArea = getNEGridDimensions grid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ removeStructure fs (FoundRegistry byName byLoc) =
tidyDelete = NEM.nonEmptyMap . NEM.delete upperLeft

addFound :: FoundStructure b a -> FoundRegistry b a -> FoundRegistry b a
addFound fs@(FoundStructure loc swg) (FoundRegistry byName byLoc) =
addFound fs@(PositionedStructure loc swg) (FoundRegistry byName byLoc) =
FoundRegistry
(M.insertWith (<>) k (NEM.singleton loc swg) byName)
(M.union occupationMap byLoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ checkChunksCombination
NE.toList $ NE.map mkFoundStructure . referencingRows . chunkStructure $ foundChunkRow x
where
mkFoundStructure r =
FoundStructure
PositionedStructure
(cLoc `offsetBy` theOffset)
(wholeStructure r)
where
Expand Down Expand Up @@ -279,14 +279,14 @@ registerRowMatches entLoader cLoc (AutomatonInfo horizontalOffsets pwMatcher) rS
registry = rState ^. foundStructures
PiecewiseRecognition pwSM rowChunkReferences = pwMatcher

getStructInfo (FoundStructure loc swg) = (distillLabel swg, loc)
getStructInfo (PositionedStructure loc swg) = (distillLabel swg, loc)

validateIntactness2d fs = do
maybeIntactnessFailure <- lift $ ensureStructureIntact (rState ^. foundStructures) entLoader fs
tell . pure . ChunkIntactnessVerification
$ IntactPlacementLog
maybeIntactnessFailure
$ FoundStructure (upperLeftCorner fs) (distillLabel . structureWithGrid $ fs)
$ PositionedStructure (upperLeftCorner fs) (distillLabel . structureWithGrid $ fs)

return $ null maybeIntactnessFailure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ type FoundStructure b a = PositionedStructure (StructureWithGrid b a)
--
-- Compare "PositionedStructure OrientedStructure" to:
-- "Swarm.Game.Scenario.Topography.Structure.Recognition.Static.LocatedStructure"
data PositionedStructure s = FoundStructure
data PositionedStructure s = PositionedStructure
{ upperLeftCorner :: Cosmic Location
, structureWithGrid :: s
}
Expand Down Expand Up @@ -323,7 +323,7 @@ instance (Eq b, Eq a) => Ord (FoundStructure b a) where
-- Cells within the rectangular bounds of the structure that are unoccupied
-- are not included.
genOccupiedCoords :: FoundStructure b a -> [Cosmic Location]
genOccupiedCoords (FoundStructure loc swg) =
genOccupiedCoords (PositionedStructure loc swg) =
catMaybes . NE.toList . mapWithCoordsNE f $ entityGrid swg
where
-- replaces an "occupied" grid cell with its location
Expand Down

0 comments on commit c2061c3

Please sign in to comment.