hannah/src/AI.hs

22 lines
632 B
Haskell
Raw Normal View History

{-# 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(..))
2019-08-19 18:48:11 +02:00
import Hanafuda.Message (PublicGame)
2019-08-19 18:48:11 +02:00
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