hannah/src/AI.hs

22 lines
632 B
Haskell

{-# LANGUAGE NamedFieldPuns #-}
module AI (
move
) where
import Data.Map ((!))
import Hanafuda (cardsOfPack, sameMonth)
import Hanafuda.Player (Player(..), Players(..))
import Hanafuda.KoiKoi (GameBlueprint(..), Move(..), PlayerKey, Step(..))
import Hanafuda.Message (PublicGame)
move :: PlayerKey -> PublicGame -> Move
move me (Game {step = ToPlay, players = Players p}) =
Play . head . cardsOfPack . hand $ p ! me
move me (Game {step = Turned card, river}) =
Choose . last . cardsOfPack $ sameMonth card river
where
last [] = error "Empty list"
last [x] = x
last (x:xs) = last xs
move me _ = KoiKoi True