This commit is contained in:
2024-09-13 09:43:56 +01:00
parent d2e1b054d0
commit c81fd5490d
6 changed files with 80 additions and 124 deletions
+1 -38
View File
@@ -1,12 +1,8 @@
--{-# LANGUAGE TupleSections #-}
module Dodge.Combine (
combineList,
combineList',
) where
import Color
--import Dodge.Data.SelectionList
import Control.Lens
import Control.Monad
import Data.Bifunctor
@@ -28,60 +24,27 @@ import Dodge.Module
import qualified IntMapHelp as IM
import SimpleTrie
--invertInventory :: IM.IntMap Item -> [(ItemBaseType, ItAmount, Int)]
--invertInventory =
-- IM.foldrWithKey
-- (\k it -> ((_iyBase $ _itType it, itStackAmount it, k) :))
-- []
invertInventoryToMap :: IM.IntMap Item -> M.Map ItemBaseType [Int]
invertInventoryToMap =
IM.foldrWithKey
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) [k]))
mempty
--splitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), (ItAmount, Int))]
--splitItAmounts = concatMap f
-- where
-- f (x, n, y) = [((i, x), (i, y)) | i <- [1 .. n]]
groupSplitItemAmounts :: M.Map ItemBaseType [Int] -> [((ItAmount, ItemBaseType), [Int])]
groupSplitItemAmounts = M.foldrWithKey f []
where
f ibt is = (++) [((fromIntegral i, ibt), take i is) | i <- [1 .. length is]]
--flatSplitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), [Int])]
--flatSplitItAmounts = concatMap f
-- where
-- f (x, n, y) = [((i, x), replicate (fromIntegral i) y) | i <- [1 .. n]]
--lookupItems :: IM.IntMap Item -> [([(ItAmount, Int)], Item)]
--lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory
flatLookupItems :: IM.IntMap Item -> [([[Int]], Item)]
flatLookupItems =
flip multiLookupTrieI combinationsTrie . sortOn fst . groupSplitItemAmounts
. invertInventoryToMap
--flatLookupItems :: IM.IntMap Item -> [([[Int]],Item)]
--flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSplitItAmounts
-- . invertInventory
combineItemListYouX :: World -> [([Int], Item)]
combineItemListYouX = map (first $ concat) . flatLookupItems . yourInv
--combineItemListYouX' :: World -> [([Int], Item)]
--combineItemListYouX' = map (first $ concatMap g) . lookupItems . yourInv
-- where
-- g (amount, i) = replicate (_getItAmount amount) i
combineList :: World -> [SelectionItem CombinableItem]
combineList w = case combineList' w of
[] -> [SelectionInfo ["No possible combinations"] 1 False white 0]
xs -> xs
combineList' :: World -> [SelectionItem CombinableItem]
combineList' = map f . combineListInfo
combineList = map f . combineListInfo
where
f (is, (strs, itm)) =
SelectionItem