From 515573665ad2e94cf3aacd045e6a70f3fc637310 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Mon, 28 Sep 2015 16:07:41 -0600 Subject: commit from git, default --- src/Mahjong/Pai.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Mahjong/Pai.hs') diff --git a/src/Mahjong/Pai.hs b/src/Mahjong/Pai.hs index 08115e9..067196e 100644 --- a/src/Mahjong/Pai.hs +++ b/src/Mahjong/Pai.hs @@ -1,6 +1,9 @@ module Pai where import Data.Char (toUpper) +import Data.List (sort) +import Data.Maybe +import Control.Monad data MCol = Man | Pin | Sou | Cha deriving (Eq,Ord) @@ -27,4 +30,13 @@ isCha c@(MCard col n) = (col == Cha) isLaoTou c@(MCard col n) = ((n == 1) || (n == 9)) && (not $ isCha c) is19 c@(MCard col n) = (isCha c) || (isLaoTou c) +orderedPai = sort $ [MCard c n | c<-[Man,Pin,Sou], n <-[1..9]] ++ (map (MCard Cha) [1..7]) +nextPai p = if xs /= [] then Just $ head xs + else Nothing + where (x:xs) = dropWhile (/= p) orderedPai + +nextPai' p@(MCard c n) = do + nx <- nextPai p + guard ((c /= Cha) && (n /= 9)) + return nx -- cgit v1.2.3-70-g09d2