Class: AcpcTableManager::MatchView
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- AcpcTableManager::MatchView
- Includes:
- AcpcPokerTypes
- Defined in:
- lib/acpc_table_manager/match_view.rb
Constant Summary collapse
- DEFAULT_WAIT_FOR_SLICE_TIMEOUT =
seconds
0
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#messages_to_display ⇒ Object
Returns the value of attribute messages_to_display.
-
#slice_index ⇒ Object
readonly
Returns the value of attribute slice_index.
Class Method Summary collapse
Instance Method Summary collapse
-
#all_in ⇒ Object
Over round.
- #amount_for_next_player_to_call ⇒ Object
- #betting_sequence ⇒ Object
- #betting_type_label ⇒ Object
-
#chip_contribution_for_next_player_after_calling ⇒ Object
Over round.
- #hand_ended? ⇒ Boolean
-
#initialize(match_id, slice_index = nil, load_previous_messages: false, timeout: DEFAULT_WAIT_FOR_SLICE_TIMEOUT) ⇒ MatchView
constructor
A new instance of MatchView.
- #legal_actions ⇒ Object
- #load_previous_messages!(index = @slice_index) ⇒ Object
- #loaded_previous_messages? ⇒ Boolean
- #match_ended? ⇒ Boolean
-
#minimum_wager_to ⇒ Object
Over round.
- #opponents ⇒ Object
- #opponents_sorted_by_position_from_user ⇒ Object
-
#players ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’.
-
#pot_after_call ⇒ Object
Over round.
- #pot_at_start_of_round ⇒ Object
-
#pot_fraction_wager_to(fraction = 1) ⇒ Object
Over round.
- #slice ⇒ Object
- #state ⇒ Object
- #user ⇒ Object
- #user_contributions_in_previous_rounds ⇒ Object
-
#users_seat ⇒ Object
zero indexed.
- #users_turn_to_act? ⇒ Boolean
Constructor Details
#initialize(match_id, slice_index = nil, load_previous_messages: false, timeout: DEFAULT_WAIT_FOR_SLICE_TIMEOUT) ⇒ MatchView
Returns a new instance of MatchView.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/acpc_table_manager/match_view.rb', line 32 def initialize(match_id, slice_index = nil, load_previous_messages: false, timeout: DEFAULT_WAIT_FOR_SLICE_TIMEOUT) @match = Match.find(match_id) super @match = [] @slice_index = slice_index || @match.last_slice_viewed raise StandardError.new("Illegal slice index: #{@slice_index}") unless @slice_index >= 0 unless @slice_index < @match.slices.length if timeout > 0 Timeout.timeout(timeout, UnableToFindNextSlice) do while @slice_index >= @match.slices.length do sleep 0.5 @match = Match.find(match_id) end end super @match else raise UnableToFindNextSlice end end = slice. = false if end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
19 20 21 |
# File 'lib/acpc_table_manager/match_view.rb', line 19 def match @match end |
#messages_to_display ⇒ Object
Returns the value of attribute messages_to_display.
19 20 21 |
# File 'lib/acpc_table_manager/match_view.rb', line 19 def end |
#slice_index ⇒ Object (readonly)
Returns the value of attribute slice_index.
19 20 21 |
# File 'lib/acpc_table_manager/match_view.rb', line 19 def slice_index @slice_index end |
Class Method Details
.chip_contributions_in_previous_rounds(player, round) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/acpc_table_manager/match_view.rb', line 22 def self.chip_contributions_in_previous_rounds(player, round) if round > 0 player['chip_contributions'][0..round-1].inject(:+) else 0 end end |
Instance Method Details
#all_in ⇒ Object
Over round
147 148 149 |
# File 'lib/acpc_table_manager/match_view.rb', line 147 def all_in @all_in ||= slice.all_in end |
#amount_for_next_player_to_call ⇒ Object
111 112 113 |
# File 'lib/acpc_table_manager/match_view.rb', line 111 def amount_for_next_player_to_call @amount_for_next_player_to_call ||= slice.amount_to_call end |
#betting_sequence ⇒ Object
70 |
# File 'lib/acpc_table_manager/match_view.rb', line 70 def betting_sequence() slice.betting_sequence end |
#betting_type_label ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/acpc_table_manager/match_view.rb', line 151 def betting_type_label if @betting_type_label.nil? @betting_type_label = if no_limit? 'nolimit' else 'limit' end end @betting_type_label end |
#chip_contribution_for_next_player_after_calling ⇒ Object
Over round
116 117 118 |
# File 'lib/acpc_table_manager/match_view.rb', line 116 def chip_contribution_for_next_player_after_calling @chip_contribution_for_next_player_after_calling ||= slice.chip_contribution_after_calling end |
#hand_ended? ⇒ Boolean
72 |
# File 'lib/acpc_table_manager/match_view.rb', line 72 def hand_ended?() slice.hand_ended? end |
#legal_actions ⇒ Object
75 76 77 78 79 |
# File 'lib/acpc_table_manager/match_view.rb', line 75 def legal_actions slice.legal_actions.map do |action| AcpcPokerTypes::PokerAction.new(action) end end |
#load_previous_messages!(index = @slice_index) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/acpc_table_manager/match_view.rb', line 163 def (index = @slice_index) = slices[0...index].inject([]) do |, s| += s. end + = true self end |
#loaded_previous_messages? ⇒ Boolean
171 172 173 |
# File 'lib/acpc_table_manager/match_view.rb', line 171 def end |
#match_ended? ⇒ Boolean
73 |
# File 'lib/acpc_table_manager/match_view.rb', line 73 def match_ended?() slice.match_ended? end |
#minimum_wager_to ⇒ Object
Over round
121 122 123 |
# File 'lib/acpc_table_manager/match_view.rb', line 121 def minimum_wager_to @minimum_wager_to ||= slice.minimum_wager_to end |
#opponents ⇒ Object
98 99 100 |
# File 'lib/acpc_table_manager/match_view.rb', line 98 def opponents @opponents ||= compute_opponents end |
#opponents_sorted_by_position_from_user ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/acpc_table_manager/match_view.rb', line 101 def opponents_sorted_by_position_from_user @opponents_sorted_by_position_from_user ||= opponents.sort_by do |opp| Seat.new( opp['seat'], players.length ).seats_from( users_seat ) end end |
#players ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’
90 91 92 93 94 |
# File 'lib/acpc_table_manager/match_view.rb', line 90 def players return @players if @players @players = slice.players end |
#pot_after_call ⇒ Object
Over round
126 127 128 |
# File 'lib/acpc_table_manager/match_view.rb', line 126 def pot_after_call @pot_after_call ||= slice.pot_after_call end |
#pot_at_start_of_round ⇒ Object
71 |
# File 'lib/acpc_table_manager/match_view.rb', line 71 def pot_at_start_of_round() slice.pot_at_start_of_round end |
#pot_fraction_wager_to(fraction = 1) ⇒ Object
Over round
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/acpc_table_manager/match_view.rb', line 131 def pot_fraction_wager_to(fraction=1) return 0 if hand_ended? [ [ ( fraction * pot_after_call + chip_contribution_for_next_player_after_calling ), minimum_wager_to ].max, all_in ].min.floor end |
#slice ⇒ Object
66 |
# File 'lib/acpc_table_manager/match_view.rb', line 66 def slice() slices[@slice_index] end |
#state ⇒ Object
65 |
# File 'lib/acpc_table_manager/match_view.rb', line 65 def state() @state ||= MatchState.parse slice.state_string end |
#user ⇒ Object
95 96 97 |
# File 'lib/acpc_table_manager/match_view.rb', line 95 def user @user ||= players[users_seat] end |
#user_contributions_in_previous_rounds ⇒ Object
62 63 64 |
# File 'lib/acpc_table_manager/match_view.rb', line 62 def user_contributions_in_previous_rounds self.class.chip_contributions_in_previous_rounds(user, state.round) end |
#users_seat ⇒ Object
zero indexed
69 |
# File 'lib/acpc_table_manager/match_view.rb', line 69 def users_seat() @users_seat ||= @match.seat - 1 end |
#users_turn_to_act? ⇒ Boolean
74 |
# File 'lib/acpc_table_manager/match_view.rb', line 74 def users_turn_to_act?() slice.users_turn_to_act? end |