diff options
Diffstat (limited to 'src/Mahjong/Pai.hs')
-rw-r--r-- | src/Mahjong/Pai.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Mahjong/Pai.hs b/src/Mahjong/Pai.hs new file mode 100644 index 0000000..08115e9 --- /dev/null +++ b/src/Mahjong/Pai.hs @@ -0,0 +1,30 @@ +module Pai where + +import Data.Char (toUpper) + +data MCol = Man | Pin | Sou | Cha + deriving (Eq,Ord) +data MCard = MCard MCol Int + deriving (Eq,Ord) + +charMcol = [(Man,'M'),(Pin,'P'),(Sou,'S'),(Cha,'C')] +instance Show MCol where + show x = [snd a | a <-charMcol, fst a == x] + +instance Read MCol where + readsPrec p r = [(fst a,t)|(c,t) <- lex r, a <- charMcol, map toUpper c == [snd a]] + +instance Show MCard where + show (MCard a b) = show b ++ show a + +instance Read MCard where + readsPrec p r = [ (MCard col n,u) | (c1,t)<- lex r, + let n = (read c1)::Int, + (c2,u) <-lex t, + let col=(read c2)::MCol] + +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) + + |