From 7a324ee7ef38477cc69e58b06bcffc1f198fba83 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Mon, 13 Jan 2020 08:40:38 +0100 Subject: [PATCH] Add gameID directly into Game data structure --- src/Hanafuda/KoiKoi.hs | 7 +++++-- src/Hanafuda/KoiKoi/Game.hs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Hanafuda/KoiKoi.hs b/src/Hanafuda/KoiKoi.hs index eda2d82..2f7dc98 100644 --- a/src/Hanafuda/KoiKoi.hs +++ b/src/Hanafuda/KoiKoi.hs @@ -32,7 +32,8 @@ import Hanafuda.KoiKoi.Game ( import qualified Hanafuda.KoiKoi.Round as Round (deal, next) import qualified Hanafuda.KoiKoi.Turn as Turn (catch, end, next) import Control.Monad.Except (MonadError(..)) -import Control.Monad.IO.Class (MonadIO) +import Control.Monad.IO.Class (MonadIO(..)) +import System.Random (randomIO) play :: Environment m => Move -> Game -> m Game play move game@(Game {river, step}) = @@ -56,8 +57,10 @@ play move game@(Game {river, step}) = new :: MonadIO m => (PlayerID, PlayerID) -> Mode -> m Game new (playerA, playerB) mode = do playing <- Player.random players + gameID <- liftIO $ randomIO Round.deal $ Game { - mode + gameID + , mode , scores = Player.scores players [0, 0] , month = Pine , players diff --git a/src/Hanafuda/KoiKoi/Game.hs b/src/Hanafuda/KoiKoi/Game.hs index 50b7b00..5b32e72 100644 --- a/src/Hanafuda/KoiKoi/Game.hs +++ b/src/Hanafuda/KoiKoi/Game.hs @@ -50,7 +50,8 @@ instance IDType Game where type PlayerTurn = Map PlayerID PlayerID data Game = Game { - mode :: Mode + gameID :: GameID + , mode :: Mode , scores :: Scores , month :: Flower , nextPlayer :: PlayerTurn