Skip to content

Commit f167286

Browse files
authored
Update hulib.c
修正部分判断胡不准确bug
1 parent 2605425 commit f167286

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

phzlib_c/hulib.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ int get_shun_huxi_xiao(char* cards);
55
int get_shun_huxi_da(char* cards);
66
int get_shun_huxi_da_without_2_7_10(char* cards, int num);
77

8-
98
int get_huxi(char* cards)
109
{
1110
int huxi = get_kan_huxi(cards);
@@ -27,12 +26,13 @@ int get_huxi(char* cards)
2726

2827
// 带将
2928
int max_huxi = -1;
29+
char tmp_cards[20];
3030
for (int i = 0; i < 20; i++) {
3131
if (cards[i] != 2) continue;
32-
cards[i] = 0;
33-
int other_huxi = get_shun_huxi_xiao(cards);
32+
memcpy(tmp_cards, cards, 20);
33+
tmp_cards[i] -= 2;
34+
int other_huxi = get_shun_huxi_xiao(tmp_cards);
3435
if (other_huxi > max_huxi) max_huxi = other_huxi;
35-
cards[i] = 2;
3636
}
3737

3838
if (max_huxi < 0) return -1;
@@ -79,7 +79,7 @@ int get_shun_huxi_xiao(char* cards) {
7979
if (find) {
8080
find = 0;
8181
int finded = 0;
82-
if (cur_item == 6) {
82+
if (cur_item == 7) {
8383
*(int*)0 = 0;
8484
}
8585
// 找到第一张牌
@@ -112,7 +112,7 @@ int get_shun_huxi_xiao(char* cards) {
112112
// 顺子
113113
if (items[cur_item].i == 0) {
114114
items[cur_item].i = 1;
115-
if (cur_card < 8 && cards[cur_card + 1] > 0 && cards[cur_card + 1] > 0) {
115+
if (cur_card < 8 && cards[cur_card + 1] > 0 && cards[cur_card + 2] > 0) {
116116
items[cur_item].j = 1;
117117
items[cur_item].card = cur_card;
118118
--cards[cur_card];
@@ -129,7 +129,7 @@ int get_shun_huxi_xiao(char* cards) {
129129
// 小小大绞
130130
if (items[cur_item].i == 1) {
131131
items[cur_item].i = 2;
132-
if (cards[cur_card + 1] >= 2 && cards[cur_card + 10] >= 1) {
132+
if (cards[cur_card] == 2 && cards[cur_card + 10] >= 1) {
133133
items[cur_item].j = 2;
134134
cards[cur_card] -= 2;
135135
--cards[cur_card + 10];
@@ -141,7 +141,7 @@ int get_shun_huxi_xiao(char* cards) {
141141
// 大大小绞
142142
if (items[cur_item].i == 2) {
143143
items[cur_item].i = 3;
144-
if (cards[cur_card + 10] >= 2) {
144+
if (cards[cur_card + 10] == 2) {
145145
items[cur_item].j = 3;
146146
cards[cur_card+10] -= 2;
147147
--cards[cur_card];
@@ -166,11 +166,13 @@ int get_shun_huxi_xiao(char* cards) {
166166
}
167167

168168
huisu: // 回溯
169-
if (cur_item == 0) break;
169+
if (cur_item < 0) goto finish;
170170

171-
if (items[cur_item].i == 0 || items[cur_item].i == 4) {
171+
if (items[cur_item].i == 0 || (items[cur_item].i == 4 && items[cur_item].j != 4)) {
172172
memset(&items[cur_item], 0, sizeof(struct Item));
173+
if (cur_item == 0) goto finish;
173174
--cur_item;
175+
goto huisu;
174176
}
175177

176178
cur_card = items[cur_item].card;
@@ -193,9 +195,14 @@ int get_shun_huxi_xiao(char* cards) {
193195
++cards[1];
194196
++cards[6];
195197
++cards[9];
198+
memset(&items[cur_item], 0, sizeof(struct Item));
199+
if (cur_item == 0) goto finish;
200+
--cur_item;
201+
goto huisu;
196202
}
197203
}
198204
}
205+
finish:
199206

200207
return max_huxi;
201208
}
@@ -223,16 +230,22 @@ int get_shun_huxi_da(char* cards) {
223230
int max_huxi = -1;
224231

225232
for (int i = 0; i < 5; ++i) {
226-
if (cards[11] < i || cards[16] < i || cards[19] < i) {
233+
memcpy(tmp_cards, &cards[10], 10);
234+
tmp_cards[0] = 0;
235+
tmp_cards[1] -= n_123;
236+
tmp_cards[2] -= n_123;
237+
if (tmp_cards[1] < i || tmp_cards[6] < i || tmp_cards[9] < i) {
227238
break;
228239
}
240+
229241
int huxi = get_shun_huxi_da_without_2_7_10(tmp_cards, i);
230242
if (huxi < 0) continue;
231243
if (huxi + n_123 * 6 > max_huxi) max_huxi = huxi + n_123 * 6;
232244
}
233245
return max_huxi;
234246
}
235247

248+
//
236249
int get_shun_huxi_da_without_2_7_10(char* cards, int num)
237250
{
238251
char tmp_cards[10];

0 commit comments

Comments
 (0)