Class: PokerOdds::Hand
- Inherits:
-
Object
- Object
- PokerOdds::Hand
- Defined in:
- lib/poker_odds/hand.rb
Overview
Represents a poker round and calculates equity for each player.
Instance Method Summary collapse
-
#equities ⇒ Object
Flop + turn known (4 cards).
- #expose ⇒ Object
-
#expose=(str) ⇒ Object
"Ah Kd" -> "AhKd".
- #flop ⇒ Object
-
#flop=(str) ⇒ Object
"Ah 9h Jd" -> "Ah9hJd".
-
#flop_equities ⇒ Object
Flop known (3 cards).
-
#initialize(**opts) ⇒ Hand
constructor
A new instance of Hand.
-
#player ⇒ Object
Getters — return normalized (spaceless) internal representation.
-
#player=(str) ⇒ Object
"9d 9c, Kd Kc" -> ["9d9c", "KdKc"].
-
#preflop_equities ⇒ Object
No community cards.
- #river ⇒ Object
-
#river=(str) ⇒ Object
"Xx" -> "Xx".
- #turn ⇒ Object
-
#turn=(str) ⇒ Object
"3d" -> "3d".
Constructor Details
#initialize(**opts) ⇒ Hand
Returns a new instance of Hand.
6 7 8 9 10 11 12 13 |
# File 'lib/poker_odds/hand.rb', line 6 def initialize(**opts) @player_hands = [] @flop_cards = "" @turn_card = nil @river_card = nil @expose_cards = "" opts.each { |k, v| send(:"#{k}=", v) } end |
Instance Method Details
#equities ⇒ Object
Flop + turn known (4 cards). Exhaustively iterates all possible river cards. Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: ["Kh", ...] }, ... }
49 50 51 52 |
# File 'lib/poker_odds/hand.rb', line 49 def equities board = [@flop_cards, @turn_card].join PokerOdds::Evaluator.equities(@player_hands, board, @expose_cards) end |
#expose ⇒ Object
20 |
# File 'lib/poker_odds/hand.rb', line 20 def expose = @expose_cards |
#expose=(str) ⇒ Object
"Ah Kd" -> "AhKd"
43 44 45 |
# File 'lib/poker_odds/hand.rb', line 43 def expose=(str) @expose_cards = str.delete(" ") end |
#flop ⇒ Object
17 |
# File 'lib/poker_odds/hand.rb', line 17 def flop = @flop_cards |
#flop=(str) ⇒ Object
"Ah 9h Jd" -> "Ah9hJd"
28 29 30 |
# File 'lib/poker_odds/hand.rb', line 28 def flop=(str) @flop_cards = str.delete(" ") end |
#flop_equities ⇒ Object
Flop known (3 cards). Exhaustively iterates all C(deck, 2) turn+river combinations. Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: [["Tc","Qd"], ...] }, ... }
56 57 58 |
# File 'lib/poker_odds/hand.rb', line 56 def flop_equities PokerOdds::Evaluator.flop_equities(@player_hands, @flop_cards, @expose_cards) end |
#player ⇒ Object
Getters — return normalized (spaceless) internal representation
16 |
# File 'lib/poker_odds/hand.rb', line 16 def player = @player_hands |
#player=(str) ⇒ Object
"9d 9c, Kd Kc" -> ["9d9c", "KdKc"]
23 24 25 |
# File 'lib/poker_odds/hand.rb', line 23 def player=(str) @player_hands = str.split(",").map { |s| s.strip.delete(" ") } end |
#preflop_equities ⇒ Object
No community cards. Exhaustively iterates all C(deck, 5) boards. Returns: { "9d9c" => { win_rate:, lose_rate:, tie_rate:, outs: [["Ah",...], ...] }, ... }
62 63 64 |
# File 'lib/poker_odds/hand.rb', line 62 def preflop_equities PokerOdds::Evaluator.preflop_equities(@player_hands, @expose_cards) end |
#river ⇒ Object
19 |
# File 'lib/poker_odds/hand.rb', line 19 def river = @river_card |
#river=(str) ⇒ Object
"Xx" -> "Xx"
38 39 40 |
# File 'lib/poker_odds/hand.rb', line 38 def river=(str) @river_card = str.strip end |
#turn ⇒ Object
18 |
# File 'lib/poker_odds/hand.rb', line 18 def turn = @turn_card |
#turn=(str) ⇒ Object
"3d" -> "3d"
33 34 35 |
# File 'lib/poker_odds/hand.rb', line 33 def turn=(str) @turn_card = str.strip end |