Class: AcpcPokerTypes::AcpcDealerData::PokerMatchData
- Inherits:
-
Object
- Object
- AcpcPokerTypes::AcpcDealerData::PokerMatchData
- Defined in:
- lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb
Instance Attribute Summary collapse
-
#chip_distribution ⇒ Object
Returns the value of attribute chip_distribution.
-
#data ⇒ Object
Returns the value of attribute data.
-
#hand_number ⇒ Object
Returns the value of attribute hand_number.
-
#match_def ⇒ Object
Returns the value of attribute match_def.
-
#players ⇒ Object
Returns the value of attribute players.
-
#seat ⇒ Object
Returns the value of attribute seat.
Class Method Summary collapse
- .parse(action_messages, result_messages, player_names, dealer_directory, num_hands = nil) ⇒ Object
- .parse_files(action_messages_file, result_messages_file, player_names, dealer_directory, num_hands = nil) ⇒ Object
Instance Method Summary collapse
- #active_players ⇒ Object
- #betting_sequence ⇒ Object
- #betting_sequence_string ⇒ Object
-
#chip_balances ⇒ Object
return [Array<Integer>] Each player’s current chip balance.
-
#chip_contributions ⇒ Object
return [Array<Array<Integer>>] Each player’s current chip contribution organized by round.
-
#chip_stacks ⇒ Array<ChipStack>
- AcpcPokerTypes
-
stacks.
- #current_hand ⇒ Object
- #final_hand? ⇒ Boolean
- #for_every_hand! ⇒ Object
- #for_every_seat! ⇒ Object
- #for_every_turn! ⇒ Object
- #hand_started? ⇒ Boolean
-
#initialize(parsed_action_messages, parsed_hand_results, player_names, dealer_directory) ⇒ PokerMatchData
constructor
A new instance of PokerMatchData.
- #match_has_another_round?(current_round, turn_index, turns_taken) ⇒ Boolean
- #non_folded_players ⇒ Object
- #opponents ⇒ Object
- #opponents_cards_visible? ⇒ Boolean
- #player(seat = @seat) ⇒ Object
- #player_acting_sequence ⇒ Object
-
#player_acting_sequence_string ⇒ String
Player acting sequence as a string.
-
#player_blind_relation ⇒ Hash<AcpcPokerTypes::, #to_i] Relation from player to the blind that player paid.
Hash<AcpcPokerTypes::, #to_i] Relation from player to the blind that player paid.
- #player_with_dealer_button ⇒ Object
- #users_turn_to_act? ⇒ Boolean
Constructor Details
#initialize(parsed_action_messages, parsed_hand_results, player_names, dealer_directory) ⇒ PokerMatchData
Returns a new instance of PokerMatchData.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 99 def initialize( , parsed_hand_results, player_names, dealer_directory ) if ( .match_def.nil? || parsed_hand_results.match_def.nil? || .match_def != parsed_hand_results.match_def ) raise MatchDefinitionsDoNotMatch end if ( .final_score != parsed_hand_results.final_score ) raise FinalScoresDoNotMatch end @match_def = parsed_hand_results.match_def if parsed_hand_results.final_score set_chip_distribution! parsed_hand_results.final_score end set_data! , parsed_hand_results # Zero-indexed seat @seat = 0 initialize_players! end |
Instance Attribute Details
#chip_distribution ⇒ Object
Returns the value of attribute chip_distribution.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def chip_distribution @chip_distribution end |
#data ⇒ Object
Returns the value of attribute data.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def data @data end |
#hand_number ⇒ Object
Returns the value of attribute hand_number.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def hand_number @hand_number end |
#match_def ⇒ Object
Returns the value of attribute match_def.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def match_def @match_def end |
#players ⇒ Object
Returns the value of attribute players.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def players @players end |
#seat ⇒ Object
Returns the value of attribute seat.
18 19 20 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 18 def seat @seat end |
Class Method Details
.parse(action_messages, result_messages, player_names, dealer_directory, num_hands = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 67 def self.parse( , , player_names, dealer_directory, num_hands=nil ) = Celluloid::Future.new do AcpcPokerTypes::AcpcDealerData::ActionMessages.parse( , player_names, dealer_directory, num_hands ) end parsed_hand_results = Celluloid::Future.new do AcpcPokerTypes::AcpcDealerData::HandResults.parse( , player_names, dealer_directory, num_hands ) end new( .value, parsed_hand_results.value, player_names, dealer_directory ) end |
.parse_files(action_messages_file, result_messages_file, player_names, dealer_directory, num_hands = nil) ⇒ Object
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 62 63 64 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 34 def self.parse_files( , , player_names, dealer_directory, num_hands=nil ) = Celluloid::Future.new do AcpcPokerTypes::AcpcDealerData::ActionMessages.parse_file( , player_names, dealer_directory, num_hands ) end parsed_hand_results = Celluloid::Future.new do AcpcPokerTypes::AcpcDealerData::HandResults.parse_file( , player_names, dealer_directory, num_hands ) end new( .value, parsed_hand_results.value, player_names, dealer_directory ) end |
Instance Method Details
#active_players ⇒ Object
259 260 261 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 259 def active_players @players.select { |player_to_collect| player_to_collect.active? } end |
#betting_sequence ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 296 def betting_sequence sequence = [[]] if ( @hand_number.nil? || current_hand.turn_number.nil? || current_hand.turn_number < 1 ) return sequence end turns_taken = current_hand.data[0..current_hand.turn_number-1] turns_taken.each_with_index do |turn, turn_index| next unless turn. sequence[turn..state.round] << turn..action if ( new_round?(sequence.length - 1 , turn_index) || players_all_in?(sequence.length - 1, turn_index, turns_taken) ) sequence << [] end end sequence end |
#betting_sequence_string ⇒ Object
323 324 325 326 327 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 323 def betting_sequence_string (betting_sequence.map do |per_round| (per_round.map{|action| action.to_acpc}).join('') end).join('/') end |
#chip_balances ⇒ Object
return [Array<Integer>] Each player’s current chip balance.
247 248 249 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 247 def chip_balances @players.map { |player| player.chip_balance } end |
#chip_contributions ⇒ Object
return [Array<Array<Integer>>] Each player’s current chip contribution organized by round.
252 253 254 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 252 def chip_contributions @players.map { |player| player.chip_contributions } end |
#chip_stacks ⇒ Array<ChipStack>
- Returns AcpcPokerTypes
-
stacks.
242 243 244 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 242 def chip_stacks @players.map { |player| player.chip_stack } end |
#current_hand ⇒ Object
233 234 235 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 233 def current_hand if @hand_number then @data[@hand_number] else nil end end |
#final_hand? ⇒ Boolean
237 238 239 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 237 def final_hand? if @hand_number then @hand_number >= @data.length - 1 else nil end end |
#for_every_hand! ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 147 def for_every_hand! initialize_players! @data.each_index do |i| @hand_number = i @players.each_with_index do |player, seat| player.start_new_hand!( @match_def.game_def.blinds[current_hand.data.first.[seat].position_relative_to_dealer], @match_def.game_def.chip_stacks[current_hand.data.first.[seat].position_relative_to_dealer], current_hand.data.first.[seat].users_hole_cards ) end yield @hand_number end if @chip_distribution && @chip_distribution != @players.map { |p| p.chip_balance } raise AcpcPokerTypes::DataInconsistent, "chip distribution: #{@chip_distribution}, player balances: #{@players.map { |p| p.chip_balance }}" end @hand_number = nil self end |
#for_every_seat! ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 133 def for_every_seat! match_def.game_def.number_of_players.times do |seat| @seat = seat initialize_players! yield seat end self end |
#for_every_turn! ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 172 def for_every_turn! current_hand.for_every_turn!(@seat) do |turn_number| @players.each_with_index do |player, seat| last_match_state = current_hand.last_match_state(seat) match_state = current_hand.current_match_state(seat) if current_hand.last_action && player.seat == current_hand.last_action.seat player.take_action!(current_hand.last_action.action) end if ( player.active? && !match_state.first_state_of_first_round? && match_state.round > last_match_state.round ) player.start_new_round! end if current_hand.final_turn? player.take_winnings!( current_hand.chip_distribution[seat] + @match_def.game_def.blinds[current_hand.current_match_state(seat).position_relative_to_dealer] ) end end yield turn_number end self end |
#hand_started? ⇒ Boolean
209 210 211 212 213 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 209 def hand_started? @hand_number && current_hand.turn_number && current_hand.turn_number > 0 end |
#match_has_another_round?(current_round, turn_index, turns_taken) ⇒ Boolean
204 205 206 207 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 204 def match_has_another_round?(current_round, turn_index, turns_taken) new_round?(current_round, turn_index) || players_all_in?(current_round, turn_index, turns_taken) end |
#non_folded_players ⇒ Object
262 263 264 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 262 def non_folded_players @players.reject { |player_to_reject| player_to_reject.folded? } end |
#opponents ⇒ Object
256 257 258 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 256 def opponents @players.reject { |other_player| player == other_player } end |
#opponents_cards_visible? ⇒ Boolean
265 266 267 268 269 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 265 def opponents_cards_visible? return false unless current_hand current_hand.current_match_state.list_of_hole_card_hands.reject_empty_elements.length > 1 end |
#player(seat = @seat) ⇒ Object
145 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 145 def player(seat=@seat) @players[seat] end |
#player_acting_sequence ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 215 def player_acting_sequence sequence = [[]] return sequence unless hand_started? turns_taken = current_hand.data[0..current_hand.turn_number-1] turns_taken.each_with_index do |turn, turn_index| next unless turn. sequence[turn..state.round] << turn..seat if match_has_another_round?(sequence.length - 1, turn_index, turns_taken) sequence << [] end end sequence end |
#player_acting_sequence_string ⇒ String
Untested
Returns player acting sequence as a string.
289 290 291 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 289 def player_acting_sequence_string (player_acting_sequence.map { |per_round| per_round.join('') }).join('/') end |
#player_blind_relation ⇒ Hash<AcpcPokerTypes::, #to_i] Relation from player to the blind that player paid.
Returns Hash<AcpcPokerTypes::, #to_i] Relation from player to the blind that player paid.
278 279 280 281 282 283 284 285 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 278 def player_blind_relation return nil unless current_hand @players.inject({}) do |relation, plr| relation[plr] = @match_def.game_def.blinds[current_hand.current_match_state(plr.seat).position_relative_to_dealer] relation end end |
#player_with_dealer_button ⇒ Object
270 271 272 273 274 275 276 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 270 def return nil unless current_hand @players.find do |plr| current_hand.current_match_state(plr.seat).position_relative_to_dealer == @players.length - 1 end end |
#users_turn_to_act? ⇒ Boolean
292 293 294 295 |
# File 'lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb', line 292 def users_turn_to_act? return false unless current_hand && current_hand.next_action current_hand.next_action.seat == @seat end |