summaryrefslogtreecommitdiff
path: root/src/Mahjong/Hand.hs
blob: f58b6027608bc34daddebd6c4b296ab1187e83cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Hand where

import Set
import Pai
import Data.List (sort)
import Data.Maybe

data Hand = Hand {getHand::MSet, getCall::[MSet]}

max2Win = 7

pairs c (h:hs) = (if length (filter (==h) hs) >= c then 1 else 0) + (pairs $ filter (/=h) hs)
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)

parseCol xx@(a:b:c:xs) (t,m,p) =
    concat []
parseCol _ r = return r
                                  
normal h = cm = 
    where cm = pairs 2 $ filter isCha h
          cp = (pairs 1 $ filter isCha h) - cm