From a7ba9e2c6706ca93cbdb8f8986fb90e814ad6fb8 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Tue, 24 May 2016 11:58:56 -0500 Subject: chi peng kang --- src/Mahjong/Tile.hs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/Mahjong/Tile.hs') 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 + + -- cgit v1.2.3-70-g09d2