acpc_poker_types 5.0.3 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/acpc_poker_types.gemspec +3 -2
  4. data/lib/acpc_poker_types.rb +1 -1
  5. data/lib/acpc_poker_types/acpc_dealer_data/hand_results.rb +5 -5
  6. data/lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb +290 -323
  7. data/lib/acpc_poker_types/game_definition.rb +54 -37
  8. data/lib/acpc_poker_types/hand_player.rb +119 -0
  9. data/lib/acpc_poker_types/match_state.rb +323 -204
  10. data/lib/acpc_poker_types/player_group.rb +62 -0
  11. data/lib/acpc_poker_types/poker_action.rb +13 -6
  12. data/lib/acpc_poker_types/version.rb +1 -1
  13. data/spec/game_definition_spec.rb +23 -4
  14. data/spec/hand_player_spec.rb +254 -0
  15. data/spec/match_state_spec.rb +655 -112
  16. data/spec/player_group_spec.rb +57 -0
  17. data/spec/poker_match_data_spec.rb +24 -21
  18. data/spec/support/spec_helper.rb +2 -16
  19. metadata +68 -148
  20. data/lib/acpc_poker_types/player.rb +0 -182
  21. data/spec/coverage/assets/0.7.1/application.css +0 -1110
  22. data/spec/coverage/assets/0.7.1/application.js +0 -626
  23. data/spec/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  24. data/spec/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  25. data/spec/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  26. data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  27. data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  28. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  29. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  30. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  31. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  32. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  33. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  34. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  35. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  36. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  37. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  38. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  39. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  40. data/spec/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  41. data/spec/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  42. data/spec/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  43. data/spec/coverage/assets/0.7.1/favicon_green.png +0 -0
  44. data/spec/coverage/assets/0.7.1/favicon_red.png +0 -0
  45. data/spec/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  46. data/spec/coverage/assets/0.7.1/loading.gif +0 -0
  47. data/spec/coverage/assets/0.7.1/magnify.png +0 -0
  48. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  49. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  50. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  51. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  52. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  53. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  54. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  55. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  56. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  57. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  58. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  59. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  60. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  61. data/spec/coverage/index.html +0 -72
  62. data/spec/match_state_perf.rb +0 -14
  63. data/spec/player_spec.rb +0 -372
Binary file
Binary file
@@ -1,72 +0,0 @@
1
- <!DOCTYPE html>
2
- <html xmlns='http://www.w3.org/1999/xhtml'>
3
- <head>
4
- <title>Code coverage for Spec</title>
5
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
- <script src='./assets/0.7.1/application.js' type='text/javascript'></script>
7
- <link href='./assets/0.7.1/application.css' media='screen, projection, print' rel='stylesheet' type='text/css'>
8
- <link rel="shortcut icon" type="image/png" href="./assets/0.7.1/favicon_green.png" />
9
- <link rel="icon" type="image/png" href="./assets/0.7.1/favicon.png" />
10
- </head>
11
-
12
- <body>
13
- <div id="loading">
14
- <img src="./assets/0.7.1/loading.gif" alt="loading"/>
15
- </div>
16
- <div id="wrapper" style="display:none;">
17
- <div class="timestamp">Generated <abbr class="timeago" title="2013-07-18T15:31:07-06:00">2013-07-18T15:31:07-06:00</abbr></div>
18
- <ul class="group_tabs"></ul>
19
-
20
- <div id="content">
21
- <div class="file_list_container" id="AllFiles">
22
- <h2>
23
- <span class="group_name">All Files</span>
24
- (<span class="covered_percent"><span class="green">100.0%</span></span>
25
- covered at
26
- <span class="covered_strength">
27
- <span class="red">
28
- 0.0
29
- </span>
30
- </span> hits/line)
31
- </h2>
32
- <a name="AllFiles"></a>
33
- <div>
34
- <b>0</b> files in total.
35
- <b>0.0</b> relevant lines.
36
- <span class="green"><b>0.0</b> lines covered</span> and
37
- <span class="red"><b>0.0</b> lines missed </span>
38
- </div>
39
- <table class="file_list">
40
- <thead>
41
- <tr>
42
- <th>File</th>
43
- <th>% covered</th>
44
- <th>Lines</th>
45
- <th>Relevant Lines</th>
46
- <th>Lines covered</th>
47
- <th>Lines missed</th>
48
- <th>Avg. Hits / Line</th>
49
- </tr>
50
- </thead>
51
- <tbody>
52
-
53
- </tbody>
54
- </table>
55
- </div>
56
-
57
-
58
-
59
- </div>
60
-
61
- <div id="footer">
62
- Generated by <a href="http://github.com/colszowka/simplecov">simplecov</a> v0.7.1
63
- and simplecov-html v0.7.1<br/>
64
- using RSpec
65
- </div>
66
-
67
- <div class="source_files">
68
-
69
- </div>
70
- </div>
71
- </body>
72
- </html>
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative "../lib/acpc_poker_types/match_state"
4
-
5
- # require 'acpc_poker_types/match_state'
6
- require 'method_profiler'
7
-
8
- profiler = MethodProfiler.observe(AcpcPokerTypes::MatchState)
9
-
10
- m = AcpcPokerTypes::MatchState.parse "#{AcpcPokerTypes::MatchState::LABEL}:0:1:cc/rrc/rf:AhKs|2c7h/Th5s6c/9s/3h"
11
-
12
- puts m
13
-
14
- puts profiler.report
data/spec/player_spec.rb DELETED
@@ -1,372 +0,0 @@
1
-
2
- # Spec helper (must include first to track code coverage with SimpleCov)
3
- require_relative 'support/spec_helper'
4
-
5
- require 'acpc_dealer'
6
- require 'acpc_poker_types/acpc_dealer_data/poker_match_data'
7
-
8
- require 'acpc_poker_types/player'
9
- require 'acpc_poker_types/poker_action'
10
- require 'acpc_poker_types/hand'
11
- require 'acpc_poker_types/match_state'
12
-
13
- describe AcpcPokerTypes::Player do
14
- NAME = 'p1'
15
- SEAT = '1'
16
- INITIAL_CHIP_STACK = 100000
17
- BLIND = 100
18
-
19
- before(:each) do
20
- @name = NAME
21
- @seat = SEAT.to_i - 1
22
- @chip_stack = INITIAL_CHIP_STACK
23
- @chip_balance = 0
24
- @hole_cards = nil
25
- @actions_taken_this_hand = [[]]
26
- @has_folded = false
27
- @is_all_in = false
28
- @is_active = true
29
- @round = 0
30
- @chip_contributions = [0]
31
-
32
- init_patient!
33
- end
34
-
35
- describe '::create_players' do
36
- it "raises an exception if the number of player names doesn't match the number of players from the game definition" do
37
- game_def = mock 'GameDefinition'
38
- various_numbers_of_players do |number_of_players|
39
- game_def.stubs(:number_of_players).returns(number_of_players)
40
-
41
- -> do
42
- AcpcPokerTypes::Player.create_players(
43
- ((number_of_players-1).times.inject([]) do |names, i|
44
- names << "p#{i}"
45
- end
46
- ),
47
- game_def
48
- )
49
- end.must_raise(AcpcPokerTypes::Player::IncorrectNumberOfPlayerNames)
50
- -> do
51
- AcpcPokerTypes::Player.create_players(
52
- ((number_of_players+1).times.inject([]) do |names, i|
53
- names << "p#{i}"
54
- end
55
- ),
56
- game_def
57
- )
58
- end.must_raise(AcpcPokerTypes::Player::IncorrectNumberOfPlayerNames)
59
- end
60
- end
61
- it 'works properly' do
62
- game_def = mock 'GameDefinition'
63
- various_numbers_of_players do |number_of_players|
64
- game_def.stubs(:number_of_players).returns(number_of_players)
65
- game_def.expects(:chip_stacks).times(number_of_players).returns(INITIAL_CHIP_STACK)
66
-
67
- patients = AcpcPokerTypes::Player.create_players(
68
- (number_of_players.times.inject([]) do |names, i|
69
- names << "p#{i}"
70
- end),
71
- game_def
72
- )
73
-
74
- patients.length.must_equal number_of_players
75
- patients.each do |patient|
76
- patient.class.must_equal AcpcPokerTypes::Player
77
- end
78
- end
79
- end
80
- end
81
- describe '#join_match' do
82
- it 'initializes properly' do
83
- check_patient
84
- end
85
- end
86
- describe '#take_action!' do
87
- describe 'updates player state properly' do
88
- it 'given the player did not fold' do
89
- test_sequence_of_non_fold_actions
90
- end
91
- end
92
- end
93
- describe '#start_new_hand!' do
94
- describe 'resets player data properly after taking actions' do
95
- it "in Doyle's game" do
96
- i = 0
97
- various_hands do |hand|
98
- init_patient!
99
- @position_relative_to_dealer = i
100
-
101
- test_sequence_of_non_fold_actions hand
102
-
103
- i += 1
104
- end
105
- end
106
- it 'in a continuous game' do
107
- i = 0
108
- various_hands do |hand|
109
- init_patient!
110
- @position_relative_to_dealer = i
111
-
112
- test_sequence_of_non_fold_actions hand
113
-
114
- i += 1
115
- end
116
- end
117
- end
118
- end
119
- describe 'reports it is not active if' do
120
- it 'it has folded' do
121
- action = AcpcPokerTypes::PokerAction.new AcpcPokerTypes::PokerAction::FOLD
122
-
123
- @patient.start_new_hand! BLIND, INITIAL_CHIP_STACK
124
- @patient.take_action! action
125
-
126
- @chip_stack = INITIAL_CHIP_STACK - BLIND
127
- @chip_balance = -BLIND
128
- @chip_contributions = [BLIND]
129
- @hole_cards = AcpcPokerTypes::Hand.new
130
- @actions_taken_this_hand = [[action]]
131
- @has_folded = true
132
- @is_all_in = false
133
- @is_active = false
134
- @round = 0
135
-
136
- check_patient
137
- end
138
- it 'it is all-in' do
139
- action = AcpcPokerTypes::PokerAction.new AcpcPokerTypes::PokerAction::RAISE, cost: INITIAL_CHIP_STACK - BLIND
140
-
141
- hand = default_hand
142
- @patient.start_new_hand! BLIND, INITIAL_CHIP_STACK, hand
143
- @patient.take_action! action
144
-
145
- @chip_stack = 0
146
- @chip_balance = -INITIAL_CHIP_STACK
147
- @chip_contributions = [INITIAL_CHIP_STACK]
148
- @hole_cards = hand
149
- @actions_taken_this_hand = [[action]]
150
- @has_folded = false
151
- @is_all_in = true
152
- @is_active = false
153
- @round = 0
154
-
155
- check_patient
156
- end
157
- end
158
- describe 'properly changes its state when it wins chips' do
159
- it 'when the number of chips is an integer' do
160
- @patient.chip_balance.must_equal 0
161
-
162
- pot_size = 22
163
- @patient.take_winnings! pot_size
164
-
165
- @patient.chip_stack.must_equal INITIAL_CHIP_STACK + pot_size
166
- @patient.chip_balance.must_equal pot_size
167
- @patient.chip_contributions.must_equal [0, -pot_size]
168
- end
169
- it 'when the number of chips is a rational' do
170
- @patient.chip_balance.must_equal 0
171
-
172
- pot_size = 22/3.to_r
173
- @patient.take_winnings! pot_size
174
-
175
- @patient.chip_stack.must_equal INITIAL_CHIP_STACK + pot_size
176
- @patient.chip_balance.must_equal pot_size
177
- @patient.chip_contributions.must_equal [0, -pot_size]
178
- end
179
- end
180
- it 'works properly over samples of data from the ACPC Dealer' do
181
- dealer_log_directory = File.expand_path('../support/dealer_logs', __FILE__)
182
- MatchLog.all.each do |log_description|
183
- match = AcpcPokerTypes::AcpcDealerData::PokerMatchData.parse_files(
184
- "#{dealer_log_directory}/#{log_description.actions_file_name}",
185
- "#{dealer_log_directory}/#{log_description.results_file_name}",
186
- log_description.player_names,
187
- AcpcDealer::DEALER_DIRECTORY,
188
- 10
189
- )
190
- match.for_every_seat! do |seat|
191
- @patient = AcpcPokerTypes::Player.join_match(
192
- match.match_def.player_names[seat],
193
- seat,
194
- match.match_def.game_def.chip_stacks[seat]
195
- )
196
-
197
- match.for_every_hand! do
198
-
199
- @patient.start_new_hand!(
200
- match.match_def.game_def.blinds[seat],
201
- match.match_def.game_def.chip_stacks[seat],
202
- match.current_hand.data.first.state_messages[seat].users_hole_cards
203
- )
204
- match.for_every_turn! do
205
- if (
206
- match.current_hand.last_action &&
207
- @patient.seat == match.current_hand.last_action.seat
208
- )
209
- @patient.take_action!(match.current_hand.last_action.action)
210
- end
211
-
212
- match_state = match.current_hand.current_match_state
213
- last_match_state = match.current_hand.last_match_state
214
-
215
- if !match_state.first_state_of_first_round? && match_state.round > last_match_state.round
216
- @patient.start_new_round!
217
- end
218
- if match.current_hand.final_turn?
219
- @patient.take_winnings!(match.current_hand.chip_distribution[seat] + match.match_def.game_def.blinds[seat])
220
- end
221
-
222
- @patient.name.must_equal match.player.name
223
- @patient.seat.must_equal seat
224
- @patient.hole_cards.must_equal match.player.hole_cards
225
- @patient.actions_taken_this_hand.reject_empty_elements.must_equal match.player.actions_taken_this_hand.reject_empty_elements
226
-
227
- @patient.folded?.must_equal match.player.folded?
228
- @patient.all_in?.must_equal match.player.all_in?
229
- @patient.active?.must_equal match.player.active?
230
- @patient.round.must_equal match.current_hand.current_match_state.round
231
- end
232
-
233
- @patient.chip_balance.must_equal match.player.chip_balance
234
- end
235
- end
236
- end
237
- end
238
-
239
- def check_patient
240
- @patient.name.must_equal @name
241
- @patient.seat.must_equal @seat
242
- @patient.chip_stack.must_equal @chip_stack
243
- @patient.chip_contributions.must_equal @chip_contributions
244
- @patient.chip_balance.must_equal @chip_balance
245
- if @hole_cards
246
- (@patient.hole_cards.map { |card| card.to_s} ).must_equal @hole_cards.map { |card| card.to_s }
247
- else
248
- @patient.hole_cards.must_be_nil
249
- end
250
-
251
- @patient.actions_taken_this_hand.must_equal @actions_taken_this_hand
252
- @patient.folded?.must_equal @has_folded
253
- @patient.all_in?.must_equal @is_all_in
254
- @patient.active?.must_equal @is_active
255
- @patient.round.must_equal @round
256
- end
257
- def various_numbers_of_players
258
- (1..100).each do |number_of_players|
259
- yield number_of_players
260
- end
261
- end
262
-
263
- class Array
264
- def reject_empty_elements
265
- reject do |elem|
266
- elem.empty?
267
- end
268
- end
269
- end
270
-
271
- def various_actions
272
- various_amounts_to_put_in_pot do |amount|
273
- with_and_without_a_modifier do |modifier|
274
- instantiate_each_action_from_symbols(amount, modifier) do |action|
275
- yield action
276
- end
277
- end
278
- end
279
- end
280
- def default_modifier
281
- modifier_amount = 9001
282
- modifier = mock 'ChipStack'
283
- modifier.stubs(:to_s).returns(modifier_amount.to_s)
284
- modifier
285
- end
286
- def various_amounts_to_put_in_pot
287
- [0, 9002, -9002].each do |amount|
288
- yield amount
289
- end
290
- end
291
- def with_and_without_a_modifier
292
- [nil, default_modifier].each do |modifier|
293
- yield modifier
294
- end
295
- end
296
- def instantiate_each_action_from_symbols(
297
- cost=0, modifier=nil
298
- )
299
- AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |action|
300
- modifier = if AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.include? action
301
- modifier
302
- else
303
- nil
304
- end
305
-
306
- yield AcpcPokerTypes::PokerAction.new(action, cost: cost, modifier: modifier)
307
- end
308
- end
309
- def test_sequence_of_non_fold_actions(hole_cards=default_hand)
310
- @hole_cards = hole_cards
311
- @has_folded = false
312
-
313
- @patient.start_new_hand! BLIND, INITIAL_CHIP_STACK, @hole_cards
314
-
315
- init_new_hand_data!
316
-
317
- number_of_rounds = 4
318
- number_of_rounds.times do |round|
319
- @round = round
320
-
321
- unless 0 == round
322
- @patient.start_new_round!
323
- @chip_contributions << 0
324
- @actions_taken_this_hand << []
325
- end
326
-
327
- various_actions do |action|
328
- next if AcpcPokerTypes::PokerAction::FOLD == action.to_s
329
-
330
- chip_stack_adjustment = if @chip_stack - action.cost >= 0
331
- action.cost
332
- else @chip_stack end
333
-
334
- @chip_balance -= chip_stack_adjustment
335
- @chip_stack -= chip_stack_adjustment
336
- @chip_contributions[-1] += chip_stack_adjustment
337
-
338
- @is_all_in = 0 == @chip_stack
339
- @is_active = !@is_all_in
340
-
341
- @actions_taken_this_hand.last << action
342
-
343
- @patient.take_action! action
344
-
345
- check_patient
346
- end
347
- end
348
- end
349
- def various_hands
350
- ([default_hand] * 10).each do |hole_cards|
351
- yield hole_cards
352
- end
353
- end
354
- def default_hand
355
- hidden_cards = AcpcPokerTypes::Hand.new
356
-
357
- hidden_cards
358
- end
359
- def init_patient!
360
- @patient = AcpcPokerTypes::Player.join_match @name, @seat, @chip_stack
361
- end
362
- def init_new_hand_data!
363
- @actions_taken_this_hand = [[]]
364
- init_new_hand_chip_data!
365
- end
366
- def init_new_hand_chip_data!
367
- # @todo Assumes Doyle's Game
368
- @chip_contributions = [BLIND]
369
- @chip_balance = -@chip_contributions.first
370
- @chip_stack = INITIAL_CHIP_STACK - @chip_contributions.first
371
- end
372
- end