Allow for stacking of items and combining sensibly

This commit is contained in:
2021-12-03 17:18:06 +00:00
parent b2a9192fe4
commit b41e3e3637
24 changed files with 166 additions and 159 deletions
-45
View File
@@ -1,45 +0,0 @@
{-# LANGUAGE TupleSections #-}
module Dodge.Combine.Combinations
where
--import Dodge.Data
import Dodge.Combine.Data
import Data.Bifunctor
import qualified Data.IntMap.Strict as IM
--import qualified Data.IntSet as IS
import qualified Data.Map.Strict as M
import Control.Monad
import Data.Maybe
combineList :: IM.IntMap CombineType -> [([Int],CombineType)]
combineList m = mapMaybe (pushoutmaybe . second (combine . toMultiset) . unzip)
. powlistN 4
$ IM.toList m
where
pushoutmaybe (_,Nothing) = Nothing
pushoutmaybe (x,Just y) = Just (x,y)
powlistN :: Int -> [a] ->[[a]]
powlistN _ [] = [[]]
powlistN n (x:xs)
| n <=0 = [[]]
| otherwise = ((x:) <$> powlistN (n-1) xs) ++ powlistN n xs
-- expo
powlist :: [a] -> [[a]]
powlist = filterM (const [True,False])
combine :: M.Map CombineType Int -> Maybe CombineType
combine m = lookup m combinations
toMultiset :: Ord a => [a] -> M.Map a Int
toMultiset = foldr (uncurry $ M.insertWith (+)) M.empty . map (,1)
combinations :: [(M.Map CombineType Int, CombineType)]
combinations = map (first toMultiset)
[ ( [ PIPE, HARDWARE ] , BANGSTICK )
, ( [ LONGPIPE, HARDWARE ] , BANGCANE )
, ( [ VERYLONGPIPE, HARDWARE ] , BANGROD )
, ( [ PIPE, PIPE ] , LONGPIPE )
, ( [ LONGPIPE, PIPE ] , VERYLONGPIPE )
]