summaryrefslogtreecommitdiff
path: root/src/Mahjong/Set.hs
blob: 555806e89306cd0c7399de2ebcbb44c21e06ac4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Mahjong.Set where

import Mahjong.Tile
import Data.List (sort)
import Data.Char (isDigit)
import Data.Either

type MSet = [MTile]

showMSet xs = fst $ foldr f ("",Nothing) $ sort xs
    where f (MTile 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) = ((MTile col a):xs,col)
          f (Right a) (xs,col) = (xs,a)