Module: PokerEngine::HandEvaluator
- Defined in:
- lib/poker_engine/hand_evaluator.rb
Class Method Summary collapse
Class Method Details
.find_top_hands(players, board) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/poker_engine/hand_evaluator.rb', line 7 def find_top_hands(players, board) players .map do |id:, cards:, **| cards = board + cards player_top_hand = cards.combination(5) .map do |five_cards| HandIndex.new(Cards.new(five_cards)) end .max [id, player_top_hand] end .to_h end |
.find_winners(players, board) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/poker_engine/hand_evaluator.rb', line 22 def find_winners(players, board) top_hand_per_player_id = find_top_hands(players, board) best_hand = top_hand_per_player_id.values.max top_hand_per_player_id .map { |player_id, hand| hand == best_hand ? player_id : nil } .compact end |