diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-09-28 16:07:41 -0600 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-09-28 16:07:41 -0600 |
commit | 515573665ad2e94cf3aacd045e6a70f3fc637310 (patch) | |
tree | 692ee5ed6e6f008862c6af204e1e5cdc301d334b /src/Mahjong/Pai.hs | |
parent | e795d3d990937a640a22b15b88eebd2b7beee340 (diff) | |
download | hmj-515573665ad2e94cf3aacd045e6a70f3fc637310.tar.gz hmj-515573665ad2e94cf3aacd045e6a70f3fc637310.tar.bz2 hmj-515573665ad2e94cf3aacd045e6a70f3fc637310.zip |
commit from git, default
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 |