packages feed

roller 0.1.5 → 0.1.6

raw patch · 3 files changed

+21/−17 lines, 3 files

Files

Roller.hs view
@@ -6,4 +6,9 @@ main = Roller.main  -- Build with:+--+-- Windows: -- ghc -package-db=.cabal-sandbox\x86_64-windows-ghc-7.10.2-packages.conf.d Roller.hs+--+-- Linux:+-- ghc -package-db=.cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d Roller.hs -o roller 
Roller/Core.hs view
@@ -22,29 +22,28 @@ negativeRolls :: Word8 -> Word8 -> IO [Integer] negativeRolls x y = replicateM (fromIntegral x) . negativeRoll $ y -rolls :: [DiceExpression] -> IO [[Integer]]-rolls expressions = foldl (\x y -> (++) <$> x <*> (extractDiceExpressionValue y)) (pure [[]]) expressions+rolls :: [DiceExpression] -> IO [Integer]+rolls expressions = foldl (\x y -> (++) <$> x <*> (extractDiceExpressionValue y)) (pure []) expressions -extractDiceExpressionValue :: DiceExpression -> IO [[Integer]]+extractDiceExpressionValue :: DiceExpression -> IO [Integer] extractDiceExpressionValue expression =   case expression of-    DieTerm x y -> return <$> positiveRolls x y-    AddedDieTerm x y -> return <$> positiveRolls x y-    SubtractedDieTerm x y -> return <$> negativeRolls x y-    ConstantTerm x -> return [[fromIntegral x]]-    AddedConstantTerm x -> return [[fromIntegral x]]-    SubtractedConstantTerm x -> return [[(-1) * (fromIntegral x)]]+    DieTerm x y -> positiveRolls x y+    AddedDieTerm x y -> positiveRolls x y+    SubtractedDieTerm x y -> negativeRolls x y+    ConstantTerm x -> return [fromIntegral x]+    AddedConstantTerm x -> return [fromIntegral x]+    SubtractedConstantTerm x -> return [(-1) * (fromIntegral x)]  rollEm :: CLI (IO ()) rollEm verbose n args = maybe parseFail rollMany (parse input)   where-    input        = concat args-    rollMany     = replicateM_ n . rollOnce-    rollOnce exp = fmap summary (rolls exp) >>= putStrLn--    summary      = if verbose then show else show . sumRolls-    sumRolls     = sum . map sum-    parseFail    = putStrLn $ "Could not parse \"" ++ input ++ "\" as dice expression!"+    input             = concat args+    rollMany          = replicateM_ n . rollOnce+    rollOnce exp      = summary <$> (rolls exp) >>= putStrLn+    summary           = if verbose then showVerbose else show . sum+    showVerbose       = (\x -> (show . sum $ x) ++ " " ++ show x)+    parseFail         = putStrLn $ "Could not parse \"" ++ input ++ "\" as dice expression!"  main :: IO () main = join . withOpts $ rollEm
roller.cabal view
@@ -1,5 +1,5 @@ name:                roller-version:             0.1.5+version:             0.1.6 synopsis:            Playing with applicatives and dice! description:         A basic library and program for simulated rolling of                      polyhedral dice, as would be used in pen and paper RPGs.