Setup.hs import Distribution.Simple main = defaultMain package.yaml name: XXXXXXXXXXrummy version: XXXXXXXXXX github: "githubuser/rummy" license: XXXXXXXXXXBSD3 author: "Tim Dwyer and Arthur Mahéo"...

making a card game in haskell programming language, pdf explains everything and code bundle to start sent also


Setup.hs import Distribution.Simple main = defaultMain package.yaml name: rummy version: 0.1.0.0 github: "githubuser/rummy" license: BSD3 author: "Tim Dwyer and Arthur Mahéo" maintainer: "[email protected]" copyright: "2020 Tim Dwyer and Arthur Mahéo" extra-source-files: [] # Metadata used when publishing your package # synopsis: Short description of your package # category: Web # To avoid duplicated efforts in documentation and dealing with the # complications of embedding Haddock markup inside cabal files, it is # common to point users to the README.md file. description: Please see the README on Github at dependencies: - base >= 4.7 && < 5="" -="" random="" -="" mtl="" -="" cassava="" -="" bytestring="" -="" vector="" -="" time="" -="" filepath="" -="" directory="" -="" utility-ht="" -="" containers="" -="" deepseq="" library:="" source-dirs:="" src="" default-extensions:="" -="" trustworthy="" -="" namedfieldpuns="" executables:="" staticgame:="" main:="" main.hs="" source-dirs:="" -="" staticgame="" -="" submission="" ghc-options:="" -="" -wall="" -="" -wno-trustworthy-safe="" -="" -wno-orphans="" -="" -wno-unused-imports="" dependencies:="" -="" rummy="" default-extensions:="" -="" trustworthy="" -="" namedfieldpuns="" src/cards.hs="" --="" |="" implement="" the="" card-related="" types="" and="" helper="" functions="" module="" cards="" where="" import="" control.deepseq="" --="" |="" the="" four="" base="" suits="" data="" suit="Spade" |="" club="" |="" diamond="" |="" heart="" deriving="" (eq,="" ord,="" enum,="" bounded)="" data="" rank="Ace" |="" two="" |="" three="" |="" four="" |="" five="" |="" six="" |="" seven="" |="" eight="" |="" nine="" |="" ten="" |="" jack="" |="" queen="" |="" king="" deriving="" (eq,="" ord,="" enum,="" bounded)="" --="" |="" a="" card="" is="" a="" suit="" and="" a="" rank="" data="" card="Card" suit="" rank="" deriving="" (eq)="" instance="" nfdata="" card="" where="" rnf="rwhnf" instance="" ord="" card="" where="" compare="" (card="" s1="" r1)="" (card="" s2="" r2)="" |="" s1="=" s2="compare" r1="" r2="" |="" otherwise="compare" s1="" s2="" src/deck.hs="" module="" deck="" where="" import="" cards="" import="" control.monad="" import="" data.list="" import="" system.random="" --="" |="" we="" deal="" each="" hand="" from="" a="" new="" deck.="" hands="" can="" be="" any="" size="" as="" long="" as="" we="" --="" have="" enough="" cards="" in="" the="" deck="" for="" each="" player="" data="" deck="Deck" {="" handsize="" ::="" int,="" deck="" ::="" [card]="" }="" --="" |="" deal="" n="" cards="" each="" to="" m="" players.="" deal="" ::="" int="" -=""> Int -> [Card] -> [[Card]] deal n m = take m . map (take n) . iterate (drop n) sortedDeck :: [Card] sortedDeck = Card <$> [Spade ..] <*> [Ace ..] shuffleList :: [a] -> IO [a] shuffleList l = do i <- replicatem="" (length="" l)="" (randomio="" ::="" io="" int)="" return="" $="" map="" snd="" $="" sorton="" fst="" $="" zip="" i="" l="" shuffleddeck="" ::="" io="" [card]="" shuffleddeck="shuffleList" sorteddeck="" src/eitherio.hs="" --="" |="" monad="" transformer="" for="" either="" and="" io,="" thanks="" to:="" --="" https://github.com/kqr/gists/blob/master/articles/gentle-introduction-monad-transformers.md#using="" module="" eitherio="" (="" eitherio(..),="" lifteither,="" liftio="" )="" where="" import="" control.applicative="" (lifta2)="" newtype="" eitherio="" e="" a="EitherIO{runEitherIO" ::="" io="" (either="" e="" a)}="" instance="" functor="" (eitherio="" e)="" where="" fmap="" f="EitherIO" .="" fmap="" (fmap="" f)="" .="" runeitherio="" instance="" applicative="" (eitherio="" e)="" where="" pure="EitherIO" .="" return="" .="" right="" f=""><*> x = EitherIO $ liftA2 (<*>) (runEitherIO f) (runEitherIO x) instance Monad (EitherIO e) where return = pure x >>= f = EitherIO $ runEitherIO x >>= either (return . Left) (runEitherIO . f) liftEither :: Either e a -> EitherIO e a liftEither x = EitherIO (return x) liftIO :: IO a -> EitherIO e a liftIO x = EitherIO (fmap Right x) src/Parser/Instances.hs -- | Instances for the parser-combinator Parser module Parser.Instances where import qualified Numeric as N data ParseError = UnexpectedEof | ExpectedEof Input | UnexpectedChar Char | UnexpectedString String deriving (Eq, Show) data ParseResult a = Error ParseError | Result Input a deriving Eq type Input = String newtype Parser a = P { parse :: Input -> ParseResult a} -- Result Instances instance Show a => Show (ParseResult a) where show (Result i a) = "Result >" ++ i ++ "< "="" ++="" show="" a="" show="" (error="" unexpectedeof)="Unexpected end of stream" show="" (error="" (unexpectedchar="" c))="Unexpected character: " ++="" show="" [c]="" show="" (error="" (unexpectedstring="" s))="Unexpected string: " ++="" show="" s="" show="" (error="" (expectedeof="" i))="Expected end of stream, but got >" ++="" show="" i="" ++=""><" instance="" functor="" parseresult="" where="" fmap="" f="" (result="" i="" a)="Result" i="" (f="" a)="" fmap="" _="" (error="" e)="Error" e="" --="" parser="" instances="" instance="" functor="" parser="" where="" fmap="" f="" (p="" p)="P" (fmap="" f="" .="" p)="" instance="" applicative="" parser="" where="" --="" creates="" a="" parser="" that="" always="" succeeds="" with="" the="" given="" input="" pure="" x="P" (`result`="" x)=""><*>) p q = p >>= (\f -> q >>= (pure . f)) instance Monad Parser where (>>=) (P p) f = P ( \i -> case p i of Result rest x -> parse (f x) rest Error e -> Error e) -- Support functions isErrorResult :: ParseResult a -> Bool isErrorResult (Error _) = True isErrorResult _ = False readFloats :: (RealFrac a) => String -> Maybe (a, String) readFloats str = case N.readSigned N.readFloat str of ((a, s):_) -> Just (a, s) _ -> Nothing readHex :: (Num a, Eq a) => String -> Maybe (a, String) readHex str = case N.readHex str of ((a, s): _) -> Just (a, s) _ -> Nothing readInt :: String -> Maybe (Int, String) readInt s = case reads s of [(x,rest)] -> Just (x,rest) _ -> Nothing src/Parser/Parser.hs -- | Parser combinator. module Parser.Parser where import Parser.Instances -- | Produces a parser that always fails with 'UnexpectedChar' using the given -- character. unexpectedCharParser :: Char -> Parser a unexpectedCharParser = P . const . Error . UnexpectedChar -- | Return a parser that produces the given character but fails if: -- * the input is empty; or -- * the produced character is not equal to the given character. -- >>> parse (is 'c') "c" -- Result >< 'c'="" --="">>> isErrorResult (parse (is 'c') "") -- True -- >>> isErrorResult (parse (is 'c') "b") -- True is :: Char -> Parser Char is c = do v <- character="" let="" next="if" v="=" c="" then="" pure="" else="" const="" $="" unexpectedcharparser="" v="" next="" c="" --="" |="" return="" a="" parser="" that="" succeeds="" with="" a="" character="" off="" the="" input="" or="" fails="" with="" --="" an="" error="" if="" the="" input="" is="" empty.="" --="">>> parse character "abc" -- Result >bc< 'a'="" --="">>> isErrorResult (parse character "") -- True character :: Parser Char character = P parseit where parseit "" = Error UnexpectedEof parseit (c:s) = Result s c -- | Return a parser that tries the first parser for a successful value, then: -- * if the first parser succeeds then use this parser; or -- * if the first parser fails, try the second parser. -- -- >>> parse (character ||| pure 'v') "" -- Result >< 'v'="" --="">>> parse (failed UnexpectedEof ||| pure 'v') "" -- Result >< 'v'="" --="">>> parse (character ||| pure 'v') "abc" -- Result >bc< 'a'="" --="">>> parse (failed UnexpectedEof ||| pure 'v') "abc" -- Result >abc< 'v'="" (|||)="" ::="" parser="" a="" -=""> Parser a -> Parser a p1 ||| p2 = P (\i -> let f (Error _) = parse p2 i f r = r in f $ parse p1 i) -- chain p op parses 1 or more instances of p -- separated by op -- (see chainl1 from Text.Parsec) chain :: Parser a -> Parser (a->a->a) -> Parser a chain p op = p >>= rest where rest a = (do f <- op="" b=""><- p="" rest="" (f="" a="" b)="" )="" |||="" pure="" a="" src/rummy/play.hs="" --="" |="" module="" to="" play="" a="" round="" of="" rummy.="" --="" --="" distribute="" 10="" cards="" to="" each="" player,="" they="" then="" have="" to="" draw/discard="" every="" turn="" --="" until="" they="" have="" formed="" all="" their="" cards="" into="" melds.="" module="" rummy.play="" where="" --="" system="" import="" system.timeout="" import="" data.list="" import="" data.maybe="" import="" control.deepseq="" --="" tournament="" import="" cards="" import="" deck="" import="" eitherio="" --="" game="" used="" import="" rummy.rules="" import="" rummy.types="" --="" play="" game="" --="" |="" play="" out="" a="" full="" game,="" then="" update="" the="" players.="" playgame="" ::="" int="" --="" ^="" max="" score="" for="" the="" game="" -=""> [Player]
Oct 18, 2021FIT2102Monash University
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here