diff options
Diffstat (limited to 'src/Mahjong/Pai.hs')
-rw-r--r-- | src/Mahjong/Pai.hs | 12 |
1 files changed, 12 insertions, 0 deletions
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 |