diff options
Diffstat (limited to 'src/Mahjong')
-rw-r--r-- | src/Mahjong/.Pai.hs.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | src/Mahjong/Hand.hs | 13 | ||||
-rw-r--r-- | src/Mahjong/Pai.hs | 12 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/Mahjong/.Pai.hs.swp b/src/Mahjong/.Pai.hs.swp Binary files differnew file mode 100644 index 0000000..38b9c97 --- /dev/null +++ b/src/Mahjong/.Pai.hs.swp diff --git a/src/Mahjong/Hand.hs b/src/Mahjong/Hand.hs index 1d1bb80..f58b602 100644 --- a/src/Mahjong/Hand.hs +++ b/src/Mahjong/Hand.hs @@ -2,6 +2,8 @@ module Hand where import Set import Pai +import Data.List (sort) +import Data.Maybe data Hand = Hand {getHand::MSet, getCall::[MSet]} @@ -13,6 +15,17 @@ pairs c [] = 0 seven h = 7 - (pairs 1 h) mosou h = 14 - (pairs 0 h') - (if pairs 1 h' > 0 then 1 else 0) where h' = filter is19 h +normal h = maxmum $ map getSteps $ normal' (0,0,0) (0,0,0) (head orderedPai) $ sort $ h + where getSteps (p,w,m) = --pairs, waits, mianzi + (if p == 0 then 1 else 0) + + (min w' 4)+2*(max 0 (4-w'-m)) + where w' = (+) w $ max 0 (p-1) + +normal' (a,b,c) (p,w,m) cur (h:hs) + | cur == h = normal' (a,b,c+1) (p,w,m) cur hs + | a + b + c < 2 = -- TODO return + | a < 1 = if nextPai' cur == Nothing + then normal' (b,c,0) cur hs costM a b = (sum $ zipWith (snd.sMmin) a b,zipWith (fst.sMmin) a b) sMmin a b = if (a>b) then (a-b,0) else (0,b-a) diff --git a/src/Mahjong/Pai.hs b/src/Mahjong/Pai.hs index 08115e9..067196e 100644 --- a/src/Mahjong/Pai.hs +++ b/src/Mahjong/Pai.hs @@ -1,6 +1,9 @@ module Pai where import Data.Char (toUpper) +import Data.List (sort) +import Data.Maybe +import Control.Monad data MCol = Man | Pin | Sou | Cha deriving (Eq,Ord) @@ -27,4 +30,13 @@ 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) +orderedPai = sort $ [MCard c n | c<-[Man,Pin,Sou], n <-[1..9]] ++ (map (MCard Cha) [1..7]) +nextPai p = if xs /= [] then Just $ head xs + else Nothing + where (x:xs) = dropWhile (/= p) orderedPai + +nextPai' p@(MCard c n) = do + nx <- nextPai p + guard ((c /= Cha) && (n /= 9)) + return nx |