class RubyHoldem::Round::MoveHistoryComputations
Attributes
move_history[R]
players[R]
Public Class Methods
new(players, move_history)
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 6 def initialize(players, move_history) @players = players @move_history = move_history end
Public Instance Methods
every_player_has_checked?()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 55 def every_player_has_checked? players_num_checks = players_still_in_round.map do |round_player| checks = moves.select do |move| move[:stage] == stage && move[:move_type] == 'check' && move[:player] == round_player end checks.length end players_num_checks.map { |num_checks| num_checks >= 1 }.all? end
has_winner?()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 21 def has_winner? (stage == 'show_down' || players_still_in_round.count == 1) end
highest_bet_placed()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 11 def highest_bet_placed get_current_bet_amount_for_player( players_still_in_round.max_by(&:current_bet_amount) ) end
player_in_turn()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 34 def player_in_turn #The player whose turn it is to make a move return players[0] if moves.length == 0 last_player = moves.last[:player] i = (players.index(last_player) + 1) % players.length player_found = false until player_found at_end_of_array = (i == (players.length - 1)) if player_is_folded?(players[i]) && !at_end_of_array i += 1 elsif player_is_folded?(players[i]) && at_end_of_array i = 0 else player_found = true end end players[i] end
players_still_in_round()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 68 def players_still_in_round players.select do |round_player| folds = moves.select do |move| move[:move_type] == 'fold' && move[:player] == round_player end folds.length == 0 end end
ready_for_next_stage?()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 17 def ready_for_next_stage? every_player_has_checked? && turns_played_in_stage > 0 end
turns_played_in_stage()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 30 def turns_played_in_stage moves.select { |move| move[:stage] == stage }.length end
winner()
click to toggle source
TODO: Compare the hands of the two players
# File lib/ruby_holdem/round/move_history_computations.rb, line 26 def winner return players_still_in_round[0] if players_still_in_round.count == 1 end
Private Instance Methods
get_current_bet_amount_for_player(player)
click to toggle source
Dependencies on Player
class
# File lib/ruby_holdem/round/move_history_computations.rb, line 100 def get_current_bet_amount_for_player(player) player.current_bet_amount end
moves()
click to toggle source
Dependencies on MoveHistory
class
# File lib/ruby_holdem/round/move_history_computations.rb, line 89 def moves move_history.moves end
player_is_folded?(player)
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 80 def player_is_folded?(player) moves.select do |move| move[:move_type] == 'fold' && move[:player] == player end.any? end
stage()
click to toggle source
# File lib/ruby_holdem/round/move_history_computations.rb, line 93 def stage move_history.stage end