From 2961923534e55478a844f0d1abdc4730984802ed Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 4 Mar 2022 00:11:36 +0000 Subject: [PATCH] Fix combination bug with small inventories --- src/Dodge/Combine.hs | 6 ++---- src/Dodge/Initialisation.hs | 5 ++++- src/Multiset.hs | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 341444073..05b324025 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -48,12 +48,10 @@ lookupItemsUsingTrie ((mods,ct,i,n):xs) t = do let is = replicate n' (mods,i) concatMap (map (first (is ++)) . lookupItemsUsingTrie xs) $ maybeToList (_trieChildren t M.!? (n',ct)) -invertListInvMult :: IM.IntMap Item - -> [[(M.Map ModuleSlot ItemModule,CombineType,Int,Int)]] +invertListInvMult :: IM.IntMap Item -> [[(M.Map ModuleSlot ItemModule,CombineType,Int,Int)]] invertListInvMult = powlistUpToN 4 . invertListInv -invertListInv :: IM.IntMap Item - -> [(M.Map ModuleSlot ItemModule,CombineType,Int,Int)] +invertListInv :: IM.IntMap Item -> [(M.Map ModuleSlot ItemModule,CombineType,Int,Int)] invertListInv = IM.foldrWithKey (\k it -> ((_itModules it,_itType it, k, itStackAmount it) :) ) [] diff --git a/src/Dodge/Initialisation.hs b/src/Dodge/Initialisation.hs index 18c35c81d..e350b2e66 100644 --- a/src/Dodge/Initialisation.hs +++ b/src/Dodge/Initialisation.hs @@ -1,5 +1,7 @@ module Dodge.Initialisation where import Dodge.Default.World +--import Dodge.Combine +--import Dodge.Base.You --import Dodge.Base --import Dodge.Save import Dodge.Data @@ -39,4 +41,5 @@ initialWorld = defaultWorld } testStringInit :: World -> [String] -testStringInit w = [show $ length $ _magnets w] +--testStringInit = map (concatMap $ \(_,ct,_,_) -> show ct) . invertListInvMult . yourInv +testStringInit = const [] diff --git a/src/Multiset.hs b/src/Multiset.hs index c481912ee..eab305df6 100644 --- a/src/Multiset.hs +++ b/src/Multiset.hs @@ -18,9 +18,19 @@ powlistUpToN' n (x:xs) -- there is a (probably) faster SO answer that produces power lists of size -- exactly N, but that answer is harder to adapt powlistUpToN :: Int -> [a] -> [[a]] -powlistUpToN n xs = +powlistUpToN n xs = concat $ drop (length xs-n) (subseqsBySize xs) + where + subseqsBySize [] = [[[]]] + subseqsBySize (y:ys) = + let next = subseqsBySize ys + in zipWith (++) ([]:next) (map (map (y:)) next ++ [[]]) +powlistUpToN'' :: Int -> [a] -> [[a]] +powlistUpToN'' n xs = let l = length xs - in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs) +-- in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs) + in if n > l + then concat $ subseqsBySize xs + else concat $ drop (l-n) (subseqsBySize xs) where subseqsBySize [] = [[[]]] subseqsBySize (y:ys) =