First attempt at defining the game's states

This commit is contained in:
Sasha 2018-02-04 23:01:42 +01:00
parent ea96530511
commit e7619af640
1 changed files with 14 additions and 7 deletions

View File

@ -30,14 +30,20 @@ data Player = Player {
, scored :: Score
}
data State = State {
data Turn = Player1 | Player2
data Step = PlayACard | ChooseWhichCard | Scored
data Game = Game {
players :: (Player, Player)
, river :: Pack
, deck :: [ Card ]
, player :: Turn
, month :: Flower
, turn :: Bool
, step :: Step
}
data Move = Take (Turn, Card, Card) | Choose (Turn, Card) | KoiKoi Bool
fixed :: (Yaku, Points) -> Pack -> YakuFinder
fixed points indicatorSet pack = if pack == indicatorSet then Just points else Nothing
@ -93,8 +99,8 @@ yakus = foldl (\map -> unionWith (++) map . index) empty [
, ([SakeCup, CampCurtain], fixed (HanamiZake, 5))
]
capture :: State -> Card -> Pack -> (Pack, Score)
capture (State {month}) card pack =
capture :: Game -> Card -> Pack -> (Pack, Score)
capture (Game {month}) card pack =
let newPack = add pack card in
let yakuFinders = (unionWith (++) yakus . index $ tsukiFuda month) ! card in
(newPack, foldl (\score -> foldr (uncurry insert) score . ($newPack)) empty yakuFinders)
@ -104,16 +110,17 @@ foldApply [] init = init
foldApply (f:fs) [x] =
let (a,b) = f x in a : foldApply fs [b]
deal :: IO State
deal :: IO Game
deal = do
shuffled <- shuffle cards
let [hand1,hand2,river,deck] = foldApply (take 3 . repeat $ splitAt 8) [shuffled]
let p1 = Player {hand = packOfCards hand1, captured = packOfCards [], scored = empty}
let p2 = Player {hand = packOfCards hand2, captured = packOfCards [], scored = empty}
return $ State {
return $ Game {
players = (p1, p2)
, river = packOfCards river
, deck
, player = Player1
, month = Pine
, turn = False
, step = PlayACard
}