forked from yuanfengyun/q_algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
麻将胡牌算法
120 lines (62 loc) · 2.73 KB
/
麻将胡牌算法
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# qipai
棋牌的胡牌算法
麻将的胡牌算法
文档 github地址 https://github.com/yuanfengyun/mj_server/tree/master/doc
lua版 https://github.com/yuanfengyun/mj_server/tree/master/mjlib
c++版 https://github.com/yuanfengyun/mj_server/tree/master/mjguiclib
golang版 https://github.com/yuanfengyun/mj_server/tree/master/mjgolib
js版 https://github.com/yuanfengyun/mj_server/tree/master/mj-js-hulib
c#版 https://github.com/yuanfengyun/mj_server/tree/master/mjlib_c%23
原理:
mjlib胡牌思路 注意:带鬼牌
1、统计牌中鬼牌个数 nGui,将鬼牌从牌数据中去除
2、不同花色分开处理,分别校验是否能满足 将、顺子、刻子
3、分析东南西北风中发白时,不需要分析顺子的情况,简单很多
4、分析单一花色时,直接根据1-9点对应数字得出一个9位
的整数,每位上为0-4代表该点数上有几张牌
比如:1筒2筒3筒3筒3筒3筒6筒7筒8筒2万3万3万3万4万
数字:筒: 1,1,4,0,0,1,1,1,0 得出的数字为114001110
万 0,1,3,1,0,0,0,0,0 得出的数字为13100000
每种花色与赖子组合,如果所有花色都能配型成功则可胡牌
检查配型时,每种花色的牌数量必需是3*n 或者 3*n + 2
根据赖子个数、带不带将,查找对应表,看能否满足胡牌
表的产生:
1、穷举筒、万两种花色的胡牌可能,将对应的牌型记录为数字(如上面的根据花色点数内容生成数字, 3*n的放入不带将的表,3*n+2的放入带将表)
2、1张鬼牌表是根据穷举不带鬼的表,去除1个牌以后形成的数字
3、2张鬼牌表是根据穷举不带鬼的表,去除2个牌以后形成的数字
4、3张鬼牌表是根据穷举不带鬼的表,去除3个牌以后形成的数字
5、4张鬼牌表是根据穷举不带鬼的表,去除4个牌以后形成的数字
字牌表产出:
1、穷举筒、字两个牌型的胡牌可能,将对应的牌型记录为数字(如上面的根据花色点数内容生成数字, 3*n的放入不带将的表,3*n+2的放入带将表)
2,3,4,5,如上
表的举例及规模:
不带鬼 {300000000} {300000002, 300000020, 300000200...}
1鬼 {200000000} {300000001, 200000002,...}
...
总数 18874368
胡 206300
失败 5201520
没有鬼表大小 2867
没有鬼将表大小 18858
1鬼表大小 11639
1鬼将表大小 55234
2鬼表大小 19309
2鬼将表大小 71128
3鬼表大小 18481
3鬼将表大小 58697
4鬼表大小 12234
4鬼将表大小 38630
字牌表规模:
总数 4477456
胡 127044
失败 1569835
没有鬼表大小 99
没有鬼将表大小 399
1鬼表大小 294
1鬼将表大小 945
2鬼表大小 630
2鬼将表大小 1576
3鬼表大小 911
3鬼将表大小 2135
4鬼表大小 1050
4鬼将表大小 2366