Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chehsunliu/poker
A pure Go library for poker hand evaluation.
https://github.com/chehsunliu/poker
go golang poker texas-holdem texasholdem
Last synced: 16 days ago
JSON representation
A pure Go library for poker hand evaluation.
- Host: GitHub
- URL: https://github.com/chehsunliu/poker
- Owner: chehsunliu
- License: mit
- Created: 2018-07-19T12:55:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T05:48:36.000Z (over 1 year ago)
- Last Synced: 2024-06-18T17:13:13.958Z (7 months ago)
- Topics: go, golang, poker, texas-holdem, texasholdem
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 61
- Watchers: 4
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Poker
[![Build](https://github.com/chehsunliu/poker/actions/workflows/build.yml/badge.svg)](https://github.com/chehsunliu/poker/actions/workflows/build.yml)
[![GoDoc](https://godoc.org/github.com/chehsunliu/poker?status.svg)](https://godoc.org/github.com/chehsunliu/poker)Poker is ported from the Python library [worldveil/deuces](https://github.com/worldveil/deuces).
## Installation
Use `go get` to install Poker:
```sh
$ go get github.com/chehsunliu/poker
```## Usage
Support 5-, 6-, and 7-card evalutions:
```go
package mainimport (
"fmt""github.com/chehsunliu/poker"
)func main() {
deck := poker.NewDeck()
hand := deck.Draw(7)
fmt.Println(hand)rank := poker.Evaluate(hand)
fmt.Println(rank)
fmt.Println(poker.RankString(rank))
}
``````sh
$ go run ./main.go
[Kd 4h Qh 3s 8s 5h Jd]
6695
High Card$ go run ./main.go
[4c Qh Ad 9c 9s 3h 4d]
3062
Two Pair$ go run ./main.go
[Jh Qd Kd Qs 7d As Qh]
1742
Three of a Kind
```## Performance
Compared with [notnil/joker](https://github.com/notnil/joker), Poker is 160x faster on 5-card evaluation, and drops to 40x faster on 7-card evaluation.
```sh
go test -bench=. -benchtime 5s
goos: darwin
goarch: amd64
pkg: github.com/chehsunliu/poker
BenchmarkFivePoker-4 23396181 253 ns/op
BenchmarkFiveJoker-4 141036 41662 ns/op
BenchmarkSixPoker-4 3037298 1949 ns/op
BenchmarkSixJoker-4 28158 211533 ns/op
BenchmarkSevenPoker-4 356448 16357 ns/op
BenchmarkSevenJoker-4 7143 759394 ns/op
PASS
ok github.com/chehsunliu/poker 40.111s
```