-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgametest.js
1575 lines (1482 loc) · 57.1 KB
/
gametest.js
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
import Poker from './poker.js';
import Util,{NormalType, SpecialType, PokerPoint, PokerHua, CompareResult} from './util.js';
import { Tree, TreeNode,Dui, LiangDui, SanTiao, TieZhi, HuLu} from './pokertype.js'
class CalSpecial {
/**
* 将树拆出各种节点出来
* @param tree
*/
static CalSpecialResult(tree) {
if (this.IsZhiZunQingLong(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.ZhiZunQingLong };
}
if (this.IsYiTiaoLong(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.YiTiaoLong };
}
// if (this.IsShiErHuangZu(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.ShiErHuangZu };
// }
if (this.IsSanTongHuaShun(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.SanTongHuaShun };
}
// if (this.IsSanFenTianXia(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.SanFenTianXia };
// }
// if (this.IsQuanDa(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.QuanDa };
// }
if (this.IsQuanXiao(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.QuanXiao };
}
// if (this.IsCouYiSe(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.ChouYiSe };
// }
// if (this.IsSiTaoSanTiao(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.SiTaoSanTiao };
// }
// if (this.IsWuDuiSanTiao(tree)) {
// return { IsSpecial: true, SpecialType: SpecialType.WuDuiSanTiao };
// }
if (this.IsLiuDuiBan(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.LiuDuiBan };
}
if (this.IsSanTongHua(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.SanTongHua };
}
if (this.IsSanSunZi(tree)) {
return { IsSpecial: true, SpecialType: SpecialType.SanSunZi };
}
return { IsSpecial: false, SpecialType: SpecialType.None };
}
/**
* 判断一个树是不是“至尊青龙”
* @param tree
*/
static IsZhiZunQingLong(tree) {
return tree.mapScoreListPoker.size == 13 && tree.mapHuaListPoker.size == 1;
}
/**
* 是否是"一条龙"
* @param tree
* @returns
*/
static IsYiTiaoLong(tree) {
return tree.mapScoreListPoker.size == 13 && tree.mapHuaListPoker.size > 1;
}
/**
* 是否是"十二皇族",13张牌中12张牌分值大于等于10
* @param tree
* @returns
*/
static IsShiErHuangZu(tree) {
//分少于10的牌的数量
var lessScoreTCount = 0;
for (const poker of tree.pokers) {
if (poker.Score < 10) {
lessScoreTCount++;
if (lessScoreTCount >= 2) {
return false;
}
}
}
return true;
}
/**
* 是否是"三同花顺"
* @returns
*/
static IsSanTongHuaShun(tree) {
//三同花顺,只可能是3个同样的花,也可能是2个花色,但每个花下都是连续的,一定不是一个花色,因为一个花色就是"至尊青龙"
if (tree.mapHuaListPoker.size == 1 || tree.mapHuaListPoker.size == 4) {
return false;
}
var isSanTongHuaShun = true;
//同一个花下的所有牌,点数是连续的
tree.mapHuaListPoker.forEach((pokers, _) => {
if (pokers.length == 3 || pokers.length == 5 || pokers.length == 8 || pokers.length == 10) {
Util.SortPoker(pokers);
var last = null;
for (const poker of pokers) {
if (last == null) {
last = poker;
}
else {
if (poker.Score == last.Score + 1) {
last = poker;
}
else {
isSanTongHuaShun = false;
}
}
}
}
else {
isSanTongHuaShun = false;
}
});
return isSanTongHuaShun;
}
/**
* 是否是"三分天下"
* @returns
*/
static IsSanFenTianXia(tree) {
//有3个铁支就是三分天下
if (tree.listTieZhi.length != 3) {
return false;
}
return true;
}
/**
* 是否是"全大"
* @returns
*/
static IsQuanDa(tree) {
var isQuanDa = true;
tree.mapScoreListPoker.forEach((_, socre) => {
if (socre < 8) {
isQuanDa = false;
}
});
return isQuanDa;
}
/**
* 是否是"全小"
* @returns
*/
static IsQuanXiao(tree) {
var isQuanXiao = true;
tree.mapScoreListPoker.forEach((_, socre) => {
// console.log(tree.mapScoreListPoker)
if (socre > 8) {
isQuanXiao = false;
}
});
return isQuanXiao;
}
/**
* 是否是"凑一色":即只有一个花色,且花色必需是全红或全黑
* @returns
*/
static IsCouYiSe(tree) {
if (tree.mapHuaListPoker.size != 2) {
return false;
}
var isCouYiSe = true;
var lastHua = PokerHua.HuaNone;
tree.mapHuaListPoker.forEach((_, hua) => {
if (lastHua == PokerHua.HuaNone) {
lastHua = hua;
}
else if (hua - lastHua != 0 && hua - lastHua != 2 && hua - lastHua != -2) {
isCouYiSe = false;
}
});
return isCouYiSe;
}
/**
* 是否是“四套三条”,即AAA,BBB,CCC,DDD,E
* @returns
*/
static IsSiTaoSanTiao(tree) {
if (tree.listSanTiao.length == 4) {
return true;
}
return false;
}
/**
* 是否是“五对三条”,即AA、BB、CC、DD、EE、FFF
* @returns 是或否
*/
static IsWuDuiSanTiao(tree) {
if (tree.listDui.length == 5 && tree.listSanTiao.length == 1) {
return true;
}
return false;
}
/**
* 是否是“六对半”,即AA、BB、CC、DD、EE、FF、G
* @returns 是或否
*/
static IsLiuDuiBan(tree) {
if (tree.listDui.length == 6) {
return true;
}
return false;
}
/**
* 是否是“三同花“
* @returns 是或否
*/
static IsSanTongHua(tree) {
//只可能是2种或3种花色,一种花色是同花顺
if (tree.mapHuaListPoker.size == 4 || tree.mapHuaListPoker.size == 1) {
return false;
}
//如果是2种花色,其中一花为8张或10,另一个花为5张或3张;如果是3种花色,同一个花下只能是3张或5张
var isSanTongHua = true;
tree.mapHuaListPoker.forEach((pokers, _) => {
var count = pokers.length;
if (count != 3 && count != 5 && count != 8 && count != 10) {
isSanTongHua = false;
}
});
return isSanTongHua;
}
/**
* 是否是“三顺子“
* @returns 是或否
*/
static IsSanSunZi(tree) {
CalNormal.SplitShunZi(tree);
for (const node1 of tree.Nodes) {
if (node1.normalType == NormalType.SHUN_ZI) {
let middle = new Tree(node1.rest);
CalNormal.SplitShunZi(middle);
for (const node2 of middle.Nodes) {
if (node2.normalType == NormalType.SHUN_ZI) {
let right = node2.rest;
Util.SortPoker(right);
//case 分值连续
if (right[0].Score + 1 == right[1].Score && right[1].Score + 1 == right[2].Score) {
return true;
}
//case A,2,3
else if (right[0].Point == PokerPoint.Poker2 && right[1].Point == PokerPoint.Poker3 && right[2].Point == PokerPoint.PokerA) {
return true;
}
}
}
}
}
return false;
}
}
class ResultNormal {
ToString() {
var leftPokerDesc = "";
for (const poker of this.Head.pokers) {
leftPokerDesc += poker.Desc;
}
var middlePokerDesc = "";
for (const poker of this.Middle.pokers) {
middlePokerDesc += poker.Desc;
}
var rightPokerDesc = "";
for (const poker of this.Tail.pokers) {
rightPokerDesc += poker.Desc;
}
// ////debugger
return "\u7ED3\u679C\uFF1A{\u4E0A:\u3010".concat(Util.NormalTypeToString(this.Tail.normalType), "\u3011= {").concat(rightPokerDesc, "},\u4E2D:\u3010").concat(Util.NormalTypeToString(this.Middle.normalType), "\u3011= {").concat(middlePokerDesc, "},\u4E0B:\u3010").concat(Util.NormalTypeToString(this.Head.normalType), "\u3011= {").concat(leftPokerDesc, "},\u597D\u724C\u503C=\u3010").concat(this.BestScore, "\u3011}");
//return `结果:{上:【${ Util.NormalTypeToString(this.Tail.normalType)}】= {${rightPokerDesc}},中:【${ Util.NormalTypeToString(this.Middle.normalType)}】= {${middlePokerDesc}},下:【${ Util.NormalTypeToString(this.Head.normalType)}】= {${leftPokerDesc, "},\u597D\u724C\u503C=\u3010").concat(this.BestScore, "\u3011}");
}
}
class CalNormal {
/**
* 列出所有的普通牌型
* @param fatherTree
* @returns
*/
static CalNormalResult(fatherTree) {
var resultList = new Array();
this.Split(fatherTree);
for (const node1 of fatherTree.Nodes) {
// console.log("下墩节点 = " + node1.ToString())
var sonTree = new Tree(node1.rest);
this.Split(sonTree);
for (const node2 of sonTree.Nodes) {
// console.log("中墩节点 = " + node2.ToString())
if (node1.CompareExternal(node2) != CompareResult.Worse) {
var node3 = Api.PokerListToTreeNode(node2.rest);
if (node2.CompareExternal(node3) != CompareResult.Worse) {
// console.log("上墩节点 = " + node3.ToString())
var bestScore = 0;
switch (node1.normalType) {
case NormalType.TONG_HUA_SHUN:
bestScore += 190000000;
//bestScore += 10
break;
case NormalType.TIE_ZHI:
bestScore += 180000000;
//bestScore += 8;
break;
case NormalType.HU_LU:
bestScore += 170000000;
break;
case NormalType.TONG_HUA:
bestScore += 160000000;
break;
case NormalType.SHUN_ZI: //同花以下 优先 中墩
bestScore += 5;
break;
case NormalType.SAN_TIAO:
bestScore += 4;
break;
case NormalType.LIANG_DUI:
bestScore += 3;
break;
case NormalType.DUI_ZI:
bestScore += 2 ;
break;
default:
bestScore += 1;
break;
}
switch (node2.normalType) {
case NormalType.TONG_HUA_SHUN:
bestScore += 1500000;
//bestScore += 10
break;
case NormalType.TIE_ZHI:
bestScore += 1400000;
//bestScore += 8;
break;
case NormalType.HU_LU:
bestScore += 1300000;
break;
case NormalType.TONG_HUA:
bestScore += 1200000;
break;
case NormalType.SHUN_ZI:
bestScore += 1100000;
break;
case NormalType.SAN_TIAO:
bestScore += 800;
break;
case NormalType.LIANG_DUI:
bestScore += 700;
break;
case NormalType.DUI_ZI:
bestScore += 600;
break;
default:
bestScore += 1;
break;
}
switch (node3.normalType) {
case NormalType.SAN_TIAO:
bestScore += 100000;
//bestScore += 3
break;
case NormalType.DUI_ZI:
bestScore += 90000;
break;
default:
bestScore += 1;
//bestScore += 1;
break;
}
var result = new ResultNormal();
result.BestScore = bestScore;
result.Head = node1; //最后一敦
result.Middle = node2;
result.Tail = node3;
resultList.push(result);
}
}
}
}
return resultList;
}
static SortFilterResult(resultList) {
resultList.sort((a, b) => {
if (a.BestScore != b.BestScore) {
return b.BestScore - a.BestScore;
}
//分数一样 比较头部
if (a.Head.reCompareExternal(b.Head) == CompareResult.Better) {
return -1;
}
if(a.Head.reCompareExternal(b.Head) == CompareResult.Worse) {
return 1;
}
if (a.Middle.reCompareExternal(b.Middle) == CompareResult.Better) {
return -1;
}
if (a.Middle.reCompareExternal(b.Middle) == CompareResult.Worse) {
return 1;
}
// if (a.Tail.reCompareExternal(b.Tail) == CompareResult.Better) {
// return -1;
// }
// if (a.Tail.reCompareExternal(b.Tail) == CompareResult.Worse) {
// return 1;
// }
return 0;
});
// var filterRes = new Array();
// var last = null;
// for (const result of resultList) {
// // if (last == null) {
// // last = result;
// // filterRes.push(last);
// // }
// // else if (result.Head.normalType != last.Head.normalType || result.Middle.normalType != last.Middle.normalType || result.Tail.normalType != last.Tail.normalType) {
// // last = result;
// // filterRes.push(result);
// // }
// filterRes.push(result);
// }
return resultList;
}
/**
* 将树拆出各种节点出来
* @param tree
*/
static Split(tree) {
this.SplitDui(tree);
this.SplitTongHuaSun(tree);
this.SplitTieZhi(tree);
this.SplitHuLu(tree);
this.SplitTongHua(tree);
this.SplitShunZi(tree);
this.SplitSanTiao(tree);
this.SplitLiangDui(tree);
this.SplitWuLong(tree);
}
/**
* 将树中拆出一个同花顺节点出来
* @param tree 要拆开的树
*/
static SplitTongHuaSun(tree) {
var count = tree.listShunZi.length;
if (count <= 0) {
return;
}
tree.listShunZi.forEach(shunZi => {
var poker1s = tree.mapScoreListPoker.get(shunZi[0]);
var poker2s = tree.mapScoreListPoker.get(shunZi[0] + 1);
var poker3s = tree.mapScoreListPoker.get(shunZi[0] + 2);
var poker4s = tree.mapScoreListPoker.get(shunZi[0] + 3);
var poker5s = tree.mapScoreListPoker.get(shunZi[1]);
for (let i1 = 0; i1 < poker1s.length; i1++) {
var hua = poker1s[i1].Hua;
for (let i2 = 0; i2 < poker2s.length; i2++) {
if (poker2s[i2].Hua == hua) {
for (let i3 = 0; i3 < poker3s.length; i3++) {
if (poker3s[i3].Hua == hua) {
for (let i4 = 0; i4 < poker4s.length; i4++) {
if (poker4s[i4].Hua == hua) {
for (let i5 = 0; i5 < poker5s.length; i5++) {
if (poker5s[i5].Hua == hua) {
var n = new TreeNode();
n.normalType = NormalType.TONG_HUA_SHUN;
for (const poker of tree.pokers) {
if (poker == poker1s[i1] || poker == poker2s[i2] || poker == poker3s[i3] || poker == poker4s[i4] || poker == poker5s[i5]) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
}
}
}
}
}
});
}
/**
* 从树中拆出一个铁支节点出来
* @param tree 要拆的树
* @returns
*/
static SplitTieZhi(tree) {
var count = tree.listTieZhi.length;
if (count <= 0) {
return;
}
var maxTieZhiScore = tree.listTieZhi[count - 1];
for (const poker1 of tree.pokers) {
if (poker1.Score != maxTieZhiScore) {
var n = new TreeNode();
n.normalType = NormalType.TIE_ZHI;
n.pokers.push(poker1);
n.tieZhi = new TieZhi();
n.tieZhi.TieZhiScore = maxTieZhiScore;
n.tieZhi.DanScore = poker1.Score;
for (const poker2 of tree.pokers) {
if (poker2 != poker1) {
if (poker2.Score == maxTieZhiScore) {
n.pokers.push(poker2);
}
else {
n.rest.push(poker2);
}
}
}
tree.Nodes.push(n);
}
}
}
/**
* 拆分出葫芦
* @param tree 要拆的树
* @returns
*/
static SplitHuLu(tree) {
var countSanTiao = tree.listSanTiao.length;
if (countSanTiao <= 0) {
return;
}
// var huLuScore = tree.listSanTiao[countSanTiao - 1]; //取最大的三条
for (const huLuScore of tree.listSanTiao) {
for (const duiScore of tree.listDui) {
// for(let i=tree.listDui.length-1;i >= 0;i--){
var n = new TreeNode();
n.normalType = NormalType.HU_LU;
n.huLu = new HuLu();
n.huLu.HuLuScore = huLuScore;
n.huLu.DuiScore = duiScore;
for (const poker of tree.pokers) {
if (poker.Score == huLuScore || poker.Score == duiScore) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
for (const huLuScore2 of tree.listSanTiao) {
// for(let i=tree.listDui.length-1;i >= 0;i--){
if(huLuScore2 != huLuScore){
var n = new TreeNode();
n.normalType = NormalType.HU_LU;
n.huLu = new HuLu();
n.huLu.HuLuScore = huLuScore;
n.huLu.DuiScore = huLuScore2;
let tempCount = 0;//计数器
for (const poker of tree.pokers) {
if (poker.Score == huLuScore ) {
n.pokers.push(poker);
}else if(poker.Score == huLuScore2){
//debugger
if(++tempCount<3){
n.pokers.push(poker);
}else{
n.rest.push(poker);
}
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
/**
* 将所有的同花组合拆出来
* @param tree 要拆的树
*/
static SplitTongHua(tree) {
tree.mapHuaListPoker.forEach((pokers, _) => {
var count = pokers.length;
if (count >= 5) {
for (let i1 = 0; i1 < count; i1++) {
for (let i2 = i1 + 1; i2 < count; i2++) {
for (let i3 = i2 + 1; i3 < count; i3++) {
for (let i4 = i3 + 1; i4 < count; i4++) {
for (let i5 = i4 + 1; i5 < count; i5++) {
var n = new TreeNode();
n.normalType = NormalType.TONG_HUA;
for (const poker of tree.pokers) {
if (poker == pokers[i1] || poker == pokers[i2] || poker == pokers[i3] || poker == pokers[i4] || poker == pokers[i5]) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
}
}
});
}
/**
* 将所有的顺子拆出来
* @param tree 要拆的树
*/
static SplitShunZi(tree) {
var count = tree.listShunZi.length;
if (count <= 0) {
return;
}
tree.listShunZi.forEach(shunZi => {
var poker1s = tree.mapScoreListPoker.get(shunZi[0]);
var poker2s = tree.mapScoreListPoker.get(shunZi[0] + 1);
var poker3s = tree.mapScoreListPoker.get(shunZi[0] + 2);
var poker4s = tree.mapScoreListPoker.get(shunZi[0] + 3);
var poker5s = tree.mapScoreListPoker.get(shunZi[1]);
for (let i1 = 0; i1 < poker1s.length; i1++) {
for (let i2 = 0; i2 < poker2s.length; i2++) {
for (let i3 = 0; i3 < poker3s.length; i3++) {
for (let i4 = 0; i4 < poker4s.length; i4++) {
for (let i5 = 0; i5 < poker5s.length; i5++) {
var n = new TreeNode();
n.normalType = NormalType.SHUN_ZI;
for (const poker of tree.pokers) {
if (poker == poker1s[i1] || poker == poker2s[i2] || poker == poker3s[i3] || poker == poker4s[i4] || poker == poker5s[i5]) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
}
});
}
/**
* 将所有的三条拆出来
* @param tree 要拆的树
*/
static SplitSanTiao(tree) {
var sanTiaoCount = tree.listSanTiao.length;
var danPaiCount = tree.listDanPai.length;
if (sanTiaoCount <= 0 || danPaiCount < 2) {
return;
}
for(let i = sanTiaoCount-1;i>=0;i--){
var maxSanTiaoScore = tree.listSanTiao[i];
for(let j=danPaiCount-1;j>=1;j--){
for(let k=j-1;k>=0;k--){
if(k != j){
var smallDanPaiScore = tree.listDanPai[j]; // 最大单牌
var bigDanPaiScore = tree.listDanPai[k]; //
var n = new TreeNode();
n.normalType = NormalType.SAN_TIAO;
n.sanTiao = new SanTiao();
n.sanTiao.SanTiaoScore = maxSanTiaoScore;
n.sanTiao.Dan1Score = bigDanPaiScore;
n.sanTiao.Dan2Score = smallDanPaiScore;
for (const poker of tree.pokers) {
if (poker.Score == smallDanPaiScore || poker.Score == bigDanPaiScore || poker.Score == maxSanTiaoScore) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
//var maxSanTiaoScore = tree.listSanTiao[sanTiaoCount - 1]; //最大的三条分数
// var smallDanPaiScore = tree.listDanPai[0]; //最小的单牌
// var bigDanPaiScore = tree.listDanPai[1]; //第二小的单牌
}
/**
* 拆分出两对出来
* @param tree
* @returns
*/
static SplitLiangDui(tree) {
var danPaiCount = tree.listDanPai.length;
var duiCount = tree.listDui.length;
if (duiCount < 2) {
return;
}
var danPaiScore = 0;
var dui1Score = 0;
var dui2Score = 0;
if (danPaiCount == 0) {
return;
}
//组成对子
for(let j=duiCount-1;j>=1;j--){
for(let k=j-1;k>=0;k--){
if(k != j){
dui1Score = tree.listDui[j];
dui2Score = tree.listDui[k];
tree.listDanPai.forEach(e => {
// ////debugger
danPaiScore = e;
var n = new TreeNode();
n.normalType = NormalType.LIANG_DUI;
n.liangDui = new LiangDui();
n.liangDui.Dui1Score = dui1Score;
n.liangDui.Dui2Score = dui2Score;
n.liangDui.DanScore = danPaiScore;
//单牌是拆出来的话,要防止单牌重复加入
var isAddDanPai = false;
for (const poker of tree.pokers) {
if (poker.Score == dui1Score || poker.Score == dui2Score) {
n.pokers.push(poker);
}
else if (poker.Score == danPaiScore && isAddDanPai == false) {
n.pokers.push(poker);
isAddDanPai = true;
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
})
}
}
}
}
/**
* 从树中拆出一对来
* @param tree
*/
static SplitDui(tree) {
var duiCount = tree.listDui.length;
var danPaiCount = tree.listDanPai.length;
if ((duiCount == 1 && danPaiCount >= 3) || (duiCount == 2 && danPaiCount >= 3) || (duiCount == 3 && danPaiCount >= 3)) {
// var duiScore = 0;
// if (duiCount == 1) {
// duiScore = tree.listDui[0];
// }
// else if (duiCount == 2) { //有两对时,取大的对
// duiScore = tree.listDui[1];
// }
// else if (duiCount == 3) {
// duiScore = tree.listDui[2];
// }
// //取大的单牌
// var dan1Score = tree.listDanPai[0];
// var dan2Score = tree.listDanPai[1];
// var dan3Score = tree.listDanPai[2];
for(let i=0;i< duiCount;i++){
var duiScore = 0;
duiScore = tree.listDui[i];
var dan1Score = tree.listDanPai[0];
var dan2Score = tree.listDanPai[1];
var dan3Score = tree.listDanPai[2];
var n = new TreeNode();
n.normalType = NormalType.DUI_ZI;
n.dui = new Dui();
n.dui.DuiScore = duiScore;
n.dui.Dan1Score = dan1Score;
n.dui.Dan2Score = dan2Score;
n.dui.Dan3Score = dan3Score;
for (const poker of tree.pokers) {
if (poker.Score == duiScore || poker.Score == dan1Score || poker.Score == dan2Score || poker.Score == dan3Score) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
/**
* 从树中拆出一对来
* @param tree
*/
static SplitWuLong(tree) {
var duiCount = tree.listDui.length;
var danPaiCount = tree.listDanPai.length;
if (duiCount > 0 || danPaiCount < 5) {
return;
}
//modify 循环生成乌龙
for(let i1 = danPaiCount-1;i1 >= 4;i1--){
for(let i2 = i1-1;i2 >= 3;i2--){
for(let i3 = i2-1;i3 >= 2;i3--){
for(let i4 = i3-1;i4 >= 1;i4--){
for(let i5 = i4-1;i5 >= 0;i5--){
var dan1Score = tree.listDanPai[i1]; //最大的单牌
var dan2Score = tree.listDanPai[i2]; //第1小的单牌
var dan3Score = tree.listDanPai[i3]; //第2小的单牌
var dan4Score = tree.listDanPai[i4]; //第3小的单牌
var dan5Score = tree.listDanPai[i5]; //第4小的单牌
var n = new TreeNode();
n.normalType = NormalType.WU_LONG;
for (const poker of tree.pokers) {
if (poker.Score == dan1Score || poker.Score == dan2Score || poker.Score == dan3Score || poker.Score == dan4Score || poker.Score == dan5Score) {
n.pokers.push(poker);
}
else {
n.rest.push(poker);
}
}
tree.Nodes.push(n);
}
}
}
}
}
// var dan1Score = tree.listDanPai[danPaiCount - 1]; //最大的单牌
// var dan2Score = tree.listDanPai[danPaiCount - 2]; //第1小的单牌
// var dan3Score = tree.listDanPai[danPaiCount - 3]; //第2小的单牌
// var dan4Score = tree.listDanPai[danPaiCount - 4]; //第3小的单牌
// var dan5Score = tree.listDanPai[danPaiCount - 5]; //第4小的单牌
// var n = new TreeNode();
// n.normalType = NormalType.WU_LONG;
// for (const poker of tree.pokers) {
// if (poker.Score == dan1Score || poker.Score == dan2Score || poker.Score == dan3Score || poker.Score == dan4Score || poker.Score == dan5Score) {
// n.pokers.push(poker);
// }
// else {
// n.rest.push(poker);
// }
// }
// tree.Nodes.push(n);
}
}
class Api {
/**
* 计算该树是否特殊牌型
* @param tree 牌的结构树
* @returns
*/
static CalSpecial(tree) {
return CalSpecial.CalSpecialResult(tree);
}
/**
* 计算该树的普通牌型
* @param tree 牌的结构树
* @returns
*/
static CalNormal(tree) {
var resultList = CalNormal.CalNormalResult(tree);
// ////debugger
var filterResultList = CalNormal.SortFilterResult(resultList);
return filterResultList;
}
/**
* 将牌型转换成树节点(墩)
* @param pokers 扑克牌
* @returns
*/
static PokerListToTreeNode(pokers) {
var length = pokers.length;
switch (length) {
case 5:
var tree = new Tree(pokers);
CalNormal.Split(tree);
return tree.Nodes[0];
case 3:
var n = new TreeNode();
n.pokers = pokers;
if (pokers[0].Score == pokers[1].Score && pokers[1].Score == pokers[2].Score) {
n.normalType = NormalType.SAN_TIAO;
n.sanTiao = new SanTiao();
n.sanTiao.SanTiaoScore = pokers[0].Score;
}
else if (pokers[0].Score == pokers[1].Score) {
n.normalType = NormalType.DUI_ZI;
n.dui = new Dui();
n.dui.DuiScore = pokers[1].Score;
n.dui.Dan3Score = pokers[2].Score;
}
else if (pokers[0].Score == pokers[2].Score) {
n.normalType = NormalType.DUI_ZI;
n.dui = new Dui();
n.dui.DuiScore = pokers[0].Score;
n.dui.Dan3Score = pokers[1].Score;
}
else if (pokers[1].Score == pokers[2].Score) {
n.normalType = NormalType.DUI_ZI;
n.dui = new Dui();
n.dui.DuiScore = pokers[1].Score;
n.dui.Dan3Score = pokers[0].Score;
}
else {
n.normalType = NormalType.WU_LONG;
}
return n;
default:
return null;
}
}
/**
* 将ASCII型的扑克id转成扑克数据结构
* @param nums
* @returns
*/
static PokersFromAscii(nums) {
var target = new Array();
for (const num of nums) {
var hua = (num >> 4) + 1;
var point = num & 0x0F;
var poker = new Poker(point, hua);
target.push(poker);
}
return target;
}
}
export default class Thirteen {
//
str = '';
start(pokers,zhuangNum,playerNum){ //牌堆,庄家编号,玩家数
pokers = this.transform(pokers);
let players = []; //玩家数组
for(let i=0;i<playerNum;i++){
players.push({
id : i+1, //玩家编号
cards : [],
isZhuang : i+1 == zhuangNum?true:false, //是否为庄家
paixing:[],
score: 0, //得分
special:false, //特殊牌
specialPai: '', //特殊牌型
beiNum:0, //倍数
HeadbeiNum:0, //
MiddlebeiNum:0,
TailbeiNum:0,
paiStr:''
});
}
let faCardCountArr = []; //每轮发牌
//获取发牌方式
// if(JSON.stringify(paramsObj.faCardCount) != "{}"&&JSON.stringify(paramsObj.faCardCount) != "null"){
// paramsObj.faCardCount.fapailunci.forEach((e,i) => {
// faCardCountArr.push(Number(e.split('-')[0]));
// })
// }else{
// faCardCountArr = [1,1,1,1,1,1,1,1,1,1,1,1,1];
// }
faCardCountArr = [1,1,1,1,1,1,1,1,1,1,1,1,1];//每轮一张牌
faCardCountArr.forEach((fapaNum,i) => {
for(let j=0;j<playerNum;j++){
players[j%playerNum].cards.push(...pokers.splice(0,fapaNum))
}
})
players.forEach(p => {
this.str+=this.generateScore(p)+'\n' //计算牌型
})