Class: EquityCalculator
- Inherits:
-
Object
- Object
- EquityCalculator
- Defined in:
- lib/rora/utils/equity_calculator.rb
Instance Method Summary collapse
- #calculate_equity(starting_hands, board = Board.new) ⇒ Object
-
#initialize ⇒ EquityCalculator
constructor
A new instance of EquityCalculator.
Constructor Details
#initialize ⇒ EquityCalculator
Returns a new instance of EquityCalculator.
5 6 7 8 |
# File 'lib/rora/utils/equity_calculator.rb', line 5 def initialize @hand_repository = HandRepository.instance @best_scores = Hash.new end |
Instance Method Details
#calculate_equity(starting_hands, board = Board.new) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rora/utils/equity_calculator.rb', line 10 def calculate_equity(starting_hands, board = Board.new) raise ArgumentError, "Must have at least two starting hands for equity comparison" if (starting_hands.nil? || starting_hands.size < 2) raise ArgumentError, "There are duplicate cards" if duplicates?(starting_hands, board) equity_map = Hash[starting_hands.map{|starting_hand| [starting_hand, 0]}] game = Deck.new.remove(merge(starting_hands, board)).combination(5 - board.cards.size) game.each do |cards| showdown(equity_map, starting_hands, board.cards + cards) end total_winning_hands = equity_map.inject(0) {|total, result| total += result[1]} equity_map.inject(Hash.new) { |hash, result| hash[result[0]] = Equity.new(game.size, total_winning_hands, result); hash} end |