-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcard_analysis.cc
1869 lines (1677 loc) · 50.5 KB
/
card_analysis.cc
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "card.h"
#include "card_type.h"
#include "card_statistics.h"
#include "card_analysis.h"
static char *card_type_str[] =
{
(char*)"CARD_TYPE_ERROR",
(char*)"CARD_TYPE_ONE",
(char*)"CARD_TYPE_ONELINE",
(char*)"CARD_TYPE_TWO",
(char*)"CARD_TYPE_TWOLINE",
(char*)"CARD_TYPE_THREE",
(char*)"CARD_TYPE_THREELINE",
(char*)"CARD_TYPE_THREEWITHONE",
(char*)"CARD_TYPE_THREEWITHTWO",
(char*)"CARD_TYPE_PLANEWITHONE",
(char*)"CARD_TYPE_PLANEWITHWING",
(char*)"CARD_TYPE_FOURWITHONE",
(char*)"CARD_TYPE_FOURWITHTWO",
(char*)"CARD_TYPE_SOFTBOMB",
(char*)"CARD_TYPE_BOMB",
(char*)"CARD_TYPE_GHOSTBOMB",
(char*)"CARD_TYPE_ROCKET"
};
CardAnalysis::CardAnalysis()
{
ghost_face = 0;
ghost_num = 0;
type = 0;
face = 0;
back_up_face.clear();
back_up_type.clear();
}
/*
@brief 分析牌型
@param anaCards[in] 要分析的牌型
@param set_ghost_face[in] 鬼牌值
*/
CardAnalysis::CardAnalysis(const std::vector<Card> &anaCards, int set_ghost_face)
{
card_stat.statistics(anaCards, set_ghost_face);
do_analysis();
}
/*
@brief 分析牌型
@param anacard_stat[in] 要分析的牌型结构
*/
CardAnalysis::CardAnalysis(const CardStatistics &anacard_stat)
{
card_stat = anacard_stat;
do_analysis();
}
/*
@brief 分析牌型
@param anaCards[in] 要分析的牌型
@param set_ghost_face[in] 鬼牌值
*/
int CardAnalysis::analysis(const std::vector<Card> &anaCards, int set_ghost_face)
{
card_stat.statistics(anaCards, set_ghost_face);
return do_analysis();
}
/*
@brief 分析牌型,只有当CardAnalysis是默认初始化的时候,才需要这个函数来analysis。
@param anacard_stat[in] 要分析的牌型结构
@retur 返回分析的牌型
*/
int CardAnalysis::analysis(const CardStatistics &anacard_stat)
{
card_stat = anacard_stat;
return do_analysis();
}
/*
@breif 查找分析出的牌型中,某个特定牌型的面值
@param expect_type[in] 要查找的牌型
@retur 0表示没有找到特定牌型, 其它值,表示特定牌型的面值
*/
int CardAnalysis::get_card_face_of_type(int expect_type)
{
if (type == expect_type)
{
return face;
}
for (unsigned i = 0; i < back_up_type.size(); ++i)
{
if (back_up_type[i] == expect_type)
{
return back_up_face[i];
}
}
return 0;
}
/*
@breif 比较两个CardAnalysis对象的牌型大小
@param card_ana[in] 要比较的对象card_ana
@retur 如果比card_ana小返回true, 其它情况返回false
*/
bool CardAnalysis::operator<(const CardAnalysis &card_ana) const
{
if (type == 0)
{
return false;
}
if (card_ana.type == 0)
{
return false;
}
if (type == card_ana.type)
{
return face < card_ana.face;
}
else if (type >= CARD_TYPE_SOFTBOMB || card_ana.type >= CARD_TYPE_SOFTBOMB)
{
return type < card_ana.type;
}
return false;
}
/*
@breif 查看牌型是否比某个指定的牌型大
@param anaCards[in] 需要比较的牌型
@param ghost_face[in] 鬼牌
@param ctype[in] 要比较的类型
@param cface[in] 要比较的面值
@retur 如果比card_ana小返回true, 其它情况返回false
*/
bool CardAnalysis::isGreater(const std::vector<Card> &anaCards, int ghost_face, int ctype, int cface, int &ret_type, int &ret_face)
{
if (ctype == 0)
return false;
CardAnalysis card_ana(anaCards, ghost_face);
ret_type = card_ana.type;
ret_face = card_ana.face;
if (card_ana.type == 0)
{
return false;
}
if (ctype >= CARD_TYPE_SOFTBOMB || card_ana.type >= CARD_TYPE_SOFTBOMB) //有炸弹的情况
{
if (card_ana.type == ctype)
{
return card_ana.face > cface;
}
else
{
return card_ana.type > ctype;
}
}
const int find_face = card_ana.get_card_face_of_type(static_cast<CardType>(ctype));
ret_type = ctype;
ret_face = find_face;
if (find_face == 0)
{
return false;
}
return find_face > cface;
}
/*
@breif 查看牌型是否比某个指定的牌型大
@param anaCards[in] 需要比较的牌型
@param ghost_face[in] 鬼牌
@param ctype[in] 要比较的类型
@param cface[in] 要比较的面值
@retur 如果比card_ana小返回true, 其它情况返回false
*/
bool CardAnalysis::isGreater(const std::vector<Card> &anaCards, int ghost_face, int ctype, int cface)
{
if (ctype == 0)
return false;
CardAnalysis card_ana(anaCards, ghost_face);
if (card_ana.type == 0)
{
return false;
}
if (ctype >= CARD_TYPE_SOFTBOMB || card_ana.type >= CARD_TYPE_SOFTBOMB) //有炸弹的情况
{
if (card_ana.type == ctype)
{
return card_ana.face > cface;
}
else
{
return card_ana.type > ctype;
}
}
const int find_face = card_ana.get_card_face_of_type(ctype);
if (find_face == 0)
{
return false;
}
return find_face > cface;
}
//*****************************下面是工具函数*******************************
/*
@brief 分析牌型成员变量card_stat中的牌型
@retur 返回分析的牌型
*/
int CardAnalysis::do_analysis()
{
type = CARD_TYPE_ERROR;
face = 0;
back_up_face.clear();
back_up_type.clear();
len = card_stat.len;
ghost_face = card_stat.ghost_face;
ghost_num = card_stat.ghost_cards.size();
if (len == 0)
{
return type;
}
if (card_stat.has_ghost())
{
return ghost_analysis();
}
if (len == 1)
{
face = card_stat.card1[0].face;
type = CARD_TYPE_ONE;
return type;
}
if (len == 2)
{
if (card_stat.line1.size() == 1 && card_stat.card2.size() == 2)
{
face = card_stat.card2[1].face;
type = CARD_TYPE_TWO;
return type;
}
else if (card_stat.line1.size() == 2 && card_stat.card1.size() == 2 &&
card_stat.card1[0].face == 16 && card_stat.card1[1].face == 17)
{
face = card_stat.card1[1].face;
type = CARD_TYPE_ROCKET;
return type;
}
}
if (len == 3)
{
if (card_stat.card3.size() == 3)
{
face = card_stat.card3[2].face;
type = CARD_TYPE_THREE;
return type;
}
}
if (len == 4)
{
if (card_stat.card4.size() == 4)
{
face = card_stat.card4[3].face;
type = CARD_TYPE_BOMB;
return type;
}
else if (card_stat.card1.size() == 1 && card_stat.card3.size() == 3)
{
face = card_stat.card3[2].face;
type = CARD_TYPE_THREEWITHONE;
return type;
}
}
if (len == 5)
{
if (card_stat.card2.size() == 2 && card_stat.card3.size() == 3)
{
face = card_stat.card3[2].face;
type = CARD_TYPE_THREEWITHTWO;
return type;
}
}
if (len == 6)
{
if (card_stat.card1.size() == 2 && card_stat.card4.size() == 4)
{
face = card_stat.card4[3].face;
type = CARD_TYPE_FOURWITHONE;
return type;
}
}
if (len == 8)
{
if (card_stat.card2.size() == 4 && card_stat.card4.size() == 4)
{
face = card_stat.card4[3].face;
type = CARD_TYPE_FOURWITHTWO;
return type;
}
}
if (card_stat.card1.size() == card_stat.line1.size())
{
if (check_is_line(card_stat, 1))
{
face = card_stat.card1[card_stat.card1.size() - 1].face;
type = CARD_TYPE_ONELINE;
return type;
}
}
if (len == card_stat.card2.size() && card_stat.card2.size() == card_stat.line2.size())
{
if (check_is_line(card_stat, 2))
{
face = card_stat.card2[card_stat.card2.size() - 1].face;
type = CARD_TYPE_TWOLINE;
return type;
}
}
if (len < 6)
{
return type;
}
unsigned int left_card_len;
if (card_stat.card3.size() == card_stat.line3.size() &&
card_stat.card4.size() == 0 &&
card_stat.card3.size() != 0)
{
if (check_is_line(card_stat, 3))
{
left_card_len = card_stat.card1.size() + card_stat.card2.size();
if (left_card_len == 0)
{
face = card_stat.card3[card_stat.line3.size() - 1].face;
type = CARD_TYPE_THREELINE;
return type;
}
else if (left_card_len * 3 == card_stat.card3.size())
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHONE;
return type;
}
else if (card_stat.card1.size() == 0 && left_card_len * 3 == card_stat.card3.size() * 2)
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHWING;
return type;
}
}
if (check_arr_is_line(card_stat.card3, 3, 3, card_stat.card3.size()))
{
left_card_len = card_stat.card1.size() + card_stat.card2.size() + 3;
if (left_card_len * 3 == (card_stat.card3.size() - 3))
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHONE;
return type;
}
}
if (check_arr_is_line(card_stat.card3, 3, 0, card_stat.card3.size() - 3))
{
left_card_len = card_stat.card1.size() + card_stat.card2.size() + 3;
if (left_card_len * 3 == (card_stat.card3.size() - 3))
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHONE;
return type;
}
}
}
if (card_stat.card3.size() != 0 && check_arr_is_line(card_stat.card3, 3))
{
left_card_len = card_stat.card1.size() + card_stat.card2.size() + card_stat.card4.size();
if (left_card_len * 3 == card_stat.card3.size())
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHONE;
return type;
}
else if (card_stat.card1.size() == 0 && left_card_len * 3 == card_stat.card3.size() * 2)
{
face = card_stat.card3[card_stat.card3.size() - 1].face;
type = CARD_TYPE_PLANEWITHWING;
return type;
}
}
return type;
}
/*
@brief 当需要分析的牌型中有鬼牌,则需要调用这个函数来分析当前牌型的值
@retur 返回分析的牌型
*/
int CardAnalysis::ghost_analysis()
{
if (len == 1)
{
face = card_stat.ghost_cards[0].face;
type = CARD_TYPE_ONE;
return type;
}
if (len == 2)
{
ghost_check_two();
return type;
}
if (len == 3)
{
ghost_check_three();
return type;
}
if (len == 4)
{
ghost_check_bomb();
ghost_check_threewithone();
return type;
}
if (len == 5)
{
ghost_check_threewithtwo();
ghost_check_line();
return type;
}
if (len == 6)
{
ghost_check_fourwithone();
ghost_check_line();
ghost_check_doubleline();
ghost_check_tripleline();
return type;
}
if (len == 8)
{
ghost_check_plane();
ghost_check_fourwithtwo();
ghost_check_line();
ghost_check_doubleline();
return type;
}
ghost_check_plane();
ghost_check_line();
ghost_check_doubleline();
ghost_check_tripleline();
return type;
}
/*
@brief 在有鬼牌的情况下,判断一对
@retur 一对的面值(如果是0表示不是一对)
*/
int CardAnalysis::ghost_check_two()
{
int max_face = 0;
if (len != 2)
return 0;
if (ghost_num == 2)
{ //二张鬼牌的情况
max_face = ghost_face;
}
else if (ghost_num == 1 && card_stat.card1.size() == 1)
{ //一张鬼牌的情况
max_face = card_stat.card1[0].face;
if (max_face > Card::Two)
{
max_face = 0; //大王和小王不算
}
}
ghost_set_face_and_type(CARD_TYPE_TWO, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断三张不带的情况
@retur 三张的面值(如果是0表示不是三张)
*/
int CardAnalysis::ghost_check_three()
{
int max_face = 0;
if (len != 3)
return 0;
if (ghost_num == 3)
{ //三张鬼牌的情况
max_face = ghost_face;
}
else if (ghost_num == 2 && card_stat.card1.size() == 1)
{ //二张鬼牌的情况
max_face = card_stat.card1[0].face;
}
else if (ghost_num == 1 && card_stat.card2.size() == 2)
{ //一张鬼牌的情况
max_face = card_stat.card2[1].face;
}
ghost_set_face_and_type(CARD_TYPE_THREE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断三带单牌
@retur 三带的面值(如果是0表示不是三带单牌)
*/
int CardAnalysis::ghost_check_threewithone()
{
int max_face = 0;
if (len != 4)
return 0;
//三带1的情况
// if (ghost_num == 3 && card_stat.card1.size() == 1)
// {
// max_face = card_stat.card1[0].face;
// if (max_face < ghost_face)
// {
// max_face = ghost_face;
// }
// }
/*else */
if (ghost_num == 2 && card_stat.card1.size() == 2)
{
if ((card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small) &&
(card_stat.card1[1].face == Card::Big || card_stat.card1[1].face == Card::Small))
{//有两个鬼牌
return 0;
}
max_face = card_stat.card1[1].face; //取card1中较大的牌做为最大的牌
}
// else if (ghost_num == 2 && card_stat.card2.size() == 2)
// {
// max_face = card_stat.card2[1].face;
// }
else if (ghost_num == 1 && card_stat.card1.size() == 1 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
}
ghost_set_face_and_type(CARD_TYPE_THREEWITHONE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断三带对子
@retur 三带的面值(如果是0表示不是三带对子)
*/
int CardAnalysis::ghost_check_threewithtwo()
{
int max_face = 0;
if (len != 5)
return 0;
if (ghost_num == 4 && card_stat.card1.size() == 1 &&
(card_stat.card1[0].face != Card::Big && card_stat.card1[0].face != Card::Small))
{
max_face = card_stat.card1[0].face;
if (max_face < ghost_face)
{
max_face = ghost_face;
}
}
else if (ghost_num == 3 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
if (max_face < ghost_face)
{
max_face = ghost_face;
}
}
else if (ghost_num == 3 && card_stat.card1.size() == 2 &&
(card_stat.card1[1].face != Card::Big && card_stat.card1[1].face != Card::Small))
{
max_face = card_stat.card1[1].face; //取card1中较大的牌做为最大的牌
}
else if (ghost_num == 2 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 2 && card_stat.card2.size() == 2 && card_stat.card1.size() == 1 &&
(card_stat.card1[0].face != Card::Big && card_stat.card1[0].face != Card::Small))
{
max_face = card_stat.card2[1].face;
if (card_stat.card2[1] < card_stat.card1[0])
max_face = card_stat.card1[0].face;
}
else if (ghost_num == 1 && card_stat.card3.size() == 3 && card_stat.card1.size() == 1 &&
(card_stat.card1[0].face != Card::Big && card_stat.card1[0].face != Card::Small))
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 1 && card_stat.card2.size() == 4)
{
max_face = card_stat.card2[3].face;
}
ghost_set_face_and_type(CARD_TYPE_THREEWITHTWO, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断顺子
@retur 顺子中最大的牌值(如果是0表示不是顺子)
*/
int CardAnalysis::ghost_check_line()
{
int max_face = 0;
if (len < 5)
return 0;
//顺子,检测一条龙的时候,必须只有card1中有值
if (card_stat.card2.size() != 0 || card_stat.card3.size() != 0 || card_stat.card4.size() != 0)
return 0;
if (has_bigger_than_ace())
return 0; //有2和王就不可能是顺子
//计算不是鬼牌的牌值,总间距是多少。如6,7之间没有间距 6, 8 之间有1个间距
//如果鬼牌的数量大于等于间距值,说明能组成顺子
int gap = ghost_calc_gap();
if (ghost_num < gap)
return 0;
//计算顺子中最大的牌值
max_face = card_stat.line1[card_stat.line1.size() - 1].face + (ghost_num - gap);
if (max_face > Card::Ace)
max_face = Card::Ace;
ghost_set_face_and_type(CARD_TYPE_ONELINE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断连对
@retur 连对中最大的牌值(如果是0表示不是连对)
*/
int CardAnalysis::ghost_check_doubleline()
{
int max_face = 0;
if (len < 6 || len % 2 != 0)
return 0;
//顺子,检测连对的时候,必须只有card1和card2中有值
if (card_stat.card3.size() != 0 || card_stat.card4.size() != 0)
return 0;
const vector<Card> &refCard1 = card_stat.card1;
const int card1Len = refCard1.size();
if (has_bigger_than_ace())
return 0; //有2和王就不可能是顺子
//先和单牌配对,使其能组成对子
int left_num = ghost_num;
if (card1Len > 0)
{
if (ghost_num < card1Len)
return 0;
left_num -= card1Len;
}
if (left_num % 2 != 0)
return 0;
//计算总间距。如6,7之间没有间距 6, 8 之间有1个间距
//如果鬼牌的数量大于等于间距值*2,说明能组成连对
int gap = ghost_calc_gap();
if (left_num < gap * 2)
return 0;
//计算连对中最大的牌值
max_face = card_stat.line1[card_stat.line1.size() - 1].face + (left_num - 2 * gap) / 2;
if (max_face > Card::Ace)
max_face = Card::Ace;
ghost_set_face_and_type(CARD_TYPE_TWOLINE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断三顺
@retur 三顺中最大的牌值(如果是0表示不是三顺)
*/
int CardAnalysis::ghost_check_tripleline()
{
int max_face = 0;
if (len < 6 || len % 3 != 0)
return 0;
if (card_stat.card4.size() != 0)
return 0;
const vector<Card> &refCard1 = card_stat.card1;
const int card1Len = refCard1.size();
const vector<Card> &refCard2 = card_stat.card2;
const int card2Len = refCard2.size();
if (has_bigger_than_ace())
return 0; //有2和王就不可能是顺子
//先和单牌配对,使其能组成三个
int left_num = ghost_num;
if (card1Len > 0)
{
if (ghost_num < card1Len * 2)
return 0;
left_num -= card1Len * 2;
}
//和对子配对,使其能组成三个
if (card2Len > 0)
{
if (left_num < card2Len / 2)
{
return 0;
}
left_num -= card2Len / 2;
}
if (left_num % 3 != 0)
{
return 0;
}
//计算总间距。如6,7之间没有间距 6, 8 之间有1个间距
//如果鬼牌的数量大于等于间距值*3,说明能组成三顺
int gap = ghost_calc_gap();
if (left_num < gap * 3)
return 0;
//计算三顺中最大的牌值
max_face = card_stat.line1[card_stat.line1.size() - 1].face + (left_num - 3 * gap) / 3;
if (max_face > Card::Ace)
max_face = Card::Ace;
ghost_set_face_and_type(CARD_TYPE_THREELINE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断炸弹(软炸,硬炸,纯癞子炸)
@retur 炸弹面值(如果是0表示炸弹)
*/
int CardAnalysis::ghost_check_bomb()
{
int max_face = 0;
int max_type = 0;
if (len != 4)
return 0;
if (ghost_num == 4)
{
max_face = ghost_face;
max_type = CARD_TYPE_GHOSTBOMB; //纯癞子炸弹
}
else if (ghost_num == 3 && card_stat.card1.size() == 1)
{
max_face = card_stat.card1[0].face;
max_type = CARD_TYPE_SOFTBOMB;
}
else if (ghost_num == 2 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
max_type = CARD_TYPE_SOFTBOMB;
}
else if (ghost_num == 1 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
max_type = CARD_TYPE_SOFTBOMB;
}
ghost_set_face_and_type(max_type, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断四带二个单牌
@retur 四个的面值(如果是0表示不能组成四带二)
*/
int CardAnalysis::ghost_check_fourwithone()
{
int max_face = 0;
if (len != 6)
return 0;
if (ghost_num == 4 && card_stat.card1.size() == 2)
{
max_face = Card::Two;
}
else if (ghost_num == 4 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
}
else if (ghost_num == 3 && card_stat.card1.size() == 3)
{
max_face = card_stat.card1[2].face;
if (max_face > Card::Two)
max_face = card_stat.card1[1].face;
if (max_face > Card::Two)
max_face = card_stat.card1[0].face;
}
else if (ghost_num == 3 && card_stat.card1.size() == 1 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
}
else if (ghost_num == 3 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 2 && card_stat.card1.size() == 2 && card_stat.card2.size() == 2)
{
max_face = card_stat.card2[1].face;
}
else if (ghost_num == 2 && card_stat.card2.size() == 4)
{
max_face = card_stat.card2[3].face;
}
else if (ghost_num == 2 && card_stat.card1.size() == 1 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 2 && card_stat.card4.size() == 4)
{
max_face = card_stat.card4[3].face;
}
else if (ghost_num == 1 && card_stat.card1.size() == 2 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 1 && card_stat.card1.size() == 1 && card_stat.card4.size() == 4)
{
max_face = card_stat.card4[3].face;
}
ghost_set_face_and_type(CARD_TYPE_FOURWITHONE, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断四带二个对子
@retur 四个的面值(如果是0表示不能组成四带二个对子)
*/
int CardAnalysis::ghost_check_fourwithtwo()
{
int max_face = 0;
if (len != 8)
return 0;
if (ghost_num == 4 && card_stat.card1.size() == 2 && card_stat.card2.size() == 2)
{
if ((card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small) ||
(card_stat.card1[1].face == Card::Big || card_stat.card1[1].face == Card::Small))
{//有大小王
return 0;
}
max_face = card_stat.card2[1].face;
if (max_face < card_stat.card1[1].face)
{
max_face = card_stat.card1[1].face;
}
}
else if (ghost_num == 4 && card_stat.card1.size() == 1 && card_stat.card3.size() == 3)
{
if (card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small)
{ //有大小王
return 0;
}
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 4 && card_stat.card2.size() == 4)
{
max_face = Card::Two;
}
else if (ghost_num == 4 && card_stat.card4.size() == 4)
{
max_face = card_stat.card4[3].face;
}
else if (ghost_num == 3 && card_stat.card1.size() == 2 && card_stat.card3.size() == 3)
{
if ((card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small) ||
(card_stat.card1[1].face == Card::Big || card_stat.card1[1].face == Card::Small))
{ //有大小王
return 0;
}
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 3 && card_stat.card1.size() == 1 && card_stat.card2.size() == 4)
{
if (card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small)
{ //有大小王
return 0;
}
max_face = card_stat.card1[0].face;
}
else if (ghost_num == 3 && card_stat.card1.size() == 1 && card_stat.card4.size() == 4)
{
if (card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small)
{ //有大小王
return 0;
}
max_face = card_stat.card4[3].face;
}
else if (ghost_num == 3 && card_stat.card2.size() == 2 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
else if (ghost_num == 2 && card_stat.card1.size() == 2 && card_stat.card4.size() == 4)
{
if ((card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small) ||
(card_stat.card1[1].face == Card::Big || card_stat.card1[1].face == Card::Small))
{//有大小王
return 0;
}
max_face = card_stat.card4[3].face;
}
else if (ghost_num == 1 && card_stat.card1.size() == 1 &&
card_stat.card2.size() == 2 && card_stat.card4.size() == 4)
{
if (card_stat.card1[0].face == Card::Big || card_stat.card1[0].face == Card::Small)
{ //有大小王
return 0;
}
max_face = card_stat.card4[3].face;
}
else if (ghost_num == 1 && card_stat.card2.size() == 4 && card_stat.card3.size() == 3)
{
max_face = card_stat.card3[2].face;
}
ghost_set_face_and_type(CARD_TYPE_FOURWITHTWO, max_face);
return max_face;
}
/*
@brief 在有鬼牌的情况下,判断飞机带羿或飞机带翅的情况
@retur 飞机的面值(如果是0表示不能组成飞机带羿或飞机带翅)
*/
int CardAnalysis::ghost_check_plane()
{
int max_face = 0;