poker_odds 0.2.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +47 -0
- data/.github/workflows/release.yml +61 -0
- data/.travis.yml +7 -0
- data/CLAUDE.md +66 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +154 -0
- data/Rakefile +25 -0
- data/lib/poker_odds/3.2/poker_odds.so +0 -0
- data/lib/poker_odds/3.3/poker_odds.so +0 -0
- data/lib/poker_odds/3.4/poker_odds.so +0 -0
- data/lib/poker_odds/hand.rb +66 -0
- data/lib/poker_odds/version.rb +5 -0
- data/lib/poker_odds.rb +9 -0
- data/mise.toml +2 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 23bb6767de09667714dad915d0a3d745870304b489abc81caf92a4f4119c4a19
|
|
4
|
+
data.tar.gz: 7e0000dbfbca83de5a09f361ddb4302e5ba487a4574a3dd47007266bb553f895
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: faf16d4694bad1df64525cfbe57373dd537145d4d0d2b57c2cbce877cf5537805261916a42da3b1befd5c4ae9b78e0f564f8aa4be2dad0af25e23edc51e0260d
|
|
7
|
+
data.tar.gz: 3fff727d76a96951cf73d4c3fc70fc4f5eec480b96999d6fc31248b66fdb2cf2daae59b388e170c5988cc346e736fc75b4d9d7176472cc8112ce93a6750984e2
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby-version: ["3.2", "3.3", "3.4"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
|
|
25
|
+
- name: Set up Rust
|
|
26
|
+
uses: dtolnay/rust-toolchain@stable
|
|
27
|
+
|
|
28
|
+
- name: Compile native extension
|
|
29
|
+
run: bundle exec rake compile
|
|
30
|
+
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: bundle exec rspec
|
|
33
|
+
|
|
34
|
+
lint:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
|
|
40
|
+
- name: Set up Ruby
|
|
41
|
+
uses: ruby/setup-ruby@v1
|
|
42
|
+
with:
|
|
43
|
+
ruby-version: "3.4"
|
|
44
|
+
bundler-cache: true
|
|
45
|
+
|
|
46
|
+
- name: Run RuboCop
|
|
47
|
+
run: bundle exec rubocop
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
cross-compile:
|
|
13
|
+
name: Cross-compile (${{ matrix.platform }})
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
platform:
|
|
19
|
+
- x86_64-linux
|
|
20
|
+
- aarch64-linux
|
|
21
|
+
- x86_64-darwin
|
|
22
|
+
- arm64-darwin
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- uses: ruby/setup-ruby@v1
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: "3.4"
|
|
30
|
+
bundler-cache: true
|
|
31
|
+
|
|
32
|
+
- uses: oxidize-rb/actions/cross-gem@v1
|
|
33
|
+
with:
|
|
34
|
+
platform: ${{ matrix.platform }}
|
|
35
|
+
ruby-versions: "3.2,3.3,3.4"
|
|
36
|
+
|
|
37
|
+
- uses: actions/upload-artifact@v4
|
|
38
|
+
with:
|
|
39
|
+
name: gem-${{ matrix.platform }}
|
|
40
|
+
path: pkg/*-${{ matrix.platform }}.gem
|
|
41
|
+
if-no-files-found: error
|
|
42
|
+
|
|
43
|
+
release:
|
|
44
|
+
name: Publish to RubyGems
|
|
45
|
+
needs: cross-compile
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
timeout-minutes: 10
|
|
48
|
+
permissions:
|
|
49
|
+
id-token: write # for OIDC trusted publishing
|
|
50
|
+
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/download-artifact@v4
|
|
53
|
+
with:
|
|
54
|
+
pattern: gem-*
|
|
55
|
+
merge-multiple: true
|
|
56
|
+
path: pkg/
|
|
57
|
+
|
|
58
|
+
- uses: rubygems/configure-rubygems-credentials@v1.0.0
|
|
59
|
+
|
|
60
|
+
- name: Push all gems to RubyGems
|
|
61
|
+
run: find pkg/ -name "*.gem" | sort | xargs -I{} gem push {}
|
data/.travis.yml
ADDED
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
bin/setup
|
|
10
|
+
# or
|
|
11
|
+
bundle install
|
|
12
|
+
|
|
13
|
+
# Run all tests
|
|
14
|
+
bundle exec rspec
|
|
15
|
+
# or
|
|
16
|
+
rake spec
|
|
17
|
+
|
|
18
|
+
# Run a single test file
|
|
19
|
+
bundle exec rspec spec/poker_odds_spec.rb
|
|
20
|
+
|
|
21
|
+
# Run a single example by line number
|
|
22
|
+
bundle exec rspec spec/poker_odds_spec.rb:10
|
|
23
|
+
|
|
24
|
+
# Interactive console with Pry
|
|
25
|
+
bundle exec bin/console
|
|
26
|
+
|
|
27
|
+
# Build gem
|
|
28
|
+
bundle exec rake build
|
|
29
|
+
|
|
30
|
+
# Install gem locally
|
|
31
|
+
bundle exec rake install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
This is a Ruby gem (`poker_odds`) that calculates poker hand equity using Monte Carlo and combinatorial simulations.
|
|
37
|
+
|
|
38
|
+
### Core module: `PokerOdds::Hand` (`lib/poker_odds/hand.rb`)
|
|
39
|
+
|
|
40
|
+
The central class. Uses `virtus` gem for typed attributes and `poker_trump` gem for card representation and hand scoring.
|
|
41
|
+
|
|
42
|
+
**Attributes (set via Virtus or DSL setters):**
|
|
43
|
+
- `player_hands` — Array of player hole card pairs
|
|
44
|
+
- `flop_cards`, `turn_card`, `river_card` — Community cards
|
|
45
|
+
- `expose_cards` — Cards known to be out of the deck
|
|
46
|
+
|
|
47
|
+
**DSL setters** parse comma-separated card strings:
|
|
48
|
+
```ruby
|
|
49
|
+
round.player = '9d 9c, Kd Kc' # sets player_hands
|
|
50
|
+
round.flop = 'Ah 9h Jd'
|
|
51
|
+
round.turn = '3d'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Equity methods** — each returns a hash keyed by player hand, with `{ win_rate:, lose_rate:, tie_rate:, outs: }`:
|
|
55
|
+
|
|
56
|
+
| Method | Stage | Strategy |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| `equities` | Turn (river unknown) | Exhaustive iteration over remaining deck |
|
|
59
|
+
| `flop_equities` | Flop (turn+river unknown) | Exhaustive combinations of remaining deck |
|
|
60
|
+
| `preflop_equities` | Preflop | Monte Carlo (10,000 random samples) |
|
|
61
|
+
|
|
62
|
+
**`deck` method** computes remaining cards by removing all known cards (player hands, community cards, exposed cards) from a full 52-card deck.
|
|
63
|
+
|
|
64
|
+
### Known bug
|
|
65
|
+
|
|
66
|
+
`hand.rb` `river=` setter references `str` instead of the parameter `s` — calling `round.river = 'Xx'` will raise `NameError`.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at kyohah@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 kyohah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# PokerOdds
|
|
2
|
+
|
|
3
|
+
Texas Hold'em のポーカーハンドエクイティ計算 Ruby gem です。
|
|
4
|
+
内部に Rust ネイティブ拡張を持ち、完全探索によって高速にエクイティ・アウツを算出します。
|
|
5
|
+
|
|
6
|
+
## 特徴
|
|
7
|
+
|
|
8
|
+
- **高速**: Rust 製ハンド評価エンジン [holdem-hand-evaluator](https://github.com/b-inary/holdem-hand-evaluator) を採用(〜12億評価/秒)
|
|
9
|
+
- **完全探索**: モンテカルロではなく全残余カードの組み合わせを網羅
|
|
10
|
+
- **プリコンパイル済みバイナリ配布**: 主要プラットフォーム向けにコンパイル済みgemを提供するため、利用時に Rust は不要
|
|
11
|
+
- **アウツ計算**: 負けているハンドが逆転できるカード(アウツ)を返す
|
|
12
|
+
|
|
13
|
+
## インストール
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "poker_odds"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
bundle install
|
|
21
|
+
# または
|
|
22
|
+
gem install poker_odds
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 使い方
|
|
26
|
+
|
|
27
|
+
### equities — ターン後(残りリバーを全探索)
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
round = PokerOdds::Hand.new
|
|
31
|
+
round.flop = "Ah 9h Jd"
|
|
32
|
+
round.turn = "3d"
|
|
33
|
+
round.player = "9d 9c, Kd Kc"
|
|
34
|
+
|
|
35
|
+
result = round.equities
|
|
36
|
+
# => {
|
|
37
|
+
# "9d9c" => { win_rate: 0.954, lose_rate: 0.045, tie_rate: 0.0, outs: [] },
|
|
38
|
+
# "KdKc" => { win_rate: 0.045, lose_rate: 0.954, tie_rate: 0.0, outs: ["Kh", "Ks"] }
|
|
39
|
+
# }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`outs` は負けているハンドが勝てるリバーカードの配列です。
|
|
43
|
+
|
|
44
|
+
### flop_equities — フロップ後(ターン+リバーの全組み合わせを探索)
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
round = PokerOdds::Hand.new
|
|
48
|
+
round.flop = "Ah 9h Jd"
|
|
49
|
+
round.player = "9d 9c, Kd Kc"
|
|
50
|
+
|
|
51
|
+
result = round.flop_equities
|
|
52
|
+
# => {
|
|
53
|
+
# "9d9c" => { win_rate: 0.87, lose_rate: 0.12, tie_rate: 0.0, outs: [] },
|
|
54
|
+
# "KdKc" => { win_rate: 0.12, lose_rate: 0.87, tie_rate: 0.0,
|
|
55
|
+
# outs: [["Kh", "2c"], ["Ks", "7d"], ...] }
|
|
56
|
+
# }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`outs` は `[turn, river]` のペア配列です。
|
|
60
|
+
|
|
61
|
+
### preflop_equities — プリフロップ(ボード5枚の全組み合わせを探索)
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
round = PokerOdds::Hand.new
|
|
65
|
+
round.player = "9d 9c, Kd Kc"
|
|
66
|
+
|
|
67
|
+
result = round.preflop_equities
|
|
68
|
+
# => {
|
|
69
|
+
# "KdKc" => { win_rate: 0.77, lose_rate: 0.22, tie_rate: 0.0, outs: [] },
|
|
70
|
+
# "9d9c" => { win_rate: 0.22, lose_rate: 0.77, tie_rate: 0.0,
|
|
71
|
+
# outs: [["9h", "9s", "2c", "3d", "7h"], ...] }
|
|
72
|
+
# }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`outs` は `[flop1, flop2, flop3, turn, river]` の5枚ボード配列です。
|
|
76
|
+
|
|
77
|
+
### 3人以上のプレイヤー
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
round = PokerOdds::Hand.new
|
|
81
|
+
round.player = "9d 9c, Kd Kc, 2h 2s"
|
|
82
|
+
|
|
83
|
+
result = round.preflop_equities
|
|
84
|
+
result.each do |hand, stats|
|
|
85
|
+
puts "#{hand}: win=#{stats[:win_rate].round(3)}"
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### expose(公開済みカードの指定)
|
|
90
|
+
|
|
91
|
+
デッキから除外したいカード(バーンカードなど)を指定できます:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
round = PokerOdds::Hand.new
|
|
95
|
+
round.flop = "Ah 9h Jd"
|
|
96
|
+
round.turn = "3d"
|
|
97
|
+
round.expose = "2c 7s" # デッキに存在しないカードとして扱う
|
|
98
|
+
round.player = "9d 9c, Kd Kc"
|
|
99
|
+
result = round.equities
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 開発
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
# 依存パッケージのインストール(Rust も必要)
|
|
106
|
+
bin/setup
|
|
107
|
+
|
|
108
|
+
# テスト実行
|
|
109
|
+
bundle exec rspec
|
|
110
|
+
|
|
111
|
+
# ネイティブ拡張のコンパイル
|
|
112
|
+
bundle exec rake compile
|
|
113
|
+
|
|
114
|
+
# 全タスク(compile + spec + rubocop)
|
|
115
|
+
bundle exec rake
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## ライセンス
|
|
119
|
+
|
|
120
|
+
このgemは [MIT License](https://opensource.org/licenses/MIT) のもとで公開されています。
|
|
121
|
+
|
|
122
|
+
### サードパーティライセンス
|
|
123
|
+
|
|
124
|
+
このgemは以下のOSSを内部で使用しています:
|
|
125
|
+
|
|
126
|
+
| ライブラリ | 作者 | ライセンス | 用途 |
|
|
127
|
+
|---|---|---|---|
|
|
128
|
+
| [holdem-hand-evaluator](https://github.com/b-inary/holdem-hand-evaluator) | Wataru Inariba (b-inary) | MIT | Rust製ポーカーハンド評価エンジン |
|
|
129
|
+
|
|
130
|
+
holdem-hand-evaluator の著作権表示:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
MIT License
|
|
134
|
+
|
|
135
|
+
Copyright (c) 2020 Wataru Inariba
|
|
136
|
+
|
|
137
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
138
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
139
|
+
in the Software without restriction, including without limitation the rights
|
|
140
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
141
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
142
|
+
furnished to do so, subject to the following conditions:
|
|
143
|
+
|
|
144
|
+
The above copyright notice and this permission notice shall be included in all
|
|
145
|
+
copies or substantial portions of the Software.
|
|
146
|
+
|
|
147
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
148
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
149
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
150
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
151
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
152
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
153
|
+
SOFTWARE.
|
|
154
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
require "rb_sys/extensiontask"
|
|
6
|
+
require "rubocop/rake_task"
|
|
7
|
+
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
9
|
+
|
|
10
|
+
GEMSPEC = Gem::Specification.load("poker_odds.gemspec")
|
|
11
|
+
|
|
12
|
+
RbSys::ExtensionTask.new("poker_odds", GEMSPEC) do |ext|
|
|
13
|
+
ext.lib_dir = "lib/poker_odds"
|
|
14
|
+
ext.cross_compile = true
|
|
15
|
+
ext.cross_platform = %w[
|
|
16
|
+
x86_64-linux
|
|
17
|
+
aarch64-linux
|
|
18
|
+
x86_64-darwin
|
|
19
|
+
arm64-darwin
|
|
20
|
+
]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
RuboCop::RakeTask.new
|
|
24
|
+
|
|
25
|
+
task default: %i[compile spec rubocop]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PokerOdds
|
|
4
|
+
# Represents a poker round and calculates equity for each player.
|
|
5
|
+
class Hand
|
|
6
|
+
def initialize(**opts)
|
|
7
|
+
@player_hands = []
|
|
8
|
+
@flop_cards = ""
|
|
9
|
+
@turn_card = nil
|
|
10
|
+
@river_card = nil
|
|
11
|
+
@expose_cards = ""
|
|
12
|
+
opts.each { |k, v| send(:"#{k}=", v) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Getters — return normalized (spaceless) internal representation
|
|
16
|
+
def player = @player_hands
|
|
17
|
+
def flop = @flop_cards
|
|
18
|
+
def turn = @turn_card
|
|
19
|
+
def river = @river_card
|
|
20
|
+
def expose = @expose_cards
|
|
21
|
+
|
|
22
|
+
# "9d 9c, Kd Kc" -> ["9d9c", "KdKc"]
|
|
23
|
+
def player=(str)
|
|
24
|
+
@player_hands = str.split(",").map { |s| s.strip.delete(" ") }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# "Ah 9h Jd" -> "Ah9hJd"
|
|
28
|
+
def flop=(str)
|
|
29
|
+
@flop_cards = str.delete(" ")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# "3d" -> "3d"
|
|
33
|
+
def turn=(str)
|
|
34
|
+
@turn_card = str.strip
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# "Xx" -> "Xx"
|
|
38
|
+
def river=(str)
|
|
39
|
+
@river_card = str.strip
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# "Ah Kd" -> "AhKd"
|
|
43
|
+
def expose=(str)
|
|
44
|
+
@expose_cards = str.delete(" ")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Flop + turn known (4 cards). Exhaustively iterates all possible river cards.
|
|
48
|
+
# Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: ["Kh", ...] }, ... }
|
|
49
|
+
def equities
|
|
50
|
+
board = [@flop_cards, @turn_card].join
|
|
51
|
+
PokerOdds::Evaluator.equities(@player_hands, board, @expose_cards)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Flop known (3 cards). Exhaustively iterates all C(deck, 2) turn+river combinations.
|
|
55
|
+
# Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: [["Tc","Qd"], ...] }, ... }
|
|
56
|
+
def flop_equities
|
|
57
|
+
PokerOdds::Evaluator.flop_equities(@player_hands, @flop_cards, @expose_cards)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# No community cards. Exhaustively iterates all C(deck, 5) boards.
|
|
61
|
+
# Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: [["Ah",...], ...] }, ... }
|
|
62
|
+
def preflop_equities
|
|
63
|
+
PokerOdds::Evaluator.preflop_equities(@player_hands, @expose_cards)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/poker_odds.rb
ADDED
data/mise.toml
ADDED
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: poker_odds
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: aarch64-linux
|
|
6
|
+
authors:
|
|
7
|
+
- kyohah
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-02-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Calculates win/lose/tie equity and outs for Texas Hold'em using exhaustive
|
|
14
|
+
enumeration. Powered by holdem-hand-evaluator via a Magnus/rb-sys Rust extension
|
|
15
|
+
(~1.2B evaluations/sec).
|
|
16
|
+
email:
|
|
17
|
+
- kyohah@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- ".github/workflows/main.yml"
|
|
23
|
+
- ".github/workflows/release.yml"
|
|
24
|
+
- ".travis.yml"
|
|
25
|
+
- CLAUDE.md
|
|
26
|
+
- CODE_OF_CONDUCT.md
|
|
27
|
+
- LICENSE.txt
|
|
28
|
+
- README.md
|
|
29
|
+
- Rakefile
|
|
30
|
+
- lib/poker_odds.rb
|
|
31
|
+
- lib/poker_odds/3.2/poker_odds.so
|
|
32
|
+
- lib/poker_odds/3.3/poker_odds.so
|
|
33
|
+
- lib/poker_odds/3.4/poker_odds.so
|
|
34
|
+
- lib/poker_odds/hand.rb
|
|
35
|
+
- lib/poker_odds/version.rb
|
|
36
|
+
- mise.toml
|
|
37
|
+
homepage: https://github.com/kyohah/poker_odds
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata:
|
|
41
|
+
homepage_uri: https://github.com/kyohah/poker_odds
|
|
42
|
+
source_code_uri: https://github.com/kyohah/poker_odds
|
|
43
|
+
changelog_uri: https://github.com/kyohah/poker_odds/blob/main/CHANGELOG.md
|
|
44
|
+
rubygems_mfa_required: 'true'
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.2'
|
|
54
|
+
- - "<"
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 3.5.dev
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
requirements: []
|
|
63
|
+
rubygems_version: 3.5.23
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: Fast poker hand equity calculator backed by a Rust native extension.
|
|
67
|
+
test_files: []
|