packages feed

general-games 1.0.4 → 1.0.5

raw patch · 3 files changed

+26/−4 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Game.Implement.Card: draw_ :: Card c => [Int] -> [c] -> Maybe [[c]]
+ Game.Implement.Card.Standard: instance GHC.Read.Read Game.Implement.Card.Standard.PlayingCard
+ Game.Implement.Card.Standard: instance GHC.Read.Read Game.Implement.Card.Standard.Rank
+ Game.Implement.Card.Standard: instance GHC.Read.Read Game.Implement.Card.Standard.Suit
- Game.Implement.Card: class (Enum c, Eq c, Ord c, Bounded c) => Card c where choose 0 _ = [[]] choose n lst = do { (x : xs) <- tails lst; rest <- choose (n - 1) xs; return $ x : rest } fullDeck = [minBound .. maxBound] dedupe l = nub l shuffle deck = shuffleM deck randomCard = let minB = minBound :: (Bounded c, Card c) => c maxB = maxBound :: (Bounded c, Card c) => c in do { randomd <- getRandomR (fromEnum minB, fromEnum maxB); return $ toEnum randomd } draw handSizeLst deck | let total = (foldl1' (+) handSizeLst) anyNeg = (length (filter (\ n -> n < 0) handSizeLst)) > 0 in (total > (length deck)) || (total < 1) || anyNeg = Nothing | otherwise = let draw2 [] (houtput, doutput) = ((reverse houtput), doutput) draw2 (nToTake : hst) (handOutput, deckOutput) = let newHand = take nToTake deckOutput newDeck = drop nToTake deckOutput in draw2 hst (newHand : handOutput, newDeck) in Just (draw2 handSizeLst ([], deck)) draw1 handSize deck = let f (Just ([h], d)) = Just (h, d) f _ = Nothing in f $ draw [handSize] deck draw1_ handSize deck = let f (Just ([h], _)) = Just h f _ = Nothing in f $ draw [handSize] deck
+ Game.Implement.Card: class (Enum c, Eq c, Ord c, Bounded c) => Card c where choose 0 _ = [[]] choose n lst = do { (x : xs) <- tails lst; rest <- choose (n - 1) xs; return $ x : rest } fullDeck = [minBound .. maxBound] dedupe l = nub l shuffle deck = shuffleM deck randomCard = let minB = minBound :: (Bounded c, Card c) => c maxB = maxBound :: (Bounded c, Card c) => c in do { randomd <- getRandomR (fromEnum minB, fromEnum maxB); return $ toEnum randomd } draw handSizeLst deck | let total = (foldl1' (+) handSizeLst) anyNeg = (length (filter (\ n -> n < 0) handSizeLst)) > 0 in (total > (length deck)) || (total < 1) || anyNeg = Nothing | otherwise = let draw2 [] (houtput, doutput) = ((reverse houtput), doutput) draw2 (nToTake : hst) (handOutput, deckOutput) = let newHand = take nToTake deckOutput newDeck = drop nToTake deckOutput in draw2 hst (newHand : handOutput, newDeck) in Just (draw2 handSizeLst ([], deck)) draw_ handSizes deck = let f (Just (h, _)) = Just h f _ = Nothing in f $ draw handSizes deck draw1 handSize deck = let f (Just ([h], d)) = Just (h, d) f _ = Nothing in f $ draw [handSize] deck draw1_ handSize deck = let f (Just ([h], _)) = Just h f _ = Nothing in f $ draw [handSize] deck

Files

general-games.cabal view
@@ -1,5 +1,5 @@ name:                general-games-version:             1.0.4+version:             1.0.5 synopsis:            Library supporting simulation of a number of games homepage:            https://github.com/cgorski/general-games bug-reports:         https://github.com/cgorski/general-games/issues
src/Game/Implement/Card.hs view
@@ -58,9 +58,16 @@   -- >>> draw [2,2,2,5] deck   -- Just ([[Ace of Spades,Jack of Spades],[Queen of Hearts,Seven of Clubs],[Jack of Diamonds,Six of Hearts],[Jack of Hearts,Five of Spades,Three of Spades,Two of Diamonds,Ace of Hearts]],[Four of Clubs,Six of Diamonds,Four of Diamonds,Eight of Spades,Six of Clubs,Seven of Spades,Three of Diamonds,Ten of Diamonds,Eight of Hearts,Nine of Diamonds,Three of Clubs,Six of Spades,King of Clubs,Nine of Clubs,Four of Spades,Five of Diamonds,Nine of Spades,Queen of Spades,Ace of Diamonds,Four of Hearts,Two of Clubs,Five of Clubs,Two of Hearts,King of Diamonds,Ten of Spades,Eight of Clubs,Seven of Hearts,Three of Hearts,Queen of Diamonds,Queen of Clubs,Ten of Clubs,King of Hearts,Eight of Diamonds,Jack of Clubs,Ten of Hearts,Seven of Diamonds,Two of Spades,Nine of Hearts,King of Spades,Ace of Clubs,Five of Hearts])   draw :: [Int] -> [c] -> Maybe ([[c]],[c])-      -- |+  -- The same as 'draw', except throw away the deck+  --+  -- >>> deck <- evalRandIO $ shuffle $ (fullDeck :: [PlayingCard])+  -- >>> draw_ [2,2,2,5] deck+  -- Just [[Eight of Hearts,Queen of Hearts],[Two of Clubs,Seven of Diamonds],[Ten of Clubs,Three of Hearts],[Ace of Spades,Nine of Spades,Five of Spades,Four of Diamonds,Two of Spades]]+  draw_ :: [Int] -> [c] -> Maybe [[c]]+  +  -- |   -- The same as 'draw', except draw only one hand of specified size.   --   -- >>> deck <- evalRandIO $ shuffle $ (fullDeck :: [PlayingCard])@@ -116,6 +123,12 @@             draw2 hst (newHand:handOutput, newDeck)         in Just (draw2 handSizeLst ([],deck)) +  draw_ handSizes deck =+    let f (Just (h, _)) = Just h+        f _ = Nothing+    in+      f $ draw handSizes deck+     draw1 handSize deck =     let       f (Just ([h], d)) = Just (h,d)
src/Game/Implement/Card/Standard.hs view
@@ -51,7 +51,7 @@   Queen |   King -  deriving (Show, Enum, Eq, Ord, Bounded)+  deriving (Show, Enum, Eq, Ord, Bounded, Read)  -- | -- Returns a random standard playing card rank, with Ace low.@@ -89,7 +89,7 @@   Diamonds |   Hearts |   Spades-  deriving (Show, Enum, Eq, Ord, Bounded)+  deriving (Show, Enum, Eq, Ord, Bounded, Read)  -- | -- Returns a random Suit.@@ -167,6 +167,15 @@  instance Show PlayingCard where   show (PlayingCard r s) = (show r) ++ " of " ++ (show s)++instance Read PlayingCard where+  readsPrec _ input =+      [(PlayingCard r s,v) |+       (rs, t) <- lex input,+       (r, _) <- reads rs,+       ("of",u) <- lex t,+       (s, v) <- reads u]+  instance ValuedCard PlayingCard Rank where   toValue (PlayingCard r _) = r