Skip to content

Commit

Permalink
Update recipe graph with yields
Browse files Browse the repository at this point in the history
  • Loading branch information
xsebek committed Jul 13, 2024
1 parent b782934 commit c761f99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/swarm-doc/Swarm/Doc/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ classicScenarioRecipeGraphData = simpleErrorHandle $ do
{ rgStartingDevices = devs
, rgStartingInventory = inv
, rgWorldEntities = worldEntities
, rgLevels = recipeLevels recipes (Set.unions [worldEntities, devs, inv])
, rgLevels = recipeLevels emap recipes (Set.unions [worldEntities, devs, inv])
, rgAllEntities = Set.fromList . Map.elems $ entitiesByName emap
, rgRecipes = recipes
}
Expand All @@ -268,16 +268,16 @@ classicScenarioRecipeGraphData = simpleErrorHandle $ do
--
-- So:
-- * Level 0 - starting entities (for example those obtainable in the world)
-- * Level N+1 - everything possible to make (or drill) from Level N
-- * Level N+1 - everything possible to make (or drill or harvest) from Level N
--
-- This is almost a BFS, but the requirement is that the set of entities
-- required for recipe is subset of the entities known in Level N.
--
-- If we ever depend on some graph library, this could be rewritten
-- as some BFS-like algorithm with added recipe nodes, but you would
-- need to enforce the condition that recipes need ALL incoming edges.
recipeLevels :: [Recipe Entity] -> Set Entity -> [Set Entity]
recipeLevels recipes start = levels
recipeLevels :: EntityMap -> [Recipe Entity] -> Set Entity -> [Set Entity]
recipeLevels emap recipes start = levels
where
recipeParts r = ((r ^. recipeInputs) <> (r ^. recipeCatalysts), r ^. recipeOutputs)
m :: [(Set Entity, Set Entity)]
Expand All @@ -286,7 +286,13 @@ recipeLevels recipes start = levels
levels = reverse $ go [start] start
where
isKnown known (i, _o) = null $ i Set.\\ known
nextLevel known = Set.unions . map snd $ filter (isKnown known) m
lookupYield e = case view entityYields e of
Nothing -> e
Just yn -> case E.lookupEntityName yn emap of
Nothing -> error "unknown yielded entity"
Just ye -> ye
yielded = Set.map lookupYield
nextLevel known = Set.unions $ yielded known : map snd (filter (isKnown known) m)
go ls known =
let n = nextLevel known Set.\\ known
in if null n
Expand Down
3 changes: 0 additions & 3 deletions test/integration/TestRecipeCoverage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ nonCoveredList =
, "binoculars"
, "blueprint"
, "caliper"
, "cup of tea"
, "decoder ring"
, "dozer blade"
, "infinite improbability drive"
, "linotype"
, "olfactometer"
, "rolex"
, "tape drive"
, "tea leaves"
, "wedge"
]

Expand Down

0 comments on commit c761f99

Please sign in to comment.