summaryrefslogtreecommitdiff
path: root/src/Mahjong/Tile.hs
diff options
context:
space:
mode:
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
+
+