forked from cardrank/cardrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
767 lines (752 loc) · 38.6 KB
/
example_test.go
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
package cardrank_test
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"strconv"
"strings"
"cardrank.io/cardrank"
)
func ExampleFromRune() {
c, err := cardrank.FromRune('🂡')
if err != nil {
log.Fatal(err)
}
fmt.Printf("%b\n", c)
// Output:
// A♠
}
func ExampleMustCard() {
c := cardrank.MustCard("Ah")
fmt.Printf("%N of %L (%b)\n", c, c, c)
// Output:
// Ace of Hearts (A♥)
}
func ExampleCard_unmarshal() {
var hand []cardrank.Card
if err := json.Unmarshal([]byte(`["3s", "4c", "5c", "Ah", "2d"]`), &hand); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", hand)
// Output:
// [3s 4c 5c Ah 2d]
}
func ExampleDeck_Draw() {
d := cardrank.NewDeck()
// note: use a real random source
rnd := rand.New(rand.NewSource(52))
d.Shuffle(rnd.Shuffle)
hand := d.Draw(7)
fmt.Printf("%b\n", hand)
// Output:
// [9♣ 6♥ Q♠ 3♠ J♠ 9♥ K♣]
}
func ExampleNewHand() {
d := cardrank.NewDeck()
// note: use a real random source
rnd := rand.New(rand.NewSource(6265))
d.Shuffle(rnd.Shuffle)
hand := d.Draw(5)
h := cardrank.NewHand(cardrank.Holdem, hand, nil)
fmt.Printf("%b\n", h)
// Output:
// Four of a Kind, Eights, kicker Seven [8♣ 8♦ 8♥ 8♠ 7♠]
}
func ExampleHoldem_RankHand() {
d := cardrank.NewDeck()
// note: use a real random source
rnd := rand.New(rand.NewSource(26076))
d.Shuffle(rnd.Shuffle)
h := cardrank.Holdem.RankHand(d.Draw(5), d.Draw(2))
fmt.Printf("%b\n", h)
// Output:
// Straight Flush, Five-high, Steel Wheel [5♣ 4♣ 3♣ 2♣ A♣]
}
func Example_holdem() {
for i, game := range []struct {
seed int64
players int
}{
{3, 2},
{278062, 2},
{1928, 6},
{6151, 6},
{5680, 6},
{23965, 2},
{13959, 2},
{23366, 6},
{29555, 3},
{472600, 3},
{107, 10},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, board := cardrank.Holdem.Deal(rnd.Shuffle, game.players)
hands := cardrank.Holdem.RankHands(pockets, board)
fmt.Printf("------ Holdem %d ------\n", i+1)
fmt.Printf("Board: %b\n", board)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b %s %b %b\n", j+1, hands[j].Pocket(), hands[j].Description(), hands[j].Best(), hands[j].Unused())
}
h, pivot := cardrank.Order(hands)
if pivot == 1 {
fmt.Printf("Result: Player %d wins with %s %b\n", h[0]+1, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < pivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result: Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
}
// Output:
// ------ Holdem 1 ------
// Board: [J♠ T♠ 2♦ 2♠ Q♥]
// Player 1: [6♦ 8♠] Pair, Twos, kickers Queen, Jack, Ten [2♦ 2♠ Q♥ J♠ T♠] [8♠ 6♦]
// Player 2: [7♠ 4♣] Pair, Twos, kickers Queen, Jack, Ten [2♦ 2♠ Q♥ J♠ T♠] [7♠ 4♣]
// Result: Players 1, 2 push with Pair, Twos, kickers Queen, Jack, Ten [2♦ 2♠ Q♥ J♠ T♠], [2♦ 2♠ Q♥ J♠ T♠]
// ------ Holdem 2 ------
// Board: [8♠ 9♠ J♠ 9♣ T♠]
// Player 1: [7♠ T♣] Straight Flush, Jack-high [J♠ T♠ 9♠ 8♠ 7♠] [T♣ 9♣]
// Player 2: [6♦ Q♠] Straight Flush, Queen-high [Q♠ J♠ T♠ 9♠ 8♠] [9♣ 6♦]
// Result: Player 2 wins with Straight Flush, Queen-high [Q♠ J♠ T♠ 9♠ 8♠]
// ------ Holdem 3 ------
// Board: [A♠ T♣ K♠ J♣ 6♥]
// Player 1: [T♥ 2♠] Pair, Tens, kickers Ace, King, Jack [T♣ T♥ A♠ K♠ J♣] [6♥ 2♠]
// Player 2: [Q♣ J♠] Straight, Ace-high [A♠ K♠ Q♣ J♣ T♣] [J♠ 6♥]
// Player 3: [4♥ Q♠] Straight, Ace-high [A♠ K♠ Q♠ J♣ T♣] [6♥ 4♥]
// Player 4: [5♦ K♦] Pair, Kings, kickers Ace, Jack, Ten [K♦ K♠ A♠ J♣ T♣] [6♥ 5♦]
// Player 5: [Q♥ 7♣] Straight, Ace-high [A♠ K♠ Q♥ J♣ T♣] [7♣ 6♥]
// Player 6: [6♠ 3♣] Pair, Sixes, kickers Ace, King, Jack [6♥ 6♠ A♠ K♠ J♣] [T♣ 3♣]
// Result: Players 2, 3, 5 push with Straight, Ace-high [A♠ K♠ Q♣ J♣ T♣], [A♠ K♠ Q♠ J♣ T♣], [A♠ K♠ Q♥ J♣ T♣]
// ------ Holdem 4 ------
// Board: [9♦ J♣ A♥ 9♥ J♠]
// Player 1: [K♠ 7♦] Two Pair, Jacks over Nines, kicker Ace [J♣ J♠ 9♦ 9♥ A♥] [K♠ 7♦]
// Player 2: [A♦ 4♥] Two Pair, Aces over Jacks, kicker Nine [A♦ A♥ J♣ J♠ 9♦] [9♥ 4♥]
// Player 3: [3♥ T♣] Two Pair, Jacks over Nines, kicker Ace [J♣ J♠ 9♦ 9♥ A♥] [T♣ 3♥]
// Player 4: [8♦ 9♠] Full House, Nines full of Jacks [9♦ 9♥ 9♠ J♣ J♠] [A♥ 8♦]
// Player 5: [8♥ 6♣] Two Pair, Jacks over Nines, kicker Ace [J♣ J♠ 9♦ 9♥ A♥] [8♥ 6♣]
// Player 6: [5♥ J♦] Full House, Jacks full of Nines [J♣ J♦ J♠ 9♦ 9♥] [A♥ 5♥]
// Result: Player 6 wins with Full House, Jacks full of Nines [J♣ J♦ J♠ 9♦ 9♥]
// ------ Holdem 5 ------
// Board: [3♠ 9♥ A♦ 6♥ Q♦]
// Player 1: [T♦ 8♦] Nothing, Ace-high, kickers Queen, Ten, Nine, Eight [A♦ Q♦ T♦ 9♥ 8♦] [6♥ 3♠]
// Player 2: [K♠ T♣] Nothing, Ace-high, kickers King, Queen, Ten, Nine [A♦ K♠ Q♦ T♣ 9♥] [6♥ 3♠]
// Player 3: [7♥ 8♣] Nothing, Ace-high, kickers Queen, Nine, Eight, Seven [A♦ Q♦ 9♥ 8♣ 7♥] [6♥ 3♠]
// Player 4: [4♥ 7♦] Nothing, Ace-high, kickers Queen, Nine, Seven, Six [A♦ Q♦ 9♥ 7♦ 6♥] [4♥ 3♠]
// Player 5: [K♥ 5♦] Nothing, Ace-high, kickers King, Queen, Nine, Six [A♦ K♥ Q♦ 9♥ 6♥] [5♦ 3♠]
// Player 6: [T♥ 5♣] Nothing, Ace-high, kickers Queen, Ten, Nine, Six [A♦ Q♦ T♥ 9♥ 6♥] [5♣ 3♠]
// Result: Player 2 wins with Nothing, Ace-high, kickers King, Queen, Ten, Nine [A♦ K♠ Q♦ T♣ 9♥]
// ------ Holdem 6 ------
// Board: [T♥ 6♥ 7♥ 2♥ 7♣]
// Player 1: [6♣ 6♠] Full House, Sixes full of Sevens [6♣ 6♥ 6♠ 7♣ 7♥] [T♥ 2♥]
// Player 2: [K♥ 5♥] Flush, King-high [K♥ T♥ 7♥ 6♥ 5♥] [2♥ 7♣]
// Result: Player 1 wins with Full House, Sixes full of Sevens [6♣ 6♥ 6♠ 7♣ 7♥]
// ------ Holdem 7 ------
// Board: [4♦ A♥ A♣ 4♠ A♦]
// Player 1: [T♥ T♠] Full House, Aces full of Tens [A♣ A♦ A♥ T♥ T♠] [4♦ 4♠]
// Player 2: [9♣ A♠] Four of a Kind, Aces, kicker Four [A♣ A♦ A♥ A♠ 4♦] [4♠ 9♣]
// Result: Player 2 wins with Four of a Kind, Aces, kicker Four [A♣ A♦ A♥ A♠ 4♦]
// ------ Holdem 8 ------
// Board: [Q♥ T♥ T♠ J♥ K♥]
// Player 1: [A♥ 9♠] Straight Flush, Ace-high, Royal [A♥ K♥ Q♥ J♥ T♥] [T♠ 9♠]
// Player 2: [Q♣ 2♠] Two Pair, Queens over Tens, kicker King [Q♣ Q♥ T♥ T♠ K♥] [J♥ 2♠]
// Player 3: [6♥ 3♦] Flush, King-high [K♥ Q♥ J♥ T♥ 6♥] [T♠ 3♦]
// Player 4: [8♥ 8♦] Flush, King-high [K♥ Q♥ J♥ T♥ 8♥] [T♠ 8♦]
// Player 5: [4♦ Q♦] Two Pair, Queens over Tens, kicker King [Q♦ Q♥ T♥ T♠ K♥] [J♥ 4♦]
// Player 6: [A♦ T♣] Straight, Ace-high [A♦ K♥ Q♥ J♥ T♣] [T♥ T♠]
// Result: Player 1 wins with Straight Flush, Ace-high, Royal [A♥ K♥ Q♥ J♥ T♥]
// ------ Holdem 9 ------
// Board: [A♣ 2♣ 4♣ 5♣ 9♥]
// Player 1: [T♣ J♦] Flush, Ace-high [A♣ T♣ 5♣ 4♣ 2♣] [J♦ 9♥]
// Player 2: [4♥ 6♠] Pair, Fours, kickers Ace, Nine, Six [4♣ 4♥ A♣ 9♥ 6♠] [5♣ 2♣]
// Player 3: [3♣ T♠] Straight Flush, Five-high, Steel Wheel [5♣ 4♣ 3♣ 2♣ A♣] [T♠ 9♥]
// Result: Player 3 wins with Straight Flush, Five-high, Steel Wheel [5♣ 4♣ 3♣ 2♣ A♣]
// ------ Holdem 10 ------
// Board: [8♣ J♣ 8♥ 7♥ 9♥]
// Player 1: [8♦ 8♠] Four of a Kind, Eights, kicker Jack [8♣ 8♦ 8♥ 8♠ J♣] [9♥ 7♥]
// Player 2: [6♥ T♥] Straight Flush, Ten-high [T♥ 9♥ 8♥ 7♥ 6♥] [J♣ 8♣]
// Player 3: [3♣ K♥] Pair, Eights, kickers King, Jack, Nine [8♣ 8♥ K♥ J♣ 9♥] [7♥ 3♣]
// Result: Player 2 wins with Straight Flush, Ten-high [T♥ 9♥ 8♥ 7♥ 6♥]
// ------ Holdem 11 ------
// Board: [5♥ 3♣ J♥ 6♦ 6♣]
// Player 1: [8♥ 4♥] Pair, Sixes, kickers Jack, Eight, Five [6♣ 6♦ J♥ 8♥ 5♥] [4♥ 3♣]
// Player 2: [T♣ 3♥] Two Pair, Sixes over Threes, kicker Jack [6♣ 6♦ 3♣ 3♥ J♥] [T♣ 5♥]
// Player 3: [A♠ 6♠] Three of a Kind, Sixes, kickers Ace, Jack [6♣ 6♦ 6♠ A♠ J♥] [5♥ 3♣]
// Player 4: [J♠ 8♠] Two Pair, Jacks over Sixes, kicker Eight [J♥ J♠ 6♣ 6♦ 8♠] [5♥ 3♣]
// Player 5: [6♥ 2♣] Three of a Kind, Sixes, kickers Jack, Five [6♣ 6♦ 6♥ J♥ 5♥] [3♣ 2♣]
// Player 6: [T♥ Q♣] Pair, Sixes, kickers Queen, Jack, Ten [6♣ 6♦ Q♣ J♥ T♥] [5♥ 3♣]
// Player 7: [Q♠ 5♦] Two Pair, Sixes over Fives, kicker Queen [6♣ 6♦ 5♦ 5♥ Q♠] [J♥ 3♣]
// Player 8: [T♠ 2♠] Pair, Sixes, kickers Jack, Ten, Five [6♣ 6♦ J♥ T♠ 5♥] [3♣ 2♠]
// Player 9: [5♣ 9♦] Two Pair, Sixes over Fives, kicker Jack [6♣ 6♦ 5♣ 5♥ J♥] [9♦ 3♣]
// Player 10: [J♣ A♣] Two Pair, Jacks over Sixes, kicker Ace [J♣ J♥ 6♣ 6♦ A♣] [5♥ 3♣]
// Result: Player 3 wins with Three of a Kind, Sixes, kickers Ace, Jack [6♣ 6♦ 6♠ A♠ J♥]
}
func Example_shortDeck() {
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{155, 4},
{384, 8},
{880, 4},
{3453, 3},
{5662, 3},
{65481, 2},
{27947, 4},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, board := cardrank.ShortDeck.Deal(rnd.Shuffle, game.players)
hands := cardrank.ShortDeck.RankHands(pockets, board)
fmt.Printf("------ ShortDeck %d ------\n", i+1)
fmt.Printf("Board: %b\n", board)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b %s %b %b\n", j+1, hands[j].Pocket(), hands[j].Description(), hands[j].Best(), hands[j].Unused())
}
h, pivot := cardrank.Order(hands)
if pivot == 1 {
fmt.Printf("Result: Player %d wins with %s %b\n", h[0]+1, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < pivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result: Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
}
// Output:
// ------ ShortDeck 1 ------
// Board: [9♥ A♦ A♥ 8♣ A♣]
// Player 1: [8♥ 7♥] Full House, Aces full of Eights [A♣ A♦ A♥ 8♣ 8♥] [9♥ 7♥]
// Player 2: [A♠ J♦] Four of a Kind, Aces, kicker Jack [A♣ A♦ A♥ A♠ J♦] [9♥ 8♣]
// Result: Player 2 wins with Four of a Kind, Aces, kicker Jack [A♣ A♦ A♥ A♠ J♦]
// ------ ShortDeck 2 ------
// Board: [9♣ 6♦ A♠ J♠ 6♠]
// Player 1: [T♥ 6♣] Three of a Kind, Sixes, kickers Ace, Jack [6♣ 6♦ 6♠ A♠ J♠] [T♥ 9♣]
// Player 2: [6♥ 9♥] Full House, Sixes full of Nines [6♦ 6♥ 6♠ 9♣ 9♥] [A♠ J♠]
// Player 3: [A♣ 7♣] Two Pair, Aces over Sixes, kicker Jack [A♣ A♠ 6♦ 6♠ J♠] [9♣ 7♣]
// Player 4: [T♠ K♠] Flush, Ace-high [A♠ K♠ J♠ T♠ 6♠] [9♣ 6♦]
// Result: Player 4 wins with Flush, Ace-high [A♠ K♠ J♠ T♠ 6♠]
// ------ ShortDeck 3 ------
// Board: [T♥ J♣ 7♥ 9♥ K♣]
// Player 1: [8♥ T♠] Straight, Jack-high [J♣ T♥ 9♥ 8♥ 7♥] [K♣ T♠]
// Player 2: [J♠ 6♣] Pair, Jacks, kickers King, Ten, Nine [J♣ J♠ K♣ T♥ 9♥] [7♥ 6♣]
// Player 3: [7♦ 8♠] Straight, Jack-high [J♣ T♥ 9♥ 8♠ 7♦] [K♣ 7♥]
// Player 4: [9♣ A♥] Pair, Nines, kickers Ace, King, Jack [9♣ 9♥ A♥ K♣ J♣] [T♥ 7♥]
// Player 5: [T♣ Q♠] Straight, King-high [K♣ Q♠ J♣ T♣ 9♥] [T♥ 7♥]
// Player 6: [7♣ Q♦] Straight, King-high [K♣ Q♦ J♣ T♥ 9♥] [7♣ 7♥]
// Player 7: [6♠ 8♦] Straight, Jack-high [J♣ T♥ 9♥ 8♦ 7♥] [K♣ 6♠]
// Player 8: [K♥ K♦] Three of a Kind, Kings, kickers Jack, Ten [K♣ K♦ K♥ J♣ T♥] [9♥ 7♥]
// Result: Players 5, 6 push with Straight, King-high [K♣ Q♠ J♣ T♣ 9♥], [K♣ Q♦ J♣ T♥ 9♥]
// ------ ShortDeck 4 ------
// Board: [T♦ 9♣ 9♦ Q♦ 8♦]
// Player 1: [J♠ T♥] Straight, Queen-high [Q♦ J♠ T♦ 9♣ 8♦] [T♥ 9♦]
// Player 2: [6♣ A♣] Pair, Nines, kickers Ace, Queen, Ten [9♣ 9♦ A♣ Q♦ T♦] [8♦ 6♣]
// Player 3: [9♥ 8♠] Full House, Nines full of Eights [9♣ 9♦ 9♥ 8♦ 8♠] [Q♦ T♦]
// Player 4: [J♦ A♦] Straight Flush, Queen-high [Q♦ J♦ T♦ 9♦ 8♦] [9♣ A♦]
// Result: Player 4 wins with Straight Flush, Queen-high [Q♦ J♦ T♦ 9♦ 8♦]
// ------ ShortDeck 5 ------
// Board: [6♠ A♣ 7♦ A♠ 6♦]
// Player 1: [9♣ T♠] Two Pair, Aces over Sixes, kicker Ten [A♣ A♠ 6♦ 6♠ T♠] [9♣ 7♦]
// Player 2: [J♥ T♦] Two Pair, Aces over Sixes, kicker Jack [A♣ A♠ 6♦ 6♠ J♥] [T♦ 7♦]
// Player 3: [K♠ A♥] Full House, Aces full of Sixes [A♣ A♥ A♠ 6♦ 6♠] [K♠ 7♦]
// Result: Player 3 wins with Full House, Aces full of Sixes [A♣ A♥ A♠ 6♦ 6♠]
// ------ ShortDeck 6 ------
// Board: [A♣ 6♣ 9♣ T♦ 8♣]
// Player 1: [6♥ 7♣] Straight Flush, Nine-high, Iron Maiden [9♣ 8♣ 7♣ 6♣ A♣] [T♦ 6♥]
// Player 2: [6♠ 9♠] Two Pair, Nines over Sixes, kicker Ace [9♣ 9♠ 6♣ 6♠ A♣] [T♦ 8♣]
// Player 3: [J♥ Q♠] Straight, Queen-high [Q♠ J♥ T♦ 9♣ 8♣] [A♣ 6♣]
// Result: Player 1 wins with Straight Flush, Nine-high, Iron Maiden [9♣ 8♣ 7♣ 6♣ A♣]
// ------ ShortDeck 7 ------
// Board: [K♥ K♦ K♠ K♣ J♣]
// Player 1: [7♦ T♦] Four of a Kind, Kings, kicker Jack [K♣ K♦ K♥ K♠ J♣] [T♦ 7♦]
// Player 2: [8♦ 6♥] Four of a Kind, Kings, kicker Jack [K♣ K♦ K♥ K♠ J♣] [8♦ 6♥]
// Result: Players 1, 2 push with Four of a Kind, Kings, kicker Jack [K♣ K♦ K♥ K♠ J♣], [K♣ K♦ K♥ K♠ J♣]
// ------ ShortDeck 8 ------
// Board: [8♦ 8♥ 8♠ Q♠ T♦]
// Player 1: [J♦ T♣] Full House, Eights full of Tens [8♦ 8♥ 8♠ T♣ T♦] [Q♠ J♦]
// Player 2: [K♠ T♠] Full House, Eights full of Tens [8♦ 8♥ 8♠ T♦ T♠] [K♠ Q♠]
// Player 3: [9♣ J♣] Straight, Queen-high [Q♠ J♣ T♦ 9♣ 8♦] [8♥ 8♠]
// Player 4: [T♥ 7♥] Full House, Eights full of Tens [8♦ 8♥ 8♠ T♦ T♥] [Q♠ 7♥]
// Result: Players 1, 2, 4 push with Full House, Eights full of Tens [8♦ 8♥ 8♠ T♣ T♦], [8♦ 8♥ 8♠ T♦ T♠], [8♦ 8♥ 8♠ T♦ T♥]
}
func Example_omaha() {
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{321, 5},
{408, 6},
{455, 6},
{1113, 6},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, board := cardrank.Omaha.Deal(rnd.Shuffle, game.players)
hands := cardrank.Omaha.RankHands(pockets, board)
fmt.Printf("------ Omaha %d ------\n", i+1)
fmt.Printf("Board: %b\n", board)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b %s %b %b\n", j+1, hands[j].Pocket(), hands[j].Description(), hands[j].Best(), hands[j].Unused())
}
h, pivot := cardrank.Order(hands)
if pivot == 1 {
fmt.Printf("Result: Player %d wins with %s %b\n", h[0]+1, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < pivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result: Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
}
// Output:
// ------ Omaha 1 ------
// Board: [3♥ 5♥ 4♥ 7♥ K♣]
// Player 1: [K♥ 7♣ J♣ 4♣] Two Pair, Kings over Sevens, kicker Five [K♣ K♥ 7♣ 7♥ 5♥] [J♣ 4♣ 3♥ 4♥]
// Player 2: [A♥ 5♠ Q♠ 2♠] Straight, Five-high [5♥ 4♥ 3♥ 2♠ A♥] [5♠ Q♠ 7♥ K♣]
// Result: Player 2 wins with Straight, Five-high [5♥ 4♥ 3♥ 2♠ A♥]
// ------ Omaha 2 ------
// Board: [3♥ 7♣ 3♣ 9♠ 9♣]
// Player 1: [3♠ 6♦ Q♦ K♦] Three of a Kind, Threes, kickers King, Nine [3♣ 3♥ 3♠ K♦ 9♠] [6♦ Q♦ 7♣ 9♣]
// Player 2: [J♦ 3♦ Q♣ K♠] Three of a Kind, Threes, kickers King, Nine [3♣ 3♦ 3♥ K♠ 9♠] [J♦ Q♣ 7♣ 9♣]
// Player 3: [T♦ 2♥ T♠ 8♥] Two Pair, Tens over Nines, kicker Seven [T♦ T♠ 9♣ 9♠ 7♣] [2♥ 8♥ 3♥ 3♣]
// Player 4: [8♣ 8♦ Q♥ Q♠] Two Pair, Queens over Nines, kicker Seven [Q♥ Q♠ 9♣ 9♠ 7♣] [8♣ 8♦ 3♥ 3♣]
// Player 5: [6♣ A♥ 4♥ 6♠] Two Pair, Nines over Sixes, kicker Seven [9♣ 9♠ 6♣ 6♠ 7♣] [A♥ 4♥ 3♥ 3♣]
// Result: Players 1, 2 push with Three of a Kind, Threes, kickers King, Nine [3♣ 3♥ 3♠ K♦ 9♠], [3♣ 3♦ 3♥ K♠ 9♠]
// ------ Omaha 3 ------
// Board: [J♣ T♥ 4♥ K♣ Q♣]
// Player 1: [K♠ J♠ 3♠ 5♣] Two Pair, Kings over Jacks, kicker Queen [K♣ K♠ J♣ J♠ Q♣] [3♠ 5♣ T♥ 4♥]
// Player 2: [7♠ 4♠ Q♠ 3♣] Two Pair, Queens over Fours, kicker King [Q♣ Q♠ 4♥ 4♠ K♣] [7♠ 3♣ J♣ T♥]
// Player 3: [T♠ 5♥ 3♥ 8♦] Pair, Tens, kickers King, Queen, Eight [T♥ T♠ K♣ Q♣ 8♦] [5♥ 3♥ J♣ 4♥]
// Player 4: [4♣ 8♥ 2♣ T♦] Flush, King-high [K♣ Q♣ J♣ 4♣ 2♣] [8♥ T♦ T♥ 4♥]
// Player 5: [6♠ K♦ J♦ 2♠] Two Pair, Kings over Jacks, kicker Queen [K♣ K♦ J♣ J♦ Q♣] [6♠ 2♠ T♥ 4♥]
// Player 6: [Q♦ 2♦ A♣ T♣] Straight Flush, Ace-high, Royal [A♣ K♣ Q♣ J♣ T♣] [Q♦ 2♦ T♥ 4♥]
// Result: Player 6 wins with Straight Flush, Ace-high, Royal [A♣ K♣ Q♣ J♣ T♣]
// ------ Omaha 4 ------
// Board: [2♦ 6♦ 6♣ Q♣ 7♣]
// Player 1: [6♠ Q♥ 2♣ 9♠] Full House, Sixes full of Queens [6♣ 6♦ 6♠ Q♣ Q♥] [2♣ 9♠ 2♦ 7♣]
// Player 2: [3♦ T♣ K♥ 4♥] Pair, Sixes, kickers King, Queen, Ten [6♣ 6♦ K♥ Q♣ T♣] [3♦ 4♥ 2♦ 7♣]
// Player 3: [6♥ J♥ 4♦ Q♦] Full House, Sixes full of Queens [6♣ 6♦ 6♥ Q♣ Q♦] [J♥ 4♦ 2♦ 7♣]
// Player 4: [A♣ J♣ 5♣ K♠] Flush, Ace-high [A♣ Q♣ J♣ 7♣ 6♣] [5♣ K♠ 2♦ 6♦]
// Player 5: [K♣ A♠ 8♣ 5♥] Flush, King-high [K♣ Q♣ 8♣ 7♣ 6♣] [A♠ 5♥ 2♦ 6♦]
// Player 6: [Q♠ J♠ 8♦ 7♥] Two Pair, Queens over Sevens, kicker Six [Q♣ Q♠ 7♣ 7♥ 6♦] [J♠ 8♦ 2♦ 6♣]
// Result: Players 1, 3 push with Full House, Sixes full of Queens [6♣ 6♦ 6♠ Q♣ Q♥], [6♣ 6♦ 6♥ Q♣ Q♦]
// ------ Omaha 5 ------
// Board: [4♣ K♣ 6♦ 9♦ 5♠]
// Player 1: [3♦ T♥ A♣ 7♦] Straight, Seven-high [7♦ 6♦ 5♠ 4♣ 3♦] [T♥ A♣ K♣ 9♦]
// Player 2: [5♣ 6♠ 4♦ J♠] Two Pair, Sixes over Fives, kicker King [6♦ 6♠ 5♣ 5♠ K♣] [4♦ J♠ 4♣ 9♦]
// Player 3: [9♠ 3♣ Q♠ 7♠] Straight, Seven-high [7♠ 6♦ 5♠ 4♣ 3♣] [9♠ Q♠ K♣ 9♦]
// Player 4: [5♦ K♠ T♠ 8♠] Two Pair, Kings over Fives, kicker Nine [K♣ K♠ 5♦ 5♠ 9♦] [T♠ 8♠ 4♣ 6♦]
// Player 5: [J♥ 7♥ J♣ 2♣] Pair, Jacks, kickers King, Nine, Six [J♣ J♥ K♣ 9♦ 6♦] [7♥ 2♣ 4♣ 5♠]
// Player 6: [3♠ 7♣ 2♠ 2♥] Straight, Seven-high [7♣ 6♦ 5♠ 4♣ 3♠] [2♠ 2♥ K♣ 9♦]
// Result: Players 1, 3, 6 push with Straight, Seven-high [7♦ 6♦ 5♠ 4♣ 3♦], [7♠ 6♦ 5♠ 4♣ 3♣], [7♣ 6♦ 5♠ 4♣ 3♠]
}
func Example_omahaHiLo() {
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{321, 5},
{408, 6},
{455, 6},
{1113, 6},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, board := cardrank.OmahaHiLo.Deal(rnd.Shuffle, game.players)
hands := cardrank.OmahaHiLo.RankHands(pockets, board)
fmt.Printf("------ OmahaHiLo %d ------\n", i+1)
fmt.Printf("Board: %b\n", board)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b\n", j+1, pockets[j])
fmt.Printf(" Hi: %s %b %b\n", hands[j].Description(), hands[j].Best(), hands[j].Unused())
if hands[j].LowValid() {
fmt.Printf(" Lo: %s %b %b\n", hands[j].LowDescription(), hands[j].LowBest(), hands[j].LowUnused())
} else {
fmt.Printf(" Lo: None\n")
}
}
h, hPivot := cardrank.Order(hands)
l, lPivot := cardrank.LowOrder(hands)
typ := "wins"
if lPivot == 0 {
typ = "scoops"
}
if hPivot == 1 {
fmt.Printf("Result (Hi): Player %d %s with %s %b\n", h[0]+1, typ, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < hPivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result (Hi): Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
if lPivot == 1 {
fmt.Printf("Result (Lo): Player %d wins with %s %b\n", l[0]+1, hands[l[0]].LowDescription(), hands[l[0]].LowBest())
} else if lPivot > 1 {
var s, b []string
for j := 0; j < lPivot; j++ {
s = append(s, strconv.Itoa(l[j]+1))
b = append(b, fmt.Sprintf("%b", hands[l[j]].LowBest()))
}
fmt.Printf("Result (Lo): Players %s push with %s %s\n", strings.Join(s, ", "), hands[l[0]].LowDescription(), strings.Join(b, ", "))
} else {
fmt.Printf("Result (Lo): no player made a low hand\n")
}
}
// Output:
// ------ OmahaHiLo 1 ------
// Board: [3♥ 5♥ 4♥ 7♥ K♣]
// Player 1: [K♥ 7♣ J♣ 4♣]
// Hi: Two Pair, Kings over Sevens, kicker Five [K♣ K♥ 7♣ 7♥ 5♥] [J♣ 4♣ 3♥ 4♥]
// Lo: None
// Player 2: [A♥ 5♠ Q♠ 2♠]
// Hi: Straight, Five-high [5♥ 4♥ 3♥ 2♠ A♥] [5♠ Q♠ 7♥ K♣]
// Lo: Five-low [5♥ 4♥ 3♥ 2♠ A♥] [5♠ Q♠ 7♥ K♣]
// Result (Hi): Player 2 wins with Straight, Five-high [5♥ 4♥ 3♥ 2♠ A♥]
// Result (Lo): Player 2 wins with Five-low [5♥ 4♥ 3♥ 2♠ A♥]
// ------ OmahaHiLo 2 ------
// Board: [3♥ 7♣ 3♣ 9♠ 9♣]
// Player 1: [3♠ 6♦ Q♦ K♦]
// Hi: Three of a Kind, Threes, kickers King, Nine [3♣ 3♥ 3♠ K♦ 9♠] [6♦ Q♦ 7♣ 9♣]
// Lo: None
// Player 2: [J♦ 3♦ Q♣ K♠]
// Hi: Three of a Kind, Threes, kickers King, Nine [3♣ 3♦ 3♥ K♠ 9♠] [J♦ Q♣ 7♣ 9♣]
// Lo: None
// Player 3: [T♦ 2♥ T♠ 8♥]
// Hi: Two Pair, Tens over Nines, kicker Seven [T♦ T♠ 9♣ 9♠ 7♣] [2♥ 8♥ 3♥ 3♣]
// Lo: None
// Player 4: [8♣ 8♦ Q♥ Q♠]
// Hi: Two Pair, Queens over Nines, kicker Seven [Q♥ Q♠ 9♣ 9♠ 7♣] [8♣ 8♦ 3♥ 3♣]
// Lo: None
// Player 5: [6♣ A♥ 4♥ 6♠]
// Hi: Two Pair, Nines over Sixes, kicker Seven [9♣ 9♠ 6♣ 6♠ 7♣] [A♥ 4♥ 3♥ 3♣]
// Lo: None
// Result (Hi): Players 1, 2 push with Three of a Kind, Threes, kickers King, Nine [3♣ 3♥ 3♠ K♦ 9♠], [3♣ 3♦ 3♥ K♠ 9♠]
// Result (Lo): no player made a low hand
// ------ OmahaHiLo 3 ------
// Board: [J♣ T♥ 4♥ K♣ Q♣]
// Player 1: [K♠ J♠ 3♠ 5♣]
// Hi: Two Pair, Kings over Jacks, kicker Queen [K♣ K♠ J♣ J♠ Q♣] [3♠ 5♣ T♥ 4♥]
// Lo: None
// Player 2: [7♠ 4♠ Q♠ 3♣]
// Hi: Two Pair, Queens over Fours, kicker King [Q♣ Q♠ 4♥ 4♠ K♣] [7♠ 3♣ J♣ T♥]
// Lo: None
// Player 3: [T♠ 5♥ 3♥ 8♦]
// Hi: Pair, Tens, kickers King, Queen, Eight [T♥ T♠ K♣ Q♣ 8♦] [5♥ 3♥ J♣ 4♥]
// Lo: None
// Player 4: [4♣ 8♥ 2♣ T♦]
// Hi: Flush, King-high [K♣ Q♣ J♣ 4♣ 2♣] [8♥ T♦ T♥ 4♥]
// Lo: None
// Player 5: [6♠ K♦ J♦ 2♠]
// Hi: Two Pair, Kings over Jacks, kicker Queen [K♣ K♦ J♣ J♦ Q♣] [6♠ 2♠ T♥ 4♥]
// Lo: None
// Player 6: [Q♦ 2♦ A♣ T♣]
// Hi: Straight Flush, Ace-high, Royal [A♣ K♣ Q♣ J♣ T♣] [Q♦ 2♦ T♥ 4♥]
// Lo: None
// Result (Hi): Player 6 scoops with Straight Flush, Ace-high, Royal [A♣ K♣ Q♣ J♣ T♣]
// Result (Lo): no player made a low hand
// ------ OmahaHiLo 4 ------
// Board: [2♦ 6♦ 6♣ Q♣ 7♣]
// Player 1: [6♠ Q♥ 2♣ 9♠]
// Hi: Full House, Sixes full of Queens [6♣ 6♦ 6♠ Q♣ Q♥] [2♣ 9♠ 2♦ 7♣]
// Lo: None
// Player 2: [3♦ T♣ K♥ 4♥]
// Hi: Pair, Sixes, kickers King, Queen, Ten [6♣ 6♦ K♥ Q♣ T♣] [3♦ 4♥ 2♦ 7♣]
// Lo: Seven-low [7♣ 6♦ 4♥ 3♦ 2♦] [T♣ K♥ 6♣ Q♣]
// Player 3: [6♥ J♥ 4♦ Q♦]
// Hi: Full House, Sixes full of Queens [6♣ 6♦ 6♥ Q♣ Q♦] [J♥ 4♦ 2♦ 7♣]
// Lo: None
// Player 4: [A♣ J♣ 5♣ K♠]
// Hi: Flush, Ace-high [A♣ Q♣ J♣ 7♣ 6♣] [5♣ K♠ 2♦ 6♦]
// Lo: Seven-low [7♣ 6♦ 5♣ 2♦ A♣] [J♣ K♠ 6♣ Q♣]
// Player 5: [K♣ A♠ 8♣ 5♥]
// Hi: Flush, King-high [K♣ Q♣ 8♣ 7♣ 6♣] [A♠ 5♥ 2♦ 6♦]
// Lo: Seven-low [7♣ 6♦ 5♥ 2♦ A♠] [K♣ 8♣ 6♣ Q♣]
// Player 6: [Q♠ J♠ 8♦ 7♥]
// Hi: Two Pair, Queens over Sevens, kicker Six [Q♣ Q♠ 7♣ 7♥ 6♦] [J♠ 8♦ 2♦ 6♣]
// Lo: None
// Result (Hi): Players 1, 3 push with Full House, Sixes full of Queens [6♣ 6♦ 6♠ Q♣ Q♥], [6♣ 6♦ 6♥ Q♣ Q♦]
// Result (Lo): Player 2 wins with Seven-low [7♣ 6♦ 4♥ 3♦ 2♦]
// ------ OmahaHiLo 5 ------
// Board: [4♣ K♣ 6♦ 9♦ 5♠]
// Player 1: [3♦ T♥ A♣ 7♦]
// Hi: Straight, Seven-high [7♦ 6♦ 5♠ 4♣ 3♦] [T♥ A♣ K♣ 9♦]
// Lo: Six-low [6♦ 5♠ 4♣ 3♦ A♣] [T♥ 7♦ K♣ 9♦]
// Player 2: [5♣ 6♠ 4♦ J♠]
// Hi: Two Pair, Sixes over Fives, kicker King [6♦ 6♠ 5♣ 5♠ K♣] [4♦ J♠ 4♣ 9♦]
// Lo: None
// Player 3: [9♠ 3♣ Q♠ 7♠]
// Hi: Straight, Seven-high [7♠ 6♦ 5♠ 4♣ 3♣] [9♠ Q♠ K♣ 9♦]
// Lo: Seven-low [7♠ 6♦ 5♠ 4♣ 3♣] [9♠ Q♠ K♣ 9♦]
// Player 4: [5♦ K♠ T♠ 8♠]
// Hi: Two Pair, Kings over Fives, kicker Nine [K♣ K♠ 5♦ 5♠ 9♦] [T♠ 8♠ 4♣ 6♦]
// Lo: None
// Player 5: [J♥ 7♥ J♣ 2♣]
// Hi: Pair, Jacks, kickers King, Nine, Six [J♣ J♥ K♣ 9♦ 6♦] [7♥ 2♣ 4♣ 5♠]
// Lo: Seven-low [7♥ 6♦ 5♠ 4♣ 2♣] [J♥ J♣ K♣ 9♦]
// Player 6: [3♠ 7♣ 2♠ 2♥]
// Hi: Straight, Seven-high [7♣ 6♦ 5♠ 4♣ 3♠] [2♠ 2♥ K♣ 9♦]
// Lo: Six-low [6♦ 5♠ 4♣ 3♠ 2♠] [7♣ 2♥ K♣ 9♦]
// Result (Hi): Players 1, 3, 6 push with Straight, Seven-high [7♦ 6♦ 5♠ 4♣ 3♦], [7♠ 6♦ 5♠ 4♣ 3♣], [7♣ 6♦ 5♠ 4♣ 3♠]
// Result (Lo): Player 1 wins with Six-low [6♦ 5♠ 4♣ 3♦ A♣]
}
func Example_stud() {
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{321, 5},
{408, 6},
{455, 6},
{1113, 6},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, _ := cardrank.Stud.Deal(rnd.Shuffle, game.players)
hands := cardrank.Stud.RankHands(pockets, nil)
fmt.Printf("------ Stud %d ------\n", i+1)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b %s %b %b\n", j+1, hands[j].Pocket(), hands[j].Description(), hands[j].Best(), hands[j].Unused())
}
h, pivot := cardrank.Order(hands)
if pivot == 1 {
fmt.Printf("Result: Player %d wins with %s %b\n", h[0]+1, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < pivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result: Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
}
// Output:
// ------ Stud 1 ------
// Player 1: [K♥ 7♣ J♣ 4♣ A♥ 5♠ Q♠] Nothing, Ace-high, kickers King, Queen, Jack, Seven [A♥ K♥ Q♠ J♣ 7♣] [5♠ 4♣]
// Player 2: [2♠ 6♣ 3♥ 5♥ 4♥ Q♦ 7♥] Straight, Seven-high [7♥ 6♣ 5♥ 4♥ 3♥] [Q♦ 2♠]
// Result: Player 2 wins with Straight, Seven-high [7♥ 6♣ 5♥ 4♥ 3♥]
// ------ Stud 2 ------
// Player 1: [3♠ 6♦ Q♦ K♦ J♦ 3♦ Q♣] Flush, King-high [K♦ Q♦ J♦ 6♦ 3♦] [Q♣ 3♠]
// Player 2: [K♠ T♦ 2♥ T♠ 8♥ 8♣ 8♦] Full House, Eights full of Tens [8♣ 8♦ 8♥ T♦ T♠] [K♠ 2♥]
// Player 3: [Q♥ Q♠ 6♣ A♥ 4♥ 6♠ T♥] Two Pair, Queens over Sixes, kicker Ace [Q♥ Q♠ 6♣ 6♠ A♥] [T♥ 4♥]
// Player 4: [3♥ 7♣ 3♣ 5♦ 9♠ T♣ 9♣] Two Pair, Nines over Threes, kicker Ten [9♣ 9♠ 3♣ 3♥ T♣] [7♣ 5♦]
// Player 5: [J♠ 7♠ K♥ 7♥ 2♣ 2♦ A♦] Two Pair, Sevens over Twos, kicker Ace [7♥ 7♠ 2♣ 2♦ A♦] [K♥ J♠]
// Result: Player 2 wins with Full House, Eights full of Tens [8♣ 8♦ 8♥ T♦ T♠]
// ------ Stud 3 ------
// Player 1: [K♠ J♠ 3♠ 5♣ 7♠ 4♠ Q♠] Flush, King-high [K♠ Q♠ J♠ 7♠ 4♠] [3♠ 5♣]
// Player 2: [3♣ T♠ 5♥ 3♥ 8♦ 4♣ 8♥] Two Pair, Eights over Threes, kicker Ten [8♦ 8♥ 3♣ 3♥ T♠] [5♥ 4♣]
// Player 3: [2♣ T♦ 6♠ K♦ J♦ 2♠ Q♦] Pair, Twos, kickers King, Queen, Jack [2♣ 2♠ K♦ Q♦ J♦] [T♦ 6♠]
// Player 4: [2♦ A♣ T♣ 7♥ J♣ T♥ 4♥] Pair, Tens, kickers Ace, Jack, Seven [T♣ T♥ A♣ J♣ 7♥] [4♥ 2♦]
// Player 5: [8♠ K♣ 7♣ Q♣ K♥ 9♦ 6♦] Pair, Kings, kickers Queen, Nine, Eight [K♣ K♥ Q♣ 9♦ 8♠] [7♣ 6♦]
// Player 6: [5♠ J♥ 7♦ 3♦ 2♥ A♦ 9♣] Nothing, Ace-high, kickers Jack, Nine, Seven, Five [A♦ J♥ 9♣ 7♦ 5♠] [3♦ 2♥]
// Result: Player 1 wins with Flush, King-high [K♠ Q♠ J♠ 7♠ 4♠]
// ------ Stud 4 ------
// Player 1: [6♠ Q♥ 2♣ 9♠ 3♦ T♣ K♥] Nothing, King-high, kickers Queen, Ten, Nine, Six [K♥ Q♥ T♣ 9♠ 6♠] [3♦ 2♣]
// Player 2: [4♥ 6♥ J♥ 4♦ Q♦ A♣ J♣] Two Pair, Jacks over Fours, kicker Ace [J♣ J♥ 4♦ 4♥ A♣] [Q♦ 6♥]
// Player 3: [5♣ K♠ K♣ A♠ 8♣ 5♥ Q♠] Two Pair, Kings over Fives, kicker Ace [K♣ K♠ 5♣ 5♥ A♠] [Q♠ 8♣]
// Player 4: [J♠ 8♦ 7♥ 2♠ 2♦ 6♦ 6♣] Two Pair, Sixes over Twos, kicker Jack [6♣ 6♦ 2♦ 2♠ J♠] [8♦ 7♥]
// Player 5: [8♥ Q♣ 5♦ 7♣ 9♥ K♦ 9♣] Pair, Nines, kickers King, Queen, Eight [9♣ 9♥ K♦ Q♣ 8♥] [7♣ 5♦]
// Player 6: [7♦ A♥ 3♠ 3♣ T♠ T♥ 2♥] Two Pair, Tens over Threes, kicker Ace [T♥ T♠ 3♣ 3♠ A♥] [7♦ 2♥]
// Result: Player 3 wins with Two Pair, Kings over Fives, kicker Ace [K♣ K♠ 5♣ 5♥ A♠]
// ------ Stud 5 ------
// Player 1: [3♦ T♥ A♣ 7♦ 5♣ 6♠ 4♦] Straight, Seven-high [7♦ 6♠ 5♣ 4♦ 3♦] [A♣ T♥]
// Player 2: [J♠ 9♠ 3♣ Q♠ 7♠ 5♦ K♠] Flush, King-high [K♠ Q♠ J♠ 9♠ 7♠] [5♦ 3♣]
// Player 3: [T♠ 8♠ J♥ 7♥ J♣ 2♣ 3♠] Pair, Jacks, kickers Ten, Eight, Seven [J♣ J♥ T♠ 8♠ 7♥] [3♠ 2♣]
// Player 4: [7♣ 2♠ 2♥ 4♥ 4♣ K♣ 6♦] Two Pair, Fours over Twos, kicker King [4♣ 4♥ 2♥ 2♠ K♣] [7♣ 6♦]
// Player 5: [A♠ 9♦ K♥ 5♠ 8♦ 6♥ 8♥] Pair, Eights, kickers Ace, King, Nine [8♦ 8♥ A♠ K♥ 9♦] [6♥ 5♠]
// Player 6: [K♦ 8♣ 2♦ A♥ 6♣ 4♠ T♦] Nothing, Ace-high, kickers King, Ten, Eight, Six [A♥ K♦ T♦ 8♣ 6♣] [4♠ 2♦]
// Result: Player 2 wins with Flush, King-high [K♠ Q♠ J♠ 9♠ 7♠]
}
func Example_studHiLo() {
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{321, 5},
{408, 6},
{455, 6},
{1113, 6},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, _ := cardrank.StudHiLo.Deal(rnd.Shuffle, game.players)
hands := cardrank.StudHiLo.RankHands(pockets, nil)
fmt.Printf("------ StudHiLo %d ------\n", i+1)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b\n", j+1, pockets[j])
fmt.Printf(" Hi: %s %b %b\n", hands[j].Description(), hands[j].Best(), hands[j].Unused())
if hands[j].LowValid() {
fmt.Printf(" Lo: %s %b %b\n", hands[j].LowDescription(), hands[j].LowBest(), hands[j].LowUnused())
} else {
fmt.Printf(" Lo: None\n")
}
}
h, hPivot := cardrank.Order(hands)
l, lPivot := cardrank.LowOrder(hands)
typ := "wins"
if lPivot == 0 {
typ = "scoops"
}
if hPivot == 1 {
fmt.Printf("Result (Hi): Player %d %s with %s %b\n", h[0]+1, typ, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < hPivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result (Hi): Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
if lPivot == 1 {
fmt.Printf("Result (Lo): Player %d wins with %s %b\n", l[0]+1, hands[l[0]].LowDescription(), hands[l[0]].LowBest())
} else if lPivot > 1 {
var s, b []string
for j := 0; j < lPivot; j++ {
s = append(s, strconv.Itoa(l[j]+1))
b = append(b, fmt.Sprintf("%b", hands[l[j]].LowBest()))
}
fmt.Printf("Result (Lo): Players %s push with %s %s\n", strings.Join(s, ", "), hands[l[0]].LowDescription(), strings.Join(b, ", "))
} else {
fmt.Printf("Result (Lo): no player made a low hand\n")
}
}
// Output:
// ------ StudHiLo 1 ------
// Player 1: [K♥ 7♣ J♣ 4♣ A♥ 5♠ Q♠]
// Hi: Nothing, Ace-high, kickers King, Queen, Jack, Seven [A♥ K♥ Q♠ J♣ 7♣] [5♠ 4♣]
// Lo: None
// Player 2: [2♠ 6♣ 3♥ 5♥ 4♥ Q♦ 7♥]
// Hi: Straight, Seven-high [7♥ 6♣ 5♥ 4♥ 3♥] [Q♦ 2♠]
// Lo: Six-low [6♣ 5♥ 4♥ 3♥ 2♠] [Q♦ 7♥]
// Result (Hi): Player 2 wins with Straight, Seven-high [7♥ 6♣ 5♥ 4♥ 3♥]
// Result (Lo): Player 2 wins with Six-low [6♣ 5♥ 4♥ 3♥ 2♠]
// ------ StudHiLo 2 ------
// Player 1: [3♠ 6♦ Q♦ K♦ J♦ 3♦ Q♣]
// Hi: Flush, King-high [K♦ Q♦ J♦ 6♦ 3♦] [Q♣ 3♠]
// Lo: None
// Player 2: [K♠ T♦ 2♥ T♠ 8♥ 8♣ 8♦]
// Hi: Full House, Eights full of Tens [8♣ 8♦ 8♥ T♦ T♠] [K♠ 2♥]
// Lo: None
// Player 3: [Q♥ Q♠ 6♣ A♥ 4♥ 6♠ T♥]
// Hi: Two Pair, Queens over Sixes, kicker Ace [Q♥ Q♠ 6♣ 6♠ A♥] [T♥ 4♥]
// Lo: None
// Player 4: [3♥ 7♣ 3♣ 5♦ 9♠ T♣ 9♣]
// Hi: Two Pair, Nines over Threes, kicker Ten [9♣ 9♠ 3♣ 3♥ T♣] [7♣ 5♦]
// Lo: None
// Player 5: [J♠ 7♠ K♥ 7♥ 2♣ 2♦ A♦]
// Hi: Two Pair, Sevens over Twos, kicker Ace [7♥ 7♠ 2♣ 2♦ A♦] [K♥ J♠]
// Lo: None
// Result (Hi): Player 2 scoops with Full House, Eights full of Tens [8♣ 8♦ 8♥ T♦ T♠]
// Result (Lo): no player made a low hand
// ------ StudHiLo 3 ------
// Player 1: [K♠ J♠ 3♠ 5♣ 7♠ 4♠ Q♠]
// Hi: Flush, King-high [K♠ Q♠ J♠ 7♠ 4♠] [3♠ 5♣]
// Lo: None
// Player 2: [3♣ T♠ 5♥ 3♥ 8♦ 4♣ 8♥]
// Hi: Two Pair, Eights over Threes, kicker Ten [8♦ 8♥ 3♣ 3♥ T♠] [5♥ 4♣]
// Lo: None
// Player 3: [2♣ T♦ 6♠ K♦ J♦ 2♠ Q♦]
// Hi: Pair, Twos, kickers King, Queen, Jack [2♣ 2♠ K♦ Q♦ J♦] [T♦ 6♠]
// Lo: None
// Player 4: [2♦ A♣ T♣ 7♥ J♣ T♥ 4♥]
// Hi: Pair, Tens, kickers Ace, Jack, Seven [T♣ T♥ A♣ J♣ 7♥] [4♥ 2♦]
// Lo: None
// Player 5: [8♠ K♣ 7♣ Q♣ K♥ 9♦ 6♦]
// Hi: Pair, Kings, kickers Queen, Nine, Eight [K♣ K♥ Q♣ 9♦ 8♠] [7♣ 6♦]
// Lo: None
// Player 6: [5♠ J♥ 7♦ 3♦ 2♥ A♦ 9♣]
// Hi: Nothing, Ace-high, kickers Jack, Nine, Seven, Five [A♦ J♥ 9♣ 7♦ 5♠] [3♦ 2♥]
// Lo: Seven-low [7♦ 5♠ 3♦ 2♥ A♦] [J♥ 9♣]
// Result (Hi): Player 1 wins with Flush, King-high [K♠ Q♠ J♠ 7♠ 4♠]
// Result (Lo): Player 6 wins with Seven-low [7♦ 5♠ 3♦ 2♥ A♦]
// ------ StudHiLo 4 ------
// Player 1: [6♠ Q♥ 2♣ 9♠ 3♦ T♣ K♥]
// Hi: Nothing, King-high, kickers Queen, Ten, Nine, Six [K♥ Q♥ T♣ 9♠ 6♠] [3♦ 2♣]
// Lo: None
// Player 2: [4♥ 6♥ J♥ 4♦ Q♦ A♣ J♣]
// Hi: Two Pair, Jacks over Fours, kicker Ace [J♣ J♥ 4♦ 4♥ A♣] [Q♦ 6♥]
// Lo: None
// Player 3: [5♣ K♠ K♣ A♠ 8♣ 5♥ Q♠]
// Hi: Two Pair, Kings over Fives, kicker Ace [K♣ K♠ 5♣ 5♥ A♠] [Q♠ 8♣]
// Lo: None
// Player 4: [J♠ 8♦ 7♥ 2♠ 2♦ 6♦ 6♣]
// Hi: Two Pair, Sixes over Twos, kicker Jack [6♣ 6♦ 2♦ 2♠ J♠] [8♦ 7♥]
// Lo: None
// Player 5: [8♥ Q♣ 5♦ 7♣ 9♥ K♦ 9♣]
// Hi: Pair, Nines, kickers King, Queen, Eight [9♣ 9♥ K♦ Q♣ 8♥] [7♣ 5♦]
// Lo: None
// Player 6: [7♦ A♥ 3♠ 3♣ T♠ T♥ 2♥]
// Hi: Two Pair, Tens over Threes, kicker Ace [T♥ T♠ 3♣ 3♠ A♥] [7♦ 2♥]
// Lo: None
// Result (Hi): Player 3 scoops with Two Pair, Kings over Fives, kicker Ace [K♣ K♠ 5♣ 5♥ A♠]
// Result (Lo): no player made a low hand
// ------ StudHiLo 5 ------
// Player 1: [3♦ T♥ A♣ 7♦ 5♣ 6♠ 4♦]
// Hi: Straight, Seven-high [7♦ 6♠ 5♣ 4♦ 3♦] [A♣ T♥]
// Lo: Six-low [6♠ 5♣ 4♦ 3♦ A♣] [T♥ 7♦]
// Player 2: [J♠ 9♠ 3♣ Q♠ 7♠ 5♦ K♠]
// Hi: Flush, King-high [K♠ Q♠ J♠ 9♠ 7♠] [5♦ 3♣]
// Lo: None
// Player 3: [T♠ 8♠ J♥ 7♥ J♣ 2♣ 3♠]
// Hi: Pair, Jacks, kickers Ten, Eight, Seven [J♣ J♥ T♠ 8♠ 7♥] [3♠ 2♣]
// Lo: None
// Player 4: [7♣ 2♠ 2♥ 4♥ 4♣ K♣ 6♦]
// Hi: Two Pair, Fours over Twos, kicker King [4♣ 4♥ 2♥ 2♠ K♣] [7♣ 6♦]
// Lo: None
// Player 5: [A♠ 9♦ K♥ 5♠ 8♦ 6♥ 8♥]
// Hi: Pair, Eights, kickers Ace, King, Nine [8♦ 8♥ A♠ K♥ 9♦] [6♥ 5♠]
// Lo: None
// Player 6: [K♦ 8♣ 2♦ A♥ 6♣ 4♠ T♦]
// Hi: Nothing, Ace-high, kickers King, Ten, Eight, Six [A♥ K♦ T♦ 8♣ 6♣] [4♠ 2♦]
// Lo: Eight-low [8♣ 6♣ 4♠ 2♦ A♥] [K♦ T♦]
// Result (Hi): Player 2 wins with Flush, King-high [K♠ Q♠ J♠ 9♠ 7♠]
// Result (Lo): Player 1 wins with Six-low [6♠ 5♣ 4♦ 3♦ A♣]
}
func Example_razz() {
// not currently working
return
for i, game := range []struct {
seed int64
players int
}{
{119, 2},
{321, 5},
{408, 6},
{455, 6},
{1113, 6},
} {
// note: use a real random source
rnd := rand.New(rand.NewSource(game.seed))
pockets, _ := cardrank.Razz.Deal(rnd.Shuffle, game.players)
hands := cardrank.Razz.RankHands(pockets, nil)
fmt.Printf("------ Razz %d ------\n", i+1)
for j := 0; j < game.players; j++ {
fmt.Printf("Player %d: %b %s %b %b\n", j+1, hands[j].Pocket(), hands[j].Description(), hands[j].Best(), hands[j].Unused())
}
h, pivot := cardrank.Order(hands)
if pivot == 1 {
fmt.Printf("Result: Player %d wins with %s %b\n", h[0]+1, hands[h[0]].Description(), hands[h[0]].Best())
} else {
var s, b []string
for j := 0; j < pivot; j++ {
s = append(s, strconv.Itoa(h[j]+1))
b = append(b, fmt.Sprintf("%b", hands[h[j]].Best()))
}
fmt.Printf("Result: Players %s push with %s %s\n", strings.Join(s, ", "), hands[h[0]].Description(), strings.Join(b, ", "))
}
}
// Output:
}