Class: AcpcPokerTypes::HandPlayerGroup
- Inherits:
-
Array
- Object
- Array
- AcpcPokerTypes::HandPlayerGroup
- Defined in:
- lib/acpc_poker_types/hand_player_group.rb
Instance Attribute Summary collapse
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
- #action_cost(acting_player_position, action, min_wager) ⇒ Object
- #amount_to_call(acting_player_position) ⇒ Object
-
#initialize(all_hands, stacks, blinds) ⇒ HandPlayerGroup
constructor
A new instance of HandPlayerGroup.
-
#legal_actions(acting_player_position, round, game_def, min_wager_by) ⇒ Array<PokerAction>
The legal actions for the next player to act.
- #next_player_position(acting_player_position = -1)) ⇒ Object
- #next_to_act(acting_player_position = -1)) ⇒ Object
-
#num_wagers(round) ⇒ Integer
The number of wagers this round.
- #position_of_first_active_player(acting_player_position = 0) ⇒ Object
Constructor Details
#initialize(all_hands, stacks, blinds) ⇒ HandPlayerGroup
Returns a new instance of HandPlayerGroup.
12 13 14 15 16 17 18 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 12 def initialize(all_hands, stacks, blinds) @players = all_hands.length.times.map do |i| HandPlayer.new all_hands[i], stacks[i], blinds[i] end super @players end |
Instance Attribute Details
#players ⇒ Object (readonly)
Returns the value of attribute players.
10 11 12 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 10 def players @players end |
Instance Method Details
#action_cost(acting_player_position, action, min_wager) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 34 def action_cost(acting_player_position, action, min_wager) case action.to_s[0] when PokerAction::CALL amount_to_call acting_player_position when PokerAction::RAISE if action.modifier action.modifier.to_i - players[acting_player_position].total_contribution else min_wager + amount_to_call(acting_player_position) end else 0 end end |
#amount_to_call(acting_player_position) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 49 def amount_to_call(acting_player_position) ChipStack.new( [ ( map do |player| player.total_contribution end ).max - players[acting_player_position].total_contribution, @players[acting_player_position].stack ].min ) end |
#legal_actions(acting_player_position, round, game_def, min_wager_by) ⇒ Array<PokerAction>
Returns The legal actions for the next player to act.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 80 def legal_actions(acting_player_position, round, game_def, min_wager_by) @players[acting_player_position].legal_actions( in_round: round, amount_to_call: amount_to_call(acting_player_position), wager_illegal: ( game_def.max_number_of_wagers[round] && num_wagers(round) >= game_def.max_number_of_wagers[round] ), betting_type: game_def.betting_type, min_wager_by: min_wager_by ) end |
#next_player_position(acting_player_position = -1)) ⇒ Object
20 21 22 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 20 def next_player_position(acting_player_position=-1) (acting_player_position + 1) % length end |
#next_to_act(acting_player_position = -1)) ⇒ Object
62 63 64 65 66 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 62 def next_to_act(acting_player_position=-1) position_of_first_active_player( next_player_position(acting_player_position) ) end |
#num_wagers(round) ⇒ Integer
Returns The number of wagers this round.
69 70 71 72 73 74 75 76 77 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 69 def num_wagers(round) inject(0) do |sum, pl| next sum if round >= pl.actions.length sum += pl.actions[round].count do |ac| PokerAction::MODIFIABLE_ACTIONS.include?(ac.action) end end end |
#position_of_first_active_player(acting_player_position = 0) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/acpc_poker_types/hand_player_group.rb', line 24 def position_of_first_active_player(acting_player_position=0) return nil if all? { |player| player.inactive? } # This must eventually exit because of the above assertion while @players[acting_player_position].inactive? acting_player_position = next_player_position(acting_player_position) end acting_player_position end |