Class: BettingRound
- Inherits:
-
Object
- Object
- BettingRound
- Defined in:
- lib/betting_round.rb
Instance Attribute Summary collapse
-
#max_wait_time_for_bet(seconds) ⇒ Object
Returns the value of attribute max_wait_time_for_bet.
Instance Method Summary collapse
- #amount_bet ⇒ Object
- #bets ⇒ Object
- #current_player ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(hand) ⇒ BettingRound
constructor
A new instance of BettingRound.
- #minimum_bet ⇒ Object
- #minimum_raise ⇒ Object
- #next_player ⇒ Object
- #players ⇒ Object
- #update(args) ⇒ Object
Constructor Details
#initialize(hand) ⇒ BettingRound
Returns a new instance of BettingRound.
6 7 8 9 10 |
# File 'lib/betting_round.rb', line 6 def initialize(hand) @hand = hand @betting_circle = players.enum_for players.each {|player| player.add_observer self } end |
Instance Attribute Details
#max_wait_time_for_bet(seconds) ⇒ Object
Returns the value of attribute max_wait_time_for_bet.
4 5 6 |
# File 'lib/betting_round.rb', line 4 def max_wait_time_for_bet @max_wait_time_for_bet end |
Instance Method Details
#amount_bet ⇒ Object
44 45 46 |
# File 'lib/betting_round.rb', line 44 def amount_bet bets.values.compact.reduce(:+) || 0 end |
#bets ⇒ Object
32 33 34 |
# File 'lib/betting_round.rb', line 32 def bets @bets ||= Hash.new(0) end |
#current_player ⇒ Object
24 25 26 |
# File 'lib/betting_round.rb', line 24 def current_player @current_player || next_player end |
#finished? ⇒ Boolean
48 49 50 |
# File 'lib/betting_round.rb', line 48 def finished? players.size == 1 || everyone_bet_equal_amount? end |
#minimum_bet ⇒ Object
36 37 38 |
# File 'lib/betting_round.rb', line 36 def minimum_bet bets.values.empty? ? @hand.minimum_bet : amount_to_match_pot end |
#minimum_raise ⇒ Object
40 41 42 |
# File 'lib/betting_round.rb', line 40 def minimum_raise minimum_bet + @hand.minimum_bet end |
#next_player ⇒ Object
12 13 14 15 16 |
# File 'lib/betting_round.rb', line 12 def next_player @current_player = @betting_circle.next rescue StopIteration @betting_circle.rewind and retry end |
#players ⇒ Object
28 29 30 |
# File 'lib/betting_round.rb', line 28 def players @players ||= @hand.players end |
#update(args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/betting_round.rb', line 52 def update(args) if args[:fold] fold @current_player else bet, player = args[:bet][:amount], args[:bet][:player] return unless valid? bet, player bets[player] += bet @hand.pot += bet end next_player end |