summaryrefslogtreecommitdiff
path: root/src/Mahjong/Hand.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mahjong/Hand.hs')
-rw-r--r--src/Mahjong/Hand.hs13
1 files changed, 13 insertions, 0 deletions
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)