diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-05-24 11:58:56 -0500 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-05-24 11:58:56 -0500 |
commit | a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8 (patch) | |
tree | a819a538301e320a254c7debdbb4d68a739393c4 /src/Mahjong/Tile.hs | |
parent | 27d29076135ab9bb8903c9d64b0988c3b366844d (diff) | |
download | hmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.tar.gz hmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.tar.bz2 hmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.zip |
Diffstat (limited to 'src/Mahjong/Tile.hs')
-rw-r--r-- | src/Mahjong/Tile.hs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Mahjong/Tile.hs b/src/Mahjong/Tile.hs index 05e2f89..b952f48 100644 --- a/src/Mahjong/Tile.hs +++ b/src/Mahjong/Tile.hs @@ -1,4 +1,4 @@ -module Tile where +module Mahjong.Tile where import Data.Char (toUpper) import Data.List (sort) @@ -32,14 +32,21 @@ is19 c@(MTile col n) = (isCha c) || (isLaoTou c) orderedTile = sort $ [MTile c n | c<-[Man,Pin,Sou], n <-[1..9]] ++ (map (MTile Cha) [1..7]) -nextTile p = if xs /= [] then Just $ head xs +nextTile' p tiles = if xs /= [] then Just $ head xs else Nothing - where (x:xs) = dropWhile (/= p) orderedTile + where (x:xs) = dropWhile (/= p) tiles -nextTile' :: Maybe MTile -> Maybe MTile -nextTile' jp = do - p <- jp - nx@(MTile c n) <- nextTile p +nextTile :: Maybe MTile -> Maybe MTile +nextTile jp = do + p@(MTile c n) <- jp guard ((c /= Cha) && (n /= 9)) + nx <- nextTile' p orderedTile return nx +prevTile jp = do + p@(MTile c n) <- jp + guard ((c /= Cha) && (n /= 1)) + nx <- nextTile' p $ reverse orderedTile + return nx + + |