Reorganise weapons
This commit is contained in:
+4
-28
@@ -20,14 +20,15 @@ import qualified Data.IntMap.Strict as IM
|
||||
--import qualified Data.IntSet as IS
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Data.List (sort,scanl',sortOn)
|
||||
import Data.List (scanl',sortOn)
|
||||
|
||||
combinationsTrie :: Trie (Int,CombineType) Item
|
||||
combinationsTrie = foldr (uncurry insertInTrie) emptyTrie
|
||||
$ map (first (sortOn snd)) itemCombinations
|
||||
|
||||
lookupTypeTrie :: [(CombineType,Int,Int)] -> Maybe ([Int],Item)
|
||||
lookupTypeTrie = undefined
|
||||
-- this can probably be improved by going through accessing the combinations
|
||||
-- trie going through each combine type in your inventory in order, rather than
|
||||
-- creating all multisets of combine types.
|
||||
|
||||
lookupItems' :: [(CombineType,Int,Int)] -> [ ([Int],Item) ]
|
||||
lookupItems' xs = lookupItems (sortOn (\(ct,_,_) -> ct) xs) combinationsTrie
|
||||
@@ -39,29 +40,6 @@ lookupItems ((ct,i,n):xs) t = do
|
||||
let is = replicate n' i
|
||||
concatMap (map (first (is ++)) . lookupItems xs) $ maybeToList (_trieChildren t M.!? (n',ct))
|
||||
|
||||
--lookupTypeTrie' :: [CombineType] -> Maybe Item
|
||||
--lookupTypeTrie' = flip lookupTrie combinationsTrie . sort
|
||||
|
||||
combineItemList :: IM.IntMap Item -> [([Int],Item)]
|
||||
combineItemList = undefined
|
||||
|
||||
--combineItemList :: IM.IntMap Item -> [([Int],Item)]
|
||||
--combineItemList = mapMaybe (pushOutMaybe . second lookupTypeTrie)
|
||||
-- . listCombos
|
||||
|
||||
pushOutMaybe :: (a,Maybe b) -> Maybe (a,b)
|
||||
pushOutMaybe (_,Nothing) = Nothing
|
||||
pushOutMaybe (x,Just y) = Just (x,y)
|
||||
|
||||
listCombos :: IM.IntMap Item -> [([Int], [CombineType])]
|
||||
listCombos = concatMap expandOut . invertListInvMult
|
||||
|
||||
expandOut :: [(CombineType,Int,Int)] -> [([Int],[CombineType])]
|
||||
expandOut [] = [([],[])]
|
||||
expandOut (x:xs) = (<>) <$> f x <*> expandOut xs
|
||||
where
|
||||
f (ct,i,n) = map (\j -> (replicate j i,replicate j ct)) [1..min 4 n]
|
||||
|
||||
invertListInvMult :: IM.IntMap Item -> [[(CombineType,Int,Int)]]
|
||||
invertListInvMult = powlistUpToN 4 . invertListInv
|
||||
|
||||
@@ -70,8 +48,6 @@ invertListInv = IM.foldrWithKey
|
||||
(\k it -> ((_itType it, k, itStackAmount it) :) )
|
||||
[]
|
||||
|
||||
combineItemListYou' :: World -> [([Int],Item)]
|
||||
combineItemListYou' = combineItemList . yourInv
|
||||
combineItemListYou :: World -> [([Int],Item)]
|
||||
combineItemListYou = concatMap lookupItems' . invertListInvMult . yourInv
|
||||
|
||||
|
||||
Reference in New Issue
Block a user