poker_odds 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b574857f4d6fad3bc14ee60f4d4b2bc41efdc38b61709615a55542bfb3423d62
4
+ data.tar.gz: 7ec770adceb40755ef8246f5964c2f308bb1df7572067a71949d0feca0190480
5
+ SHA512:
6
+ metadata.gz: 4fa5bd0bee8b6baf898b8988baba6de6a053939d9c49a98f49956f1dfc9f79558825aad78ff22bc5a997847414324ac9ee36258d1f173b4e2b65f7fb1eb652b3
7
+ data.tar.gz: 9e747a262df44ccc21e930a92ac58b115977bd2ca07cbca61db22711befda0bba24f5e0658d042ad758378b4d59ed4b1c017f0043814ecb7176895058ca0d07b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.8
7
+ before_install: gem install bundler -v 1.17.2
@@ -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/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in poker_odds.gemspec
6
+ gemspec
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,61 @@
1
+ # PokerOdds
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/poker_odds`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'poker_odds'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install poker_odds
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ round = PokerOdds::Round.new(flop: 'Ah 9h Jd', turn: '3d')
27
+ round.add_hand("9d 9c")
28
+ round.add_hand("Kd Kc")
29
+
30
+ round.equities
31
+ # =>
32
+ [{:hand=>[{:rank=>"K", :suit=>:d}, {:rank=>"K", :suit=>:c}],
33
+ :win_rate=>0.045454545454545456,
34
+ :lose_rate=>0.9545454545454546,
35
+ :tie_rate=>0.0,
36
+ :outs=>[{:suit=>:s, :rank=>"K"}, {:suit=>:h, :rank=>"K"}]},
37
+ {:hand=>[{:rank=>"9", :suit=>:d}, {:rank=>"9", :suit=>:c}],
38
+ :win_rate=>0.9545454545454546,
39
+ :lose_rate=>0.045454545454545456,
40
+ :tie_rate=>0.0,
41
+ :outs=>[]}]
42
+
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/poker_odds. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58
+
59
+ ## Code of Conduct
60
+
61
+ Everyone interacting in the PokerOdds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/poker_odds/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "poker_odds"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ module PokerOdds
2
+ class Card < Hash
3
+ include Hashie::Extensions::Coercion
4
+ include Hashie::Extensions::MergeInitializer
5
+ include Hashie::Extensions::MethodAccess
6
+
7
+ RANKS = %w[A 2 3 4 5 6 7 8 9 T J Q K].freeze
8
+ SUITS = %i[s h d c].freeze
9
+
10
+ RANK_VALUE = {
11
+ '2' => 2,
12
+ '3' => 3,
13
+ '4' => 4,
14
+ '5' => 5,
15
+ '6' => 6,
16
+ '7' => 7,
17
+ '8' => 8,
18
+ '9' => 9,
19
+ 'T' => 10,
20
+ 'J' => 11,
21
+ 'Q' => 12,
22
+ 'K' => 13,
23
+ 'A' => 14
24
+ }
25
+
26
+ coerce_key :rank, String
27
+ coerce_key :suit, Symbol
28
+
29
+ class << self
30
+ def string_parse(string)
31
+ Card.new(rank: string[0], suit: string[1])
32
+ end
33
+ end
34
+
35
+ def rank_value
36
+ RANK_VALUE[rank]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,232 @@
1
+ module PokerOdds
2
+ class Cards < Array
3
+ include Comparable
4
+ DeleteError = Class.new(StandardError)
5
+
6
+ STRAIGHT_PATTERNS = (6..14).to_a.reverse.map { |i| (0..4).map {|j| i - j } }.push([5,4,3,2,14]).map { |a| /#{a[0]}.+#{a[1]}.+#{a[2]}.+#{a[3]}.+#{a[4]}/ }.freeze
7
+
8
+ class << self
9
+ def new_deck
10
+ new(Card::RANKS.flat_map do |rank|
11
+ Card::SUITS.map do |suit|
12
+ Card.new(suit: suit, rank: rank)
13
+ end
14
+ end)
15
+ end
16
+
17
+ def string_parse(string)
18
+ a = string.split.map do |s|
19
+ Card.new(rank: s[0], suit: s[1])
20
+ end
21
+
22
+ new(a)
23
+ end
24
+
25
+ def json_parse(json)
26
+ h = JSON.parse(json)
27
+
28
+ b = h.map { |a| Card.new(rank: a['rank'].to_sym, suit: a['suit'].to_sym) }
29
+
30
+ Hands.new(b)
31
+ end
32
+ end
33
+
34
+ def delete_card!(card)
35
+ i = index(card)
36
+ raise DeleteError if i.nil?
37
+
38
+ delete_at(i)
39
+ self
40
+ end
41
+
42
+ def delete_card(card)
43
+ i = index(card)
44
+ raise DeleteError if i.nil?
45
+
46
+ clone_cards = clone
47
+ clone_cards.delete_at(i)
48
+
49
+ clone_cards
50
+ end
51
+
52
+ def delete_cards!(cards)
53
+ cards.each { |t| delete_card!(t) }
54
+ self
55
+ end
56
+
57
+ def delete_cards(cards)
58
+ clone_cards = clone
59
+ cards.each { |t| clone_cards.delete_card!(t) }
60
+ clone_cards
61
+ end
62
+
63
+ def add_card(card)
64
+ clone_cards = clone
65
+ clone_cards.push(card)
66
+ end
67
+
68
+ def add_card!(card)
69
+ push(card)
70
+ end
71
+
72
+ def add_cards(cards)
73
+ clone_cards = clone
74
+
75
+ cards.each { |card| clone_cards.add_card!(card) }
76
+ clone_cards
77
+ end
78
+
79
+ def add_cards!(cards)
80
+ cards.each { |card| add_card!(card) }
81
+ self
82
+ end
83
+
84
+ def sort_by_suit
85
+ @sort_by_suit ||= self.class.new(sort_by { |card| [card.suit, card.rank_value] }.reverse)
86
+ end
87
+
88
+ def sort_by_rank
89
+ @sort_by_rank ||= self.class.new(sort_by { |card| [card.rank_value, card.suit] }.reverse)
90
+ rescue => e
91
+ binding.pry
92
+ end
93
+
94
+ def to_s
95
+ map { |c| "#{c.rank}#{c.suit}" }.join(' ')
96
+ end
97
+
98
+ def to_s_rank_value
99
+ map(&:rank_value).join(' ')
100
+ end
101
+
102
+ def group_by_suit
103
+ @group_by_suit ||= group_by(&:suit).each_with_object({}) { |(k, v), h| h[k] = self.class.new(v).sort_by_rank }
104
+ end
105
+
106
+ def royal_flush_rate
107
+ [10, 0,0,0,0,0] if /A(.) K\1 Q\1 J\1 T\1/.match?(sort_by_suit.to_s)
108
+ end
109
+
110
+ def straight_flush_rate
111
+ group_by_suit.each do |k, v|
112
+ next if v.size < 5
113
+
114
+ a = v.straight_rate
115
+ if a
116
+ return [9, a[1], a[2], a[3], a[4], a[5]]
117
+ end
118
+ end
119
+ nil
120
+ end
121
+
122
+ def four_of_a_kind_rate
123
+ a = sort_by_rank.to_s.match(/(.). \1. \1. \1./)
124
+
125
+ if a
126
+ b = (a.pre_match + a.post_match).match(/(\S)/).to_s
127
+
128
+ [8, PokerOdds::Card::RANK_VALUE[a[1]], PokerOdds::Card::RANK_VALUE[b.to_s], 0, 0,0]
129
+ end
130
+ end
131
+
132
+ def full_house_rate
133
+ case sort_by_rank.to_s
134
+ when /(.). \1. \1. (.*)(.). \3./
135
+ [7, PokerOdds::Card::RANK_VALUE[$1], PokerOdds::Card::RANK_VALUE[$3], 0, 0,0]
136
+ when /((.). \2.) (.*)((.). \5. \5.)/
137
+ [7, PokerOdds::Card::RANK_VALUE[$5], PokerOdds::Card::RANK_VALUE[$2], 0, 0,0]
138
+ else
139
+ nil
140
+ end
141
+ end
142
+
143
+ def flush_rate
144
+ group_by_suit.each do |k, v|
145
+ next if v.size < 5
146
+
147
+ return [6, v[0].rank_value, v[1].rank_value, v[2].rank_value, v[3].rank_value, v[4].rank_value]
148
+ end
149
+
150
+ nil
151
+ end
152
+
153
+ def straight_rate
154
+ a = sort_by_rank.to_s.match(/(?<_A>A.+K.+Q.+J.+T)|(?<_K>K.+Q.+J.+T.+9)|(?<_Q>Q.+J.+T.+9.+8)|(?<_J>J.+T.+9.+8.+7)|(?<_T>T.+9.+8.+7.+6)|(?<_9>9.+8.+7.+6.+5)|(?<_8>8.+7.+6.+5.+4)|(?<_7>7.+6.+5.+4.+3)|(?<_6>6.+5.+4.+3.+2)|(?<_5>A.+5.+4.+3.+2)/)
155
+ if a
156
+ case k
157
+ when :_A
158
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('A', 'K', 'Q','J', 'T')]
159
+ when :_K
160
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('K', 'Q', 'J','T', '9')]
161
+ when :_Q
162
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('Q', 'J', 'T','9', '8')]
163
+ when :_J
164
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('J', 'T', '9','8', '7')]
165
+ when :_T
166
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('T', '9', '8','7', '6')]
167
+ when :_9
168
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('9', '8', '7','6', '5')]
169
+ when :_8
170
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('8', '7', '6','5', '4')]
171
+ when :_7
172
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('7', '6', '5','4', '3')]
173
+ when :_6
174
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('6', '5', '4','3', '2')]
175
+ when :_5
176
+ [5, *PokerOdds::Card::RANK_VALUE.values_at('5', '4', '3','2', 'A')]
177
+ end
178
+ else
179
+ nil
180
+ end
181
+ end
182
+
183
+ def three_of_a_kind_rate
184
+ md = sort_by_rank.to_s.match(/(.). \1. \1./)
185
+
186
+ if md
187
+ arranged_hand = (md.pre_match + md.post_match).strip.squeeze(" ")
188
+
189
+ [4, PokerOdds::Card::RANK_VALUE[md[1]], PokerOdds::Card::RANK_VALUE[arranged_hand[0]], PokerOdds::Card::RANK_VALUE[arranged_hand[3]], 0, 0]
190
+ else
191
+ nil
192
+ end
193
+ end
194
+
195
+ def two_pair_rate
196
+ md = sort_by_rank.to_s.match(/(.). \1.(.*?) (.). \3./)
197
+
198
+ if md
199
+ arranged_hand = (md.pre_match + ' ' + md[2] + ' ' + md.post_match).strip.squeeze(" ")
200
+ [3, PokerOdds::Card::RANK_VALUE[md[1]], PokerOdds::Card::RANK_VALUE[md[3]], PokerOdds::Card::RANK_VALUE[arranged_hand[0]], 0, 0]
201
+ else
202
+ nil
203
+ end
204
+ end
205
+
206
+ def one_pair_rate
207
+ md = sort_by_rank.to_s.match(/(.). \1./)
208
+
209
+ if md
210
+ arranged_hand = (md.pre_match + ' ' + md.post_match).strip.squeeze(" ")
211
+
212
+ [2, PokerOdds::Card::RANK_VALUE[md[1]], PokerOdds::Card::RANK_VALUE[arranged_hand[0]], PokerOdds::Card::RANK_VALUE[arranged_hand[3]], PokerOdds::Card::RANK_VALUE[arranged_hand[6]], 0]
213
+ else
214
+ nil
215
+ end
216
+ end
217
+
218
+ def high_card_rate
219
+ arranged_hand = sort_by_rank.to_s
220
+
221
+ [1, PokerOdds::Card::RANK_VALUE[arranged_hand[0]], PokerOdds::Card::RANK_VALUE[arranged_hand[3]], PokerOdds::Card::RANK_VALUE[arranged_hand[6]], PokerOdds::Card::RANK_VALUE[arranged_hand[9]], PokerOdds::Card::RANK_VALUE[arranged_hand[12]]]
222
+ end
223
+
224
+ def score
225
+ @score ||= royal_flush_rate || straight_flush_rate || four_of_a_kind_rate || full_house_rate || flush_rate || straight_flush_rate || three_of_a_kind_rate || two_pair_rate || one_pair_rate || high_card_rate
226
+ end
227
+
228
+ def <=>(other_cards)
229
+ score <=> other_cards.score
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,109 @@
1
+ module PokerOdds
2
+ class Round < Hash
3
+ include Hashie::Extensions::Coercion
4
+ include Hashie::Extensions::MergeInitializer
5
+ include Hashie::Extensions::MethodAccess
6
+
7
+ coerce_key :hands, Array
8
+ coerce_key :flop_cards, PokerOdds::Cards
9
+ coerce_key :turn_card, PokerOdds::Card
10
+ coerce_key :river_card, PokerOdds::Card
11
+
12
+ coerce_key :expose_cards, PokerOdds::Cards
13
+
14
+ # class << self
15
+ # def flop =(h)
16
+
17
+ # end
18
+ # end
19
+
20
+ def initialize(**arg)
21
+ self.flop=arg[:flop] if arg[:flop]
22
+ self.turn=arg[:turn] if arg[:turn]
23
+ self.river=arg[:river] if arg[:river]
24
+
25
+ self[:hands] ||= []
26
+ self[:expose_cards] ||= PokerOdds::Cards.new
27
+ self[:flop_cards] ||= PokerOdds::Cards.new
28
+ self[:turn_card] ||= PokerOdds::Card.new
29
+ self[:river_card] ||= PokerOdds::Card.new
30
+ end
31
+
32
+ def add_hand(s)
33
+ self[:hands] << PokerOdds::Cards.string_parse(s)
34
+ self
35
+ end
36
+
37
+ def flop=(s)
38
+ self[:flop_cards] = PokerOdds::Cards.string_parse(s)
39
+ self
40
+ end
41
+
42
+ def turn=(s)
43
+ self[:turn_card] = PokerOdds::Card.string_parse(s)
44
+ self
45
+ end
46
+
47
+ def river=(s)
48
+ self[:river_cards] = PokerOdds::Card.string_parse(s)
49
+ self
50
+ end
51
+
52
+ def equities
53
+ z = deck.each_with_object({}) do |card, a|
54
+ scores = hands.each_with_object({}) do |hand, h|
55
+ cards = hand
56
+ cards = cards.add_cards(flop_cards)
57
+ cards = cards.add_card(turn_card)
58
+ cards = cards.add_card(card)
59
+
60
+ if h[cards.score].present?
61
+ h[cards.score] << hand
62
+ else
63
+ h[cards.score] = [hand]
64
+ end
65
+ end
66
+
67
+ a[card] = {}
68
+ if scores.keys.size == 1
69
+ a[card][:tie_hands] = hands
70
+ else
71
+ mk = scores.keys.max
72
+ a[card][:win_hands] = scores[mk]
73
+ a[card][:lose_hands] = scores.each_with_object([]) do |(k,v), a|
74
+ next if k == mk
75
+
76
+ a.concat(v)
77
+ end
78
+ end
79
+ end
80
+
81
+ s = z.size.to_f
82
+
83
+ hands.each_with_object([]) do |hand, a|
84
+ win_hands = z.select { |a,b| b[:win_hands]&.include?(hand) }
85
+ win_rate = win_hands.size / s
86
+ a << {
87
+ hand: hand,
88
+ win_rate: win_rate,
89
+ lose_rate: z.count { |a,b| b[:lose_hands]&.include?(hand) } / s,
90
+ tie_rate: z.count { |a,b| b[:tie_hands]&.include?(hand) } / s,
91
+ outs: win_rate > 0.5 ? [] : win_hands.keys
92
+ }
93
+ end
94
+ end
95
+
96
+ def deck
97
+ cards = Cards.new_deck
98
+ cards.delete_cards!(expose_cards) if expose_cards
99
+ hands.each do |hand|
100
+ cards.delete_cards!(hand)
101
+ end
102
+ cards.delete_cards!(flop_cards) if flop_cards.present?
103
+ cards.delete_card!(turn_card) if turn_card.present?
104
+ cards.delete_card!(river_card) if river_card.present?
105
+
106
+ cards
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ module PokerOdds
2
+ VERSION = "0.1.0"
3
+ end
data/lib/poker_odds.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'hashie'
2
+ require 'active_support/all'
3
+ require_relative "poker_odds/version"
4
+ require_relative 'poker_odds/card'
5
+ require_relative 'poker_odds/cards'
6
+ require_relative 'poker_odds/round'
7
+
8
+ module PokerOdds
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "poker_odds/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "poker_odds"
8
+ spec.version = PokerOdds::VERSION
9
+ spec.authors = ["kyohah"]
10
+ spec.email = ["kyohah@gmail.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/kyohah/poker_odds"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler"
40
+ spec.add_development_dependency "rake"
41
+ spec.add_development_dependency "rspec"
42
+ spec.add_development_dependency "pry"
43
+ spec.add_dependency "hashie"
44
+ spec.add_dependency 'activesupport'
45
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poker_odds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kyohah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Write a longer description or delete this line.
98
+ email:
99
+ - kyohah@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/poker_odds.rb
115
+ - lib/poker_odds/card.rb
116
+ - lib/poker_odds/cards.rb
117
+ - lib/poker_odds/round.rb
118
+ - lib/poker_odds/version.rb
119
+ - poker_odds.gemspec
120
+ homepage: https://github.com/kyohah/poker_odds
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ homepage_uri: https://github.com/kyohah/poker_odds
125
+ source_code_uri: https://github.com/kyohah/poker_odds
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.3.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Write a short summary, because RubyGems requires one.
145
+ test_files: []