summaryrefslogtreecommitdiff
path: root/src/Mahjong/Tile.hs
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-05-24 11:58:56 -0500
committerTuowen Zhao <ztuowen@gmail.com>2016-05-24 11:58:56 -0500
commita7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8 (patch)
treea819a538301e320a254c7debdbb4d68a739393c4 /src/Mahjong/Tile.hs
parent27d29076135ab9bb8903c9d64b0988c3b366844d (diff)
downloadhmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.tar.gz
hmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.tar.bz2
hmj-a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8.zip
chi peng kangHEADmaster
Diffstat (limited to 'src/Mahjong/Tile.hs')
-rw-r--r--src/Mahjong/Tile.hs21
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
+
+