Class: RubyHoldem::Round::MoveHistoryComputations
- Inherits:
-
Object
- Object
- RubyHoldem::Round::MoveHistoryComputations
- Defined in:
- lib/ruby_holdem/round/move_history_computations.rb
Instance Attribute Summary collapse
-
#move_history ⇒ Object
readonly
Returns the value of attribute move_history.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
- #every_player_has_checked? ⇒ Boolean
- #has_winner? ⇒ Boolean
- #highest_bet_placed ⇒ Object
-
#initialize(players, move_history) ⇒ MoveHistoryComputations
constructor
A new instance of MoveHistoryComputations.
-
#player_in_turn ⇒ Object
The player whose turn it is to make a move.
- #players_still_in_round ⇒ Object
- #ready_for_next_stage? ⇒ Boolean
- #turns_played_in_stage ⇒ Object
-
#winner ⇒ Object
TODO: Compare the hands of the two players.
Constructor Details
#initialize(players, move_history) ⇒ MoveHistoryComputations
Returns a new instance of MoveHistoryComputations.
6 7 8 9 |
# File 'lib/ruby_holdem/round/move_history_computations.rb', line 6 def initialize(players, move_history) @players = players @move_history = move_history end |
Instance Attribute Details
#move_history ⇒ Object (readonly)
Returns the value of attribute move_history.
4 5 6 |
# File 'lib/ruby_holdem/round/move_history_computations.rb', line 4 def move_history @move_history end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
4 5 6 |
# File 'lib/ruby_holdem/round/move_history_computations.rb', line 4 def players @players end |
Instance Method Details
#every_player_has_checked? ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 |
# 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? ⇒ Boolean
21 22 23 |
# 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 ⇒ Object
11 12 13 14 15 |
# 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 ⇒ Object
The player whose turn it is to make a move
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 ⇒ Object
68 69 70 71 72 73 74 75 76 |
# 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? ⇒ Boolean
17 18 19 |
# 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 ⇒ Object
30 31 32 |
# 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 ⇒ Object
TODO: Compare the hands of the two players
26 27 28 |
# 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 |