Move towards correcting module combinations

This commit is contained in:
2022-06-08 17:36:24 +01:00
parent ba8b33a87c
commit 95ec30837a
2 changed files with 42 additions and 8 deletions
+34 -8
View File
@@ -18,6 +18,9 @@ import Dodge.Module
import Multiset import Multiset
import SimpleTrie import SimpleTrie
import Data.Foldable
import Data.Map.Merge.Strict
import Control.Monad
import Control.Lens import Control.Lens
import Data.Bifunctor import Data.Bifunctor
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
@@ -50,7 +53,36 @@ combineItemListYou = map (first f) . lookupItems' . yourInv
where where
f = concatMap g f = concatMap g
g (amount,i) = replicate (_toInt amount) i g (amount,i) = replicate (_toInt amount) i
combineItemListYou' :: World -> [([Int],(Item,[String]))]
combineItemListYou' w = map (cmm (yourInv w)) $ combineItemListYou w
cmm :: IM.IntMap Item -> ([Int],Item) -> ([Int],(Item,[String]))
cmm inv (is,itm) = (is,(itm & itType . iyModules .~ mods, s))
where
mms = map (_iyModules . _itType . (inv IM.!)) $ is
(s,mods) = combineModuleMaps (_iyModules $ _itType itm) mms
combineModuleMaps :: M.Map ModuleSlot ItemModuleType -> [M.Map ModuleSlot ItemModuleType]
-> ([String],M.Map ModuleSlot ItemModuleType)
combineModuleMaps = foldrM cMod
cMod :: M.Map ModuleSlot ItemModuleType
-> (M.Map ModuleSlot ItemModuleType)
-> ([String],M.Map ModuleSlot ItemModuleType)
cMod = mergeA
(filterAMissing f)
(filterAMissing f')
(zipWithAMatched g)
where
f k EMPTYMODULE = ([],False)
f k md = ([],False)
f' k EMPTYMODULE = ([],True)
f' k md = ([rm md++"SECOND"++show k],True)
g k EMPTYMODULE md = ([],md)
g k md1 md2 = ([rm md1++"BOTH"],md2)
rm md = "REMOVES "++fromJust (moduleName md)
-- this can probably be improved by going through accessing the combinations -- this can probably be improved by going through accessing the combinations
-- trie going through each combine type in your inventory in order, rather than -- trie going through each combine type in your inventory in order, rather than
@@ -77,14 +109,8 @@ invertListInv = IM.foldrWithKey
(\k it -> ((_iyModules $ _itType it,_iyBase $ _itType it, k, itStackAmount it) :) ) (\k it -> ((_iyModules $ _itType it,_iyBase $ _itType it, k, itStackAmount it) :) )
[] []
-- gives a list of indices-item pairs. combineItemListYou'' :: World -> [([Int],(Item,[String]))]
-- Note that within the pair, indices can be repeated if two or more of an item combineItemListYou'' = map addModules . concatMap lookupItems . invertListInvMult . yourInv
-- are needed
combineItemListYou'' :: World -> [([Int],Item)]
combineItemListYou'' = map (second fst) . combineItemListYou'
combineItemListYou' :: World -> [([Int],(Item,[String]))]
combineItemListYou' = map addModules . concatMap lookupItems . invertListInvMult . yourInv
addModules :: ([(M.Map ModuleSlot ItemModuleType,Int)],Item) addModules :: ([(M.Map ModuleSlot ItemModuleType,Int)],Item)
-> ([Int],(Item,[String])) -> ([Int],(Item,[String]))
+8
View File
@@ -229,6 +229,14 @@ inventoryX c = case c of
, makeTypeCraftNum 5 TRANSFORMER , makeTypeCraftNum 5 TRANSFORMER
, makeTypeCraftNum 5 PRISM , makeTypeCraftNum 5 PRISM
, makeTypeCraftNum 5 LIGHTER , makeTypeCraftNum 5 LIGHTER
, makeTypeCraftNum 5 INCENDIARYMODULE
]
'G' ->
[ autoPistol
, makeTypeCraftNum 2 HARDWARE
, makeTypeCraftNum 2 MAGNET
, makeTypeCraftNum 5 INCENDIARYMODULE
, makeTypeCraftNum 5 STATICMODULE
] ]
_ -> [] _ -> []