summaryrefslogtreecommitdiff
path: root/src/Mahjong/Set.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-08-26 17:19:31 -0600
committerJoe Zhao <ztuowen@gmail.com>2015-08-26 17:19:31 -0600
commite795d3d990937a640a22b15b88eebd2b7beee340 (patch)
treeec367330ae9fa2502d29434c298bb8dad83592ee /src/Mahjong/Set.hs
downloadhmj-e795d3d990937a640a22b15b88eebd2b7beee340.tar.gz
hmj-e795d3d990937a640a22b15b88eebd2b7beee340.tar.bz2
hmj-e795d3d990937a640a22b15b88eebd2b7beee340.zip
fst commit
Diffstat (limited to 'src/Mahjong/Set.hs')
-rw-r--r--src/Mahjong/Set.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Mahjong/Set.hs b/src/Mahjong/Set.hs
new file mode 100644
index 0000000..4c3e799
--- /dev/null
+++ b/src/Mahjong/Set.hs
@@ -0,0 +1,20 @@
+module Set where
+
+import Pai
+import Data.List (sort)
+import Data.Char (isDigit)
+import Data.Either
+
+data MSet = MSet {getMSet:: [MCard]}
+
+instance Show MSet where
+ show xs = fst $ foldr f ("",Nothing) $ sort $ getMSet xs
+ where f (MCard col n) (o,p) = let o' = show n ++ (if Just col == p then ""
+ else show col) ++ o in (o', Just col)
+
+readMSet r = fst $ foldr f ([],Man) $ map g r
+ where g x | isDigit x = Left ((read [x])::Int)
+ | otherwise = Right ((read [x])::MCol)
+ f (Left a) (xs,col) = ((MCard col a):xs,col)
+ f (Right a) (xs,col) = (xs,a)
+