-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStructs.hs
More file actions
59 lines (54 loc) · 2.48 KB
/
Copy pathStructs.hs
File metadata and controls
59 lines (54 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Structs ( Card(..), User(..), Turn(..), Game(..) ) where
import Data.Map
import System.Random
import System.IO
-- data structure representing a single card in the game
-- cost - the cost to buy this card from the store
-- valu - the amount of gold this card provides when left unused in the hand
-- desc - a human-readable description of the card's behaviour
-- vps - a function that takes the ending game state and produces the number
-- of victory points this card is worth. The user who owns this card
-- will be the "active" (turn) user in the game state
-- func - a function that takes the game state and produces an IO Game, which
-- (maybe) interacts with the users to apply the effect of the card,
-- producing the new game state
data Card = Card { cost :: Int
, valu :: Int
, vps :: Either Int (Game -> Int)
, func :: Maybe (Game -> IO Game)
, desc :: String
}
instance Show Card where
show (Card c v _ _ d) = "Card("++ show c ++","++ show v ++": "++ d ++")"
-- name - the name of the user
-- hand - a list of the cards in the user's hand
-- deck - a list of the cards in the user's deck
-- disc - a list of the cards in the user's discard pile
-- io - handles to talk to the user; (toUser, fromUser)
data User = User { name :: String
, hand :: [String]
, deck :: [String]
, disc :: [String]
, io :: (Handle, Handle)
} deriving (Show)
-- user - the index of the user whose turn it is in the users field of Game
-- buys - the number of buys in the current turn
-- gold - the amount of bonus gold in the current turn
-- acts - the number of free actions in the current turn
data Turn = Turn { user :: Int
, buys :: Int
, gold :: Int
, acts :: Int
} deriving (Show)
-- cards - a dictionary mapping names of cards in this game to Cards
-- amounts - a dictionary mapping names of cards in this game to the current
-- size of their shop piles
-- users - a list of the players in this game, ordered by turn order
-- turn - the state of the current turn
-- rand - a random number generator
data Game = Game { cards :: Map String Card
, amounts :: Map String Int
, users :: [User]
, turn :: Turn
, rand :: StdGen
} deriving (Show)