Add gameID directly into Game data structure

This commit is contained in:
Tissevert 2020-01-13 08:40:38 +01:00
parent ce0f51720a
commit 7a324ee7ef
2 changed files with 7 additions and 3 deletions

View file

@ -32,7 +32,8 @@ import Hanafuda.KoiKoi.Game (
import qualified Hanafuda.KoiKoi.Round as Round (deal, next) import qualified Hanafuda.KoiKoi.Round as Round (deal, next)
import qualified Hanafuda.KoiKoi.Turn as Turn (catch, end, next) import qualified Hanafuda.KoiKoi.Turn as Turn (catch, end, next)
import Control.Monad.Except (MonadError(..)) 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 :: Environment m => Move -> Game -> m Game
play move game@(Game {river, step}) = 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 :: MonadIO m => (PlayerID, PlayerID) -> Mode -> m Game
new (playerA, playerB) mode = do new (playerA, playerB) mode = do
playing <- Player.random players playing <- Player.random players
gameID <- liftIO $ randomIO
Round.deal $ Game { Round.deal $ Game {
mode gameID
, mode
, scores = Player.scores players [0, 0] , scores = Player.scores players [0, 0]
, month = Pine , month = Pine
, players , players

View file

@ -50,7 +50,8 @@ instance IDType Game where
type PlayerTurn = Map PlayerID PlayerID type PlayerTurn = Map PlayerID PlayerID
data Game = Game { data Game = Game {
mode :: Mode gameID :: GameID
, mode :: Mode
, scores :: Scores , scores :: Scores
, month :: Flower , month :: Flower
, nextPlayer :: PlayerTurn , nextPlayer :: PlayerTurn