1
- local mjlib = require " mjlib"
2
1
local table_mgr = require " table_mgr"
3
2
4
- local split_table = {
5
- {min = 1 , max = 9 , chi = true },
6
- {min = 10 , max = 18 , chi = true },
7
- {min = 19 , max = 27 , chi = true },
8
- {min = 28 , max = 34 , chi = false }
9
- }
10
-
11
3
local M = {}
12
- function M .check_7dui (hand_cards , waves )
13
- if # waves > 0 then return false end
14
-
15
- for _ ,c in ipairs (hand_cards ) do
16
- if c % 2 ~= 0 then
17
- return false
18
- end
19
- end
20
-
21
- return true
22
- end
23
-
24
- function M .check_pengpeng ()
25
4
26
- end
27
-
28
- function M .get_hu_info (cards , waves , gui_index )
5
+ function M .get_hu_info (cards , gui_index )
29
6
local hand_cards = {}
30
7
for i ,v in ipairs (cards ) do
31
8
hand_cards [i ] = v
@@ -37,107 +14,53 @@ function M.get_hu_info(cards, waves, gui_index)
37
14
hand_cards [gui_index ] = 0
38
15
end
39
16
40
- local splited_tbl = M .split_info (hand_cards , gui_num )
41
- if not splited_tbl then
42
- return false
43
- end
17
+ return M .check (hand_cards , gui_num )
18
+ end
44
19
45
- return M .check_probability (splited_tbl , gui_num )
20
+ function M .check (cards , gui_num )
21
+ local total_need_gui = 0
22
+ local eye_num = 0
23
+ for i = 0 ,3 do
24
+ local from = i * 9 + 1
25
+ local to = from + 8
26
+ if i == 3 then
27
+ to = from + 6
28
+ end
29
+
30
+ local need_gui , eye = M .get_need_gui (cards , from , to , i == 3 , gui_num )
31
+ if need_gui then
32
+ total_need_gui = total_need_gui + need_gui
33
+ end
34
+ if eye then
35
+ eye_num = eye_num + 1
36
+ end
37
+ end
38
+
39
+ if eye_num == 0 then
40
+ return total_need_gui + 2 <= gui_num
41
+ elseif eye_num == 1 then
42
+ return total_need_gui <= gui_num
43
+ elseif
44
+ return total_need_gui + eye_num - 1 <= gui_num
45
+ end
46
46
end
47
47
48
- function M .list_probability (gui_num , num , key , chi )
49
- local find = false
50
- local t = {}
48
+ function M .get_need_gui (cards , from , to , chi , gui_num )
49
+ local num = 0
50
+ local key = 0
51
+ for i = from ,to do
52
+ key = key * 10 + cards [i ]
53
+ end
54
+
51
55
for i = 0 , gui_num do
52
56
local yu = (num + i )% 3
53
57
if yu ~= 1 then
54
58
local eye = (yu == 2 )
55
- if find or table_mgr :check (key , i , eye , chi ) then
56
- table.insert (t , {eye = eye , gui_num = i })
57
- find = true
58
- end
59
- end
60
- end
61
-
62
- return t
63
- end
64
-
65
- -- 根据花色切分
66
- function M .split_info (t , gui_num )
67
- local ret = {}
68
- for _ ,v in ipairs (split_table ) do
69
- local key = 0
70
- local num = 0
71
- for i = v .min ,v .max do
72
- key = key * 10 + t [i ]
73
- num = num + t [i ]
74
- end
75
- if num > 0 then
76
- local t = M .list_probability (gui_num , num , key , v .chi )
77
- if # t == 0 then
78
- return false
79
- end
80
- table.insert (ret , t )
81
- end
82
- end
83
- return ret
84
- end
85
-
86
- function M .check_probability_sub (splited_table , eye , gui_num , level , max_level )
87
- for _ ,v in ipairs (splited_table [level ]) do
88
- repeat
89
- if eye and v .eye then
90
- break
91
- end
92
-
93
- if gui_num < v .gui_num then
94
- break
95
- end
96
-
97
- if level < max_level then
98
- if M .check_probability_sub (
99
- splited_table ,
100
- eye or v .eye ,
101
- gui_num - v .gui_num ,
102
- level + 1 ,
103
- max_level ) then
104
- return true
105
- end
106
- break
107
- end
108
-
109
- if not eye and not v .eye and gui_num < 2 + v .gui_num then
110
- break
59
+ if table_mgr :check (key , i , eye , chi ) then
60
+ return i , eye
111
61
end
112
-
113
- return true
114
- until (true )
115
- end
116
-
117
- return false
118
- end
119
-
120
- function M .check_probability (splited_table , gui_num )
121
- local c = # splited_table
122
- -- 全是鬼牌
123
- if c == 0 then
124
- return true
125
- end
126
-
127
- -- 只有一种花色的牌和鬼牌
128
- if c == 1 then
129
- return true
130
- end
131
-
132
- -- 组合花色间的组合,如果能满足组合条件,则胡
133
- for i ,v in ipairs (splited_table [1 ]) do
134
- local ret = M .check_probability_sub (splited_table , v .eye , gui_num - v .gui_num , 2 , c )
135
- if ret then
136
- return true
137
62
end
138
63
end
139
-
140
- return false
141
64
end
142
65
143
66
return M
0 commit comments