lib/src/Hanafuda/Game.hs

40 lines
860 B
Haskell

{-# LANGUAGE MultiParamTypeClasses #-}
module Hanafuda.Game where
import Data.Map (Map, empty, fromList)
import Hanafuda.Card (Card, Pack, packOfCards)
import Hanafuda.Yaku (Score, Points)
data Player =
Player1
| Player2
deriving (Eq, Ord)
next :: Player -> Player
next Player1 = Player2
next _ = Player1
data PlayerState = PlayerState {
hand :: Pack
, meld :: Pack
, yakus :: Score
}
type Players = Map Player PlayerState
initPlayers :: [Card] -> [Card] -> Players
initPlayers hand1 hand2 =
fromList [(Player1, player hand1), (Player2, player hand2)]
where
player cards = PlayerState {
hand = packOfCards cards
, meld = packOfCards []
, yakus = empty
}
data Move = Play Card | Choose Card | KoiKoi Bool
type Scores = Map Player Points
class Game a b where
play :: a -> Move -> Either String b