Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some more type definitions. mkPlayers-function

  • Loading branch information...
commit e93d3e5ee8fcb74973f2f549d42d32bdb5040b7a 1 parent 7ed7f24
@Detegr authored
Showing with 45 additions and 26 deletions.
  1. +6 −0 src/DML/Game.hs
  2. +31 −22 src/DML/Types.hs
  3. +8 −4 src/Main.hs
View
6 src/DML/Game.hs
@@ -16,6 +16,12 @@ evalDML f s g = fst $ runDML f s g
execDML :: (RandomGen g) => DML g a -> DMLState -> g -> DMLState
execDML f s g = snd $ runDML f s g
+supply :: DMLState -> DMLState
+supply s
+ | deck s == [] = s
+ | otherwise = undefined
+ where c = head (deck s)
+
-- | Rolls two dice and returns the values in a tuple
mkRoll :: (RandomGen g) => DML g (Int, Int)
mkRoll = (,) <$> rollOne <*> rollOne
View
53 src/DML/Types.hs
@@ -12,11 +12,10 @@ module DML.Types(Resource(..),
Event,
mkEvent,
mkDeck,
- mkKings,
- Player(..),
+ mkPlayers,
+ Player,
DMLState(..)) where
-import System.Random (StdGen)
import Data.Default
import Data.Maybe (fromJust)
import Data.Random.RVar
@@ -32,12 +31,12 @@ data Character = MotherOfDragons | Archudess | DragonEmpress | BitchQueen
| TroublesomeBlabbermouth | GoodsSwindler | GrandInquisitor | BoonLiquidator deriving (Show, Eq)
-- | Type representing a card in a DML game
-data Card = Card { resource :: Resource, value :: Int }
- | Guild { resource :: Resource }
- | Character { character :: Character }
- | DragonEgg { resource :: Resource }
+data Card = Card { resource :: Resource, value :: Int }
+ | Guild { resource :: Resource }
+ | Character { character :: Character }
+ | DragonEgg { resource :: Resource }
| Thief
- | King { resource :: Resource } deriving (Show,Eq)
+ | King { resource :: Resource } deriving (Show,Eq)
-- | Type representing a global event type in a DML game
data EventType = Decadence | TaxRelief | Looters | SupplyShortage | ForeignMerchant deriving (Show,Eq)
@@ -51,6 +50,7 @@ data Market = Market { slaves :: [Card]
, iron :: [Card]
, wood :: [Card]
} deriving (Show,Eq)
+
instance Default Market where
def = Market [] [] [] []
@@ -60,12 +60,17 @@ type EventDeck = [Card]
type Treasury = [Card]
type House = [Card]
-data Player = Player { treasury :: Treasury, house :: House, king :: Card } deriving (Show,Eq)
-data DMLState = DMLState { deck :: EventDeck
- , market :: Market
- , bMarket :: BlackMarket
- , loot :: DragonsLoot
- , players :: (Player, Player, Player, Player)
+data Player = Player { treasury :: Treasury
+ , house :: House
+ , king :: Card
+ } deriving (Show,Eq)
+
+data DMLState = DMLState { deck :: EventDeck
+ , market :: Market
+ , bMarkets :: [BlackMarket]
+ , loot :: DragonsLoot
+ , players :: (Player, Player, Player, Player)
+ , event :: Maybe Event
}
-- | Constructs jack Character from a Resource
@@ -112,11 +117,15 @@ mkCard r v
-- | Creates a deck of cards and shuffles it
mkDeck :: RandomSource m DevRandom => m [Card]
mkDeck = do
- let deck = Thief : Thief : [fromJust $ mkCard r v | r <- [Slave,Spice,Iron,Wood], v <- [1..12]]
- runRVar (shuffle deck) DevURandom
-
--- | Creates a deck of kings and shuffles it
-mkKings :: RandomSource m DevRandom => m [Card]
-mkKings = do
- let deck = [fromJust $ mkCard r 13 | r <- [Slave, Spice, Iron, Wood]]
- runRVar (shuffle deck) DevURandom
+ let orderedDeck = Thief : Thief : [fromJust $ mkCard r v | r <- [Slave,Spice,Iron,Wood], v <- [1..12]]
+ runRVar (shuffle orderedDeck) DevURandom
+
+mkPlayer :: Card -> Player
+mkPlayer (King r) = Player [] [] (King r)
+
+-- | Creates a tuple of players
+mkPlayers :: RandomSource m DevRandom => m (Player, Player, Player, Player)
+mkPlayers = do
+ let kingDeck = [fromJust $ mkCard r 13 | r <- [Slave, Spice, Iron, Wood]]
+ kings <- runRVar (shuffle kingDeck) DevURandom
+ return (mkPlayer $ kings !! 0, mkPlayer $ kings !! 1, mkPlayer $ kings !! 2, mkPlayer $ kings !! 3) -- ugly :(
View
12 src/Main.hs
@@ -11,11 +11,15 @@ main :: IO()
main = do
gen <- fmap mkStdGen randomIO
deck <- mkDeck
- kings <- mkKings
+ players <- mkPlayers
print $ deck
- let plr = Player [] [] (kings !! 0)
- let plrs = (plr,plr,plr,plr)
- let initialState=DMLState deck def [] [] plrs
+ let initialState = DMLState { deck = deck
+ , market = def
+ , bMarkets = []
+ , loot = []
+ , players = players
+ , event = Nothing
+ }
let roll=evalDML mkRoll initialState gen
putStrLn $ show roll
Please sign in to comment.
Something went wrong with that request. Please try again.