-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
36 lines (33 loc) · 1.04 KB
/
main.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
package main
import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
"cardrank.io/cardrank"
)
func main() {
const players = 6
seed := time.Now().UnixNano()
// note: use a better pseudo-random number generator
rnd := rand.New(rand.NewSource(seed))
pockets, board := cardrank.Holdem.Deal(rnd.Shuffle, players)
hands := cardrank.Holdem.RankHands(pockets, board)
fmt.Printf("------ Holdem %d ------\n", seed)
fmt.Printf("Board: %b\n", board)
for i := 0; i < players; i++ {
fmt.Printf("Player %d: %b %s %b %b\n", i+1, hands[i].Pocket(), hands[i].Description(), hands[i].Best(), hands[i].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, ", "))
}
}