Class: AcpcPokerTypes::DealerData::PokerMatchData

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/dealer_data/poker_match_data.rb

Defined Under Namespace

Classes: Player

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_action_messages, parsed_hand_results, player_names, dealer_directory) ⇒ PokerMatchData

Returns a new instance of PokerMatchData.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 109

def initialize(
  parsed_action_messages,
  parsed_hand_results,
  player_names,
  dealer_directory
)
  @hand_number = nil
  @chip_distribution = nil
  if (
    parsed_action_messages.match_def.nil? ||
    parsed_hand_results.match_def.nil? ||
    parsed_action_messages.match_def != parsed_hand_results.match_def
  )
    raise MatchDefinitionsDoNotMatch
  end

  if parsed_action_messages.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_action_messages, parsed_hand_results

  # Zero-indexed seat
  @seat = 0

  initialize_players!
end

Instance Attribute Details

#chip_distributionObject

Returns the value of attribute chip_distribution.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def chip_distribution
  @chip_distribution
end

#dataObject

Returns the value of attribute data.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def data
  @data
end

#hand_numberObject

Returns the value of attribute hand_number.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def hand_number
  @hand_number
end

#match_defObject

Returns the value of attribute match_def.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def match_def
  @match_def
end

#playersObject

Returns the value of attribute players.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def players
  @players
end

#seatObject

Returns the value of attribute seat.



19
20
21
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 19

def seat
  @seat
end

Class Method Details

.parse(action_messages, result_messages, player_names, dealer_directory, num_hands = nil) ⇒ Object



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
98
99
100
101
102
103
104
105
106
107
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 72

def self.parse(
  action_messages,
  result_messages,
  player_names,
  dealer_directory,
  num_hands=nil
)
  Celluloid.boot
  parsed_action_messages = Celluloid::Future.new do
     DealerData::ActionMessages.parse(
      action_messages,
      player_names,
      dealer_directory,
      num_hands
    )
  end
  parsed_hand_results = Celluloid::Future.new do
     DealerData::HandResults.parse(
      result_messages,
      player_names,
      dealer_directory,
      num_hands
    )
  end

  instance = new(
    parsed_action_messages.value,
    parsed_hand_results.value,
    player_names,
    dealer_directory
  )

  Celluloid.shutdown

  instance
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
60
61
62
63
64
65
66
67
68
69
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 35

def self.parse_files(
  action_messages_file,
  result_messages_file,
  player_names,
  dealer_directory,
  num_hands=nil
)
  Celluloid.boot
  parsed_action_messages = Celluloid::Future.new do
     DealerData::ActionMessages.parse_file(
      action_messages_file,
      player_names,
      dealer_directory,
      num_hands
    )
  end
  parsed_hand_results = Celluloid::Future.new do
     DealerData::HandResults.parse_file(
      result_messages_file,
      player_names,
      dealer_directory,
      num_hands
    )
  end

  instance = new(
    parsed_action_messages.value,
    parsed_hand_results.value,
    player_names,
    dealer_directory
  )
  Celluloid.shutdown

  instance
end

Instance Method Details

#balancesObject

return [Array<Integer>] Each player’s current chip balance.



244
245
246
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 244

def balances
  @players.map { |player| player.balance }
end

#betting_sequenceObject



275
276
277
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 275

def betting_sequence
  sequence_from_action_messages(:action)
end

#betting_sequence_stringObject



278
279
280
281
282
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 278

def betting_sequence_string
  (betting_sequence.map do |per_round|
     (per_round.map{|action| action.to_acpc}).join('')
  end).join('/')
end

#current_handObject



235
236
237
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 235

def current_hand
  if @hand_number then @data[@hand_number] else nil end
end

#distribute_chips!Object



164
165
166
167
168
169
170
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 164

def distribute_chips!
  @players.each do |plyr|
    plyr.balance += hand_player(plyr).balance
  end

  self
end

#end_hand!Object



172
173
174
175
176
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 172

def end_hand!
  current_hand.end_hand!

  self
end

#end_match!Object



178
179
180
181
182
183
184
185
186
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 178

def end_match!
  player_balances = @players.map { |plyr| plyr.balance }
  if @chip_distribution && @chip_distribution != player_balances
    raise DataInconsistent, "chip distribution: #{@chip_distribution}, player balances: #{player_balances}"
  end

  @hand_number = nil
  self
end

#final_hand?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 239

def final_hand?
  if @hand_number then @hand_number >= @data.length - 1 else nil end
end

#for_every_hand!Object



200
201
202
203
204
205
206
207
208
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 200

def for_every_hand!
  while @hand_number.nil? || (@hand_number < @data.length - 1) do
    next_hand!
    yield @hand_number
    end_hand!
  end

  end_match!
end

#for_every_seat!Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 143

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



216
217
218
219
220
221
222
223
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 216

def for_every_turn!
  while current_hand.turn_number.nil? || (current_hand.turn_number < current_hand.data.length - 1) do
    next_turn!
    yield current_hand.turn_number
  end

  self
end

#hand_player(plyr = player) ⇒ Object



194
195
196
197
198
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 194

def hand_player(plyr = player)
  return nil unless current_hand && current_hand.current_match_state

  current_hand.current_match_state.players(match_def.game_def)[position_relative_to_dealer(plyr)]
end

#hand_player_balancesObject



188
189
190
191
192
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 188

def hand_player_balances
  return [0] * match_def.game_def.number_of_players unless current_hand && current_hand.current_match_state

  @players.map { |p| hand_player(p).balance }
end

#hand_started?Boolean

Returns:

  • (Boolean)


225
226
227
228
229
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 225

def hand_started?
  @hand_number &&
  current_hand.turn_number &&
  current_hand.turn_number > 0
end

#next_hand!Object



157
158
159
160
161
162
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 157

def next_hand!
  init_or_increment_hand_num!
  current_hand.start_hand! @seat

  self
end

#next_turn!Object



210
211
212
213
214
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 210

def next_turn!
  current_hand.next_turn!
  distribute_chips! if current_hand.final_turn?
  self
end

#opponents_cards_visible?Boolean

Returns:

  • (Boolean)


248
249
250
251
252
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 248

def opponents_cards_visible?
  return false unless current_hand

  current_hand.current_match_state.opponents_cards_visible?
end

#player(seat = @seat) ⇒ Object



155
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 155

def player(seat=@seat) @players[seat] end

#player_acting_sequenceObject



231
232
233
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 231

def player_acting_sequence
  sequence_from_action_messages(:seat)
end

#player_acting_sequence_stringString

Returns player acting sequence as a string.

Returns:

  • (String)

    player acting sequence as a string.



268
269
270
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 268

def player_acting_sequence_string
  (player_acting_sequence.map { |per_round| per_round.join('') }).join('/')
end

#player_with_dealer_buttonObject



253
254
255
256
257
258
259
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 253

def player_with_dealer_button
  return nil unless current_hand

  @players.find do |plr|
    position_relative_to_dealer(plr) == @players.length - 1
  end
end

#position_relative_to_dealer(plyr = player) ⇒ Object



261
262
263
264
265
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 261

def position_relative_to_dealer(plyr = player)
  return nil unless current_hand && current_hand.current_match_state(plyr.seat)

  current_hand.current_match_state(plyr.seat).position_relative_to_dealer
end

#users_turn_to_act?Boolean

Returns:

  • (Boolean)


271
272
273
274
# File 'lib/acpc_poker_types/dealer_data/poker_match_data.rb', line 271

def users_turn_to_act?
  return false unless current_hand && current_hand.next_action
  current_hand.next_action.seat == @seat
end