Class: PokerMatchData
- Inherits:
-
Object
- Object
- PokerMatchData
- Defined in:
- lib/acpc_dealer_data/poker_match_data.rb
Instance Attribute Summary collapse
-
#chip_distribution ⇒ Object
readonly
Returns the value of attribute chip_distribution.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#hand_number ⇒ Object
readonly
Returns the value of attribute hand_number.
-
#match_def ⇒ Object
readonly
Returns the value of attribute match_def.
-
#players ⇒ Object
readonly
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
- #actions_taken_this_hand(seat = @seat) ⇒ Object
- #active?(seat = @seat) ⇒ Boolean
- #all_in?(seat = @seat) ⇒ Boolean
- #chip_balance(seat = @seat) ⇒ Object
- #current_hand ⇒ Object
- #final_hand? ⇒ Boolean
- #folded?(seat = @seat) ⇒ Boolean
- #for_every_hand! ⇒ Object
- #for_every_seat! ⇒ Object
- #for_every_turn! ⇒ Object
- #hole_cards(seat = @seat) ⇒ Object
-
#initialize(parsed_action_messages, parsed_hand_results, player_names, dealer_directory) ⇒ PokerMatchData
constructor
A new instance of PokerMatchData.
- #initialize_players! ⇒ Object protected
- #player_acting_sequence ⇒ Object
- #player_name(seat = @seat) ⇒ Object
- #set_chip_distribution!(final_score) ⇒ Object protected
- #set_data!(parsed_action_messages, parsed_hand_results) ⇒ Object protected
Constructor Details
#initialize(parsed_action_messages, parsed_hand_results, player_names, dealer_directory) ⇒ PokerMatchData
Returns a new instance of PokerMatchData.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 88 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 (readonly)
Returns the value of attribute chip_distribution.
17 18 19 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 17 def chip_distribution @chip_distribution end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 17 def data @data end |
#hand_number ⇒ Object (readonly)
Returns the value of attribute hand_number.
17 18 19 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 17 def hand_number @hand_number end |
#match_def ⇒ Object (readonly)
Returns the value of attribute match_def.
17 18 19 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 17 def match_def @match_def end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
17 18 19 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 17 def players @players end |
#seat ⇒ Object
Returns the value of attribute seat.
29 30 31 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 29 def seat @seat end |
Class Method Details
.parse(action_messages, result_messages, player_names, dealer_directory, num_hands = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 62 def self.parse(, , player_names, dealer_directory, num_hands=nil) = Celluloid::Future.new do ActionMessages.parse( , player_names, dealer_directory, num_hands ) end parsed_hand_results = Celluloid::Future.new do HandResults.parse( , player_names, dealer_directory, num_hands ) end PokerMatchData.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
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 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 35 def self.parse_files(, , player_names, dealer_directory, num_hands=nil) = Celluloid::Future.new do ActionMessages.parse_file( , player_names, dealer_directory, num_hands ) end parsed_hand_results = Celluloid::Future.new do HandResults.parse_file( , player_names, dealer_directory, num_hands ) end PokerMatchData.new( .value, parsed_hand_results.value, player_names, dealer_directory ) end |
Instance Method Details
#actions_taken_this_hand(seat = @seat) ⇒ Object
132 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 132 def actions_taken_this_hand(seat=@seat) @players[seat].actions_taken_this_hand end |
#active?(seat = @seat) ⇒ Boolean
135 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 135 def active?(seat=@seat) @players[seat].active? end |
#all_in?(seat = @seat) ⇒ Boolean
134 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 134 def all_in?(seat=@seat) @players[seat].all_in? end |
#chip_balance(seat = @seat) ⇒ Object
130 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 130 def chip_balance(seat=@seat) @players[seat].chip_balance end |
#current_hand ⇒ Object
213 214 215 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 213 def current_hand if @hand_number then @data[@hand_number] else nil end end |
#final_hand? ⇒ Boolean
217 218 219 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 217 def final_hand? if @hand_number then @hand_number >= @data.length - 1 else nil end end |
#folded?(seat = @seat) ⇒ Boolean
133 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 133 def folded?(seat=@seat) @players[seat].folded? end |
#for_every_hand! ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 137 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[seat], @match_def.game_def.chip_stacks[seat], 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 PlayerDataInconsistent, "chip distribution: #{@chip_distribution}, player balances: #{@players.map { |p| p.chip_balance }}" end @hand_number = nil self end |
#for_every_seat! ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 117 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
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 162 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 !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[seat] ) end end yield turn_number end self end |
#hole_cards(seat = @seat) ⇒ Object
131 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 131 def hole_cards(seat=@seat) @players[seat].hole_cards end |
#initialize_players! ⇒ Object (protected)
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 223 def initialize_players! @players = @match_def.player_names.length.times.map do |seat| Player.join_match( @match_def.player_names[seat], seat, @match_def.game_def.chip_stacks[seat] ) end self end |
#player_acting_sequence ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 189 def player_acting_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..seat if ( new_round?(sequence.length - 1 , turn_index) || players_all_in?(sequence.length - 1, turn_index) ) sequence << [] end end sequence end |
#player_name(seat = @seat) ⇒ Object
129 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 129 def player_name(seat=@seat) @players[seat].name end |
#set_chip_distribution!(final_score) ⇒ Object (protected)
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 235 def set_chip_distribution!(final_score) @chip_distribution = [] final_score.each do |player_name, amount| begin @chip_distribution[@match_def.player_names.index(player_name.to_s)] = amount rescue TypeError raise PlayerNamesDoNotMatch end end self end |
#set_data!(parsed_action_messages, parsed_hand_results) ⇒ Object (protected)
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/acpc_dealer_data/poker_match_data.rb', line 248 def set_data!(, parsed_hand_results) @data = [] .data.zip(parsed_hand_results.data).each do |, hand_result| @data << HandData.new( @match_def, , hand_result ) end self end |