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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cb9cb8ff43820e44d0d424314ffa480a1a10e53
4
- data.tar.gz: 48a0dde3388f6fe3c829fba78eab32764feedb85
3
+ metadata.gz: 3381e33e9879dcca0d128817498cb80ef96155f7
4
+ data.tar.gz: f1a3fd8a83746913f6a395d715fa5aaa1c085529
5
5
  SHA512:
6
- metadata.gz: 238349c4a28a621eef03e9226baafb1275cb0258e627c088bdcfcce5a7a7ce7e4bb5b5d12a9f471b0c626824344f2f1c0e767c2c5fa8ca6217e79fe9c3c635ca
7
- data.tar.gz: 9f8328b2e465f50a6a6bd2c71d36e83779f2b29404cb0f95d0b1b79dfacb34b76d771f684d86fc17c48e9c73fd32a09192fcb8da8a17a3966e3c1548e2fa4b9e
6
+ metadata.gz: 8cd00ac46a327928b2bee5e2a92c87001ff01f3d0e8afe9c3ab6792d4f72cc1651322fcd0dc485b2691286858461c2135015dd743c9cd439e96410a0da6d11b1
7
+ data.tar.gz: abee379aa7a779b73b344997bba3fb036852211493f3abcc72fb4fa528d2f2e1518bdd40cf2ce0cd81a16f6ac16e651dcc85c3488b7c4bd0a7b4e5d119defaaa
data/Rakefile CHANGED
@@ -8,5 +8,5 @@ Rake::TestTask.new do |t|
8
8
  t.libs << "lib" << 'spec/support'
9
9
  t.test_files = FileList['spec/**/*_spec.rb']
10
10
  t.verbose = false
11
- t.warning = false # pry-rescue has a lot of warnings
11
+ t.warning = false
12
12
  end
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.homepage = "https://github.com/dmorrill10/acpc_poker_types"
10
10
  s.summary = %q{ACPC Poker Types}
11
11
  s.description = %q{Poker classes and constants that conform to the standards of the Annual Computer Poker Competition.}
12
+ s.license = 'MIT'
12
13
 
13
14
  s.add_dependency 'process_runner', '~> 0.0'
14
15
  s.add_dependency 'acpc_dealer', '~> 2.0'
@@ -19,10 +20,10 @@ Gem::Specification.new do |s|
19
20
  s.test_files = Dir.glob "spec/**/*"
20
21
  s.require_paths = ["lib"]
21
22
 
22
- s.add_development_dependency 'turn', '~> 0.9'
23
- s.add_development_dependency 'minitest', '~> 4.7'
23
+ s.add_development_dependency 'minitest', '~> 5.0.6'
24
24
  s.add_development_dependency 'mocha', '~> 0.13'
25
25
  s.add_development_dependency 'awesome_print', '~> 1.0'
26
26
  s.add_development_dependency 'pry-rescue', '~> 1.0'
27
27
  s.add_development_dependency 'simplecov', '~> 0.7'
28
+ s.add_development_dependency 'method_profiler'
28
29
  end
@@ -5,9 +5,9 @@ require "acpc_poker_types/card"
5
5
  require "acpc_poker_types/chip_stack"
6
6
  require "acpc_poker_types/game_definition"
7
7
  require "acpc_poker_types/hand"
8
+ require 'acpc_poker_types/player_group'
8
9
  require "acpc_poker_types/match_state"
9
10
  require "acpc_poker_types/pile_of_cards"
10
- require "acpc_poker_types/player"
11
11
  require "acpc_poker_types/rank"
12
12
  require "acpc_poker_types/suit"
13
13
  require "acpc_poker_types/acpc_dealer_data"
@@ -14,7 +14,7 @@ module AcpcPokerTypes::AcpcDealerData
14
14
  players = $2.split '|'
15
15
 
16
16
  players.each_index.inject({}) do |player_results, j|
17
- player_results[players[j].to_sym] = stack_changes[j].to_r
17
+ player_results[players[j].to_sym] = stack_changes[j].to_f
18
18
  player_results
19
19
  end
20
20
  else
@@ -31,7 +31,7 @@ module AcpcPokerTypes::AcpcDealerData
31
31
  players = $2.split '|'
32
32
 
33
33
  players.each_index.inject({}) do |player_results, j|
34
- player_results[players[j].to_sym] = stack_changes[j].to_r
34
+ player_results[players[j].to_sym] = stack_changes[j].to_f
35
35
  player_results
36
36
  end
37
37
  else
@@ -58,9 +58,9 @@ module AcpcPokerTypes::AcpcDealerData
58
58
 
59
59
  @data = acpc_log_statements.inject([]) do |accumulating_data, log_line|
60
60
  if @match_def.nil?
61
- @match_def = AcpcPokerTypes::AcpcDealerData::MatchDefinition.parse(log_line, player_names, game_def_directory)
61
+ @match_def = AcpcPokerTypes::AcpcDealerData::MatchDefinition.parse(log_line, player_names, game_def_directory)
62
62
  else
63
- parsed_message = AcpcPokerTypes::AcpcDealerData::HandResults.parse_state(log_line)
63
+ parsed_message = AcpcPokerTypes::AcpcDealerData::HandResults.parse_state(log_line)
64
64
  if parsed_message
65
65
  # Yes, this causes one more result to be parsed than is saved as long as
66
66
  # the number of hands is less than the total number in the log, but this
@@ -68,7 +68,7 @@ module AcpcPokerTypes::AcpcDealerData
68
68
  break accumulating_data if accumulating_data.length == num_hands
69
69
  accumulating_data << parsed_message
70
70
  else
71
- @final_score = AcpcPokerTypes::AcpcDealerData::HandResults.parse_score(log_line) unless @final_score
71
+ @final_score = AcpcPokerTypes::AcpcDealerData::HandResults.parse_score(log_line) unless @final_score
72
72
  end
73
73
  end
74
74
 
@@ -1,6 +1,3 @@
1
-
2
- require 'acpc_poker_types/player'
3
-
4
1
  require 'celluloid/autostart'
5
2
 
6
3
  require 'acpc_poker_types/acpc_dealer_data/action_messages'
@@ -11,404 +8,374 @@ require 'acpc_poker_types/acpc_dealer_data/match_definition'
11
8
  require 'contextual_exceptions'
12
9
  using ContextualExceptions::ClassRefinement
13
10
 
14
- module AcpcPokerTypes::AcpcDealerData
15
- class PokerMatchData
16
-
17
- exceptions :match_definitions_do_not_match, :final_scores_do_not_match, :data_inconsistent, :names_do_not_match
18
-
19
- attr_accessor(
20
- # @returns [Array<Numeric>] Chip distribution at the end of the match
21
- :chip_distribution,
22
- # @returns [MatchDefinition] Game definition and match parameters
23
- :match_def,
24
- # @returns [Integer] Zero-index turn number within the hand
25
- :hand_number,
26
- # @returns [ AcpcPokerTypes::AcpcDealerData::HandData] Data from each hand
27
- :data,
28
- # @returns [Array<AcpcPokerTypes::>] AcpcPokerTypes:: information
29
- :players,
30
- # @returns [Integer] Seat of the active player
31
- :seat
32
- )
33
-
34
- # @returns [ AcpcPokerTypes::AcpcDealerData::PokerMatchData]
35
- def self.parse_files(
36
- action_messages_file,
37
- result_messages_file,
38
- player_names,
39
- dealer_directory,
40
- num_hands=nil
41
- )
42
- parsed_action_messages = Celluloid::Future.new do
43
- AcpcPokerTypes::AcpcDealerData::ActionMessages.parse_file(
44
- action_messages_file,
45
- player_names,
46
- dealer_directory,
47
- num_hands
48
- )
49
- end
50
- parsed_hand_results = Celluloid::Future.new do
51
- AcpcPokerTypes::AcpcDealerData::HandResults.parse_file(
52
- result_messages_file,
53
- player_names,
54
- dealer_directory,
55
- num_hands
56
- )
57
- end
58
-
59
- new(
60
- parsed_action_messages.value,
61
- parsed_hand_results.value,
11
+ module AcpcPokerTypes
12
+ module AcpcDealerData
13
+
14
+ class PokerMatchData
15
+ exceptions :match_definitions_do_not_match, :final_scores_do_not_match, :data_inconsistent, :names_do_not_match
16
+
17
+ Player = Struct.new(:name, :seat, :balance)
18
+
19
+ attr_accessor(
20
+ # @returns [Array<Numeric>] Chip distribution at the end of the match
21
+ :chip_distribution,
22
+ # @returns [MatchDefinition] Game definition and match parameters
23
+ :match_def,
24
+ # @returns [Integer] Zero-index turn number within the hand
25
+ :hand_number,
26
+ # @returns [AcpcDealerData::HandData] Data from each hand
27
+ :data,
28
+ # @returns [Array<AcpcDealerData::PokerMatchData::Player>]
29
+ :players,
30
+ # @returns [Integer] Seat of the active player
31
+ :seat
32
+ )
33
+
34
+ # @returns [AcpcDealerData::PokerMatchData]
35
+ def self.parse_files(
36
+ action_messages_file,
37
+ result_messages_file,
38
+ player_names,
39
+ dealer_directory,
40
+ num_hands=nil
41
+ )
42
+ parsed_action_messages = Celluloid::Future.new do
43
+ AcpcDealerData::ActionMessages.parse_file(
44
+ action_messages_file,
62
45
  player_names,
63
- dealer_directory
46
+ dealer_directory,
47
+ num_hands
48
+ )
49
+ end
50
+ parsed_hand_results = Celluloid::Future.new do
51
+ AcpcDealerData::HandResults.parse_file(
52
+ result_messages_file,
53
+ player_names,
54
+ dealer_directory,
55
+ num_hands
64
56
  )
65
57
  end
66
58
 
67
- # @returns [ AcpcPokerTypes::AcpcDealerData::PokerMatchData]
68
- def self.parse(
69
- action_messages,
70
- result_messages,
59
+ new(
60
+ parsed_action_messages.value,
61
+ parsed_hand_results.value,
71
62
  player_names,
72
- dealer_directory,
73
- num_hands=nil
63
+ dealer_directory
74
64
  )
75
- parsed_action_messages = Celluloid::Future.new do
76
- AcpcPokerTypes::AcpcDealerData::ActionMessages.parse(
77
- action_messages,
78
- player_names,
79
- dealer_directory,
80
- num_hands
81
- )
82
- end
83
- parsed_hand_results = Celluloid::Future.new do
84
- AcpcPokerTypes::AcpcDealerData::HandResults.parse(
85
- result_messages,
86
- player_names,
87
- dealer_directory,
88
- num_hands
89
- )
90
- end
65
+ end
91
66
 
92
- new(
93
- parsed_action_messages.value,
94
- parsed_hand_results.value,
67
+ # @returns [AcpcDealerData::PokerMatchData]
68
+ def self.parse(
69
+ action_messages,
70
+ result_messages,
71
+ player_names,
72
+ dealer_directory,
73
+ num_hands=nil
74
+ )
75
+ parsed_action_messages = Celluloid::Future.new do
76
+ AcpcDealerData::ActionMessages.parse(
77
+ action_messages,
78
+ player_names,
79
+ dealer_directory,
80
+ num_hands
81
+ )
82
+ end
83
+ parsed_hand_results = Celluloid::Future.new do
84
+ AcpcDealerData::HandResults.parse(
85
+ result_messages,
95
86
  player_names,
96
- dealer_directory
87
+ dealer_directory,
88
+ num_hands
97
89
  )
98
90
  end
99
91
 
100
- def initialize(
101
- parsed_action_messages,
102
- parsed_hand_results,
92
+ new(
93
+ parsed_action_messages.value,
94
+ parsed_hand_results.value,
103
95
  player_names,
104
96
  dealer_directory
105
97
  )
106
- if (
107
- parsed_action_messages.match_def.nil? ||
108
- parsed_hand_results.match_def.nil? ||
109
- parsed_action_messages.match_def != parsed_hand_results.match_def
110
- )
111
- raise MatchDefinitionsDoNotMatch
112
- end
98
+ end
113
99
 
114
- if parsed_action_messages.final_score != parsed_hand_results.final_score
115
- raise FinalScoresDoNotMatch
116
- end
100
+ def initialize(
101
+ parsed_action_messages,
102
+ parsed_hand_results,
103
+ player_names,
104
+ dealer_directory
105
+ )
106
+ if (
107
+ parsed_action_messages.match_def.nil? ||
108
+ parsed_hand_results.match_def.nil? ||
109
+ parsed_action_messages.match_def != parsed_hand_results.match_def
110
+ )
111
+ raise MatchDefinitionsDoNotMatch
112
+ end
117
113
 
118
- @match_def = parsed_hand_results.match_def
114
+ if parsed_action_messages.final_score != parsed_hand_results.final_score
115
+ raise FinalScoresDoNotMatch
116
+ end
119
117
 
120
- if parsed_hand_results.final_score
121
- set_chip_distribution! parsed_hand_results.final_score
122
- end
118
+ @match_def = parsed_hand_results.match_def
123
119
 
124
- set_data! parsed_action_messages, parsed_hand_results
120
+ if parsed_hand_results.final_score
121
+ set_chip_distribution! parsed_hand_results.final_score
122
+ end
125
123
 
126
- # Zero-indexed seat
127
- @seat = 0
124
+ set_data! parsed_action_messages, parsed_hand_results
128
125
 
129
- initialize_players!
130
- end
126
+ # Zero-indexed seat
127
+ @seat = 0
131
128
 
132
- def for_every_seat!
133
- match_def.game_def.number_of_players.times do |seat|
134
- @seat = seat
129
+ initialize_players!
130
+ end
135
131
 
136
- initialize_players!
132
+ def for_every_seat!
133
+ match_def.game_def.number_of_players.times do |seat|
134
+ @seat = seat
137
135
 
138
- yield seat
139
- end
136
+ initialize_players!
140
137
 
141
- self
138
+ yield seat
142
139
  end
143
140
 
144
- def player(seat=@seat) @players[seat] end
141
+ self
142
+ end
145
143
 
146
- def next_hand!
147
- init_or_increment_hand_num!
148
- provide_players_with_new_hand!
149
- current_hand.start_hand! @seat
150
- end
144
+ def player(seat=@seat) @players[seat] end
151
145
 
152
- def end_match!
153
- if @chip_distribution && @chip_distribution != @players.map { |p| p.chip_balance }
154
- raise DataInconsistent, "chip distribution: #{@chip_distribution}, player balances: #{@players.map { |p| p.chip_balance }}"
155
- end
146
+ def next_hand!
147
+ init_or_increment_hand_num!
148
+ current_hand.start_hand! @seat
156
149
 
157
- @hand_number = nil
158
- self
150
+ self
151
+ end
152
+
153
+ def end_hand!
154
+ @players.each do |plyr|
155
+ plyr.balance += hand_player(plyr).balance
159
156
  end
157
+ current_hand.end_hand!
160
158
 
161
- def for_every_hand!
162
- while @hand_number.nil? || (@hand_number < @data.length - 1) do
163
- next_hand!
164
- yield @hand_number
165
- current_hand.end_hand!
166
- end
159
+ self
160
+ end
167
161
 
168
- end_match!
162
+ def end_match!
163
+ player_balances = @players.map { |plyr| plyr.balance }
164
+ if @chip_distribution && @chip_distribution != player_balances
165
+ raise DataInconsistent, "chip distribution: #{@chip_distribution}, player balances: #{player_balances}"
169
166
  end
170
167
 
171
- def next_turn!
172
- current_hand.next_turn!
168
+ @hand_number = nil
169
+ self
170
+ end
173
171
 
174
- @players.each_with_index do |player, seat|
175
- last_match_state = current_hand.last_match_state(seat)
176
- match_state = current_hand.current_match_state(seat)
172
+ def hand_player_balances
173
+ return [0] * match_def.game_def.number_of_players unless current_hand && current_hand.current_match_state
177
174
 
178
- if current_hand.last_action && player.seat == current_hand.last_action.seat
175
+ @players.map { |p| hand_player(p).balance }
176
+ end
179
177
 
180
- player.take_action!(current_hand.last_action.action)
181
- end
178
+ def hand_player(plyr = player)
179
+ return nil unless current_hand && current_hand.current_match_state
182
180
 
183
- if (
184
- player.active? &&
185
- !match_state.first_state_of_first_round? &&
186
- match_state.round > last_match_state.round
187
- )
188
- player.start_new_round!
189
- end
190
-
191
- if current_hand.final_turn?
192
- player.take_winnings!(
193
- current_hand.chip_distribution[seat] + @match_def.game_def.blinds[current_hand.current_match_state(seat).position_relative_to_dealer]
194
- )
195
- end
196
- end
197
- self
181
+ current_hand.current_match_state.players(match_def.game_def)[position_relative_to_dealer(plyr)]
182
+ end
183
+
184
+ def for_every_hand!
185
+ while @hand_number.nil? || (@hand_number < @data.length - 1) do
186
+ next_hand!
187
+ yield @hand_number
188
+ end_hand!
198
189
  end
199
190
 
200
- def for_every_turn!
201
- while current_hand.turn_number.nil? || (current_hand.turn_number < current_hand.data.length - 1) do
202
- next_turn!
203
- yield current_hand.turn_number
204
- end
191
+ end_match!
192
+ end
205
193
 
206
- self
207
- end
194
+ def next_turn!
195
+ current_hand.next_turn!
208
196
 
209
- def match_has_another_round?(current_round, turn_index, turns_taken)
210
- new_round?(current_round, turn_index) ||
211
- players_all_in?(current_round, turn_index, turns_taken)
197
+ @players.each_with_index do |player, seat|
198
+ last_match_state = current_hand.last_match_state(seat)
199
+ match_state = current_hand.current_match_state(seat)
212
200
  end
213
201
 
214
- def hand_started?
215
- @hand_number &&
216
- current_hand.turn_number &&
217
- current_hand.turn_number > 0
202
+ self
203
+ end
204
+
205
+ def for_every_turn!
206
+ while current_hand.turn_number.nil? || (current_hand.turn_number < current_hand.data.length - 1) do
207
+ next_turn!
208
+ yield current_hand.turn_number
218
209
  end
219
210
 
220
- def player_acting_sequence
221
- sequence = [[]]
211
+ self
212
+ end
222
213
 
223
- return sequence unless hand_started?
214
+ def match_has_another_round?(current_round, turn_index, turns_taken)
215
+ new_round?(current_round, turn_index) ||
216
+ players_all_in?(current_round, turn_index, turns_taken)
217
+ end
224
218
 
225
- turns_taken = current_hand.data[0..current_hand.turn_number-1]
226
- turns_taken.each_with_index do |turn, turn_index|
227
- next unless turn.action_message
219
+ def hand_started?
220
+ @hand_number &&
221
+ current_hand.turn_number &&
222
+ current_hand.turn_number > 0
223
+ end
228
224
 
229
- sequence[turn.action_message.state.round] << turn.action_message.seat
230
- if match_has_another_round?(sequence.length - 1, turn_index, turns_taken)
231
- sequence << []
232
- end
233
- end
225
+ def player_acting_sequence
226
+ sequence = [[]]
234
227
 
235
- sequence
236
- end
228
+ return sequence unless hand_started?
237
229
 
238
- def current_hand
239
- if @hand_number then @data[@hand_number] else nil end
240
- end
230
+ turns_taken = current_hand.data[0..current_hand.turn_number-1]
231
+ turns_taken.each_with_index do |turn, turn_index|
232
+ next unless turn.action_message
241
233
 
242
- def final_hand?
243
- if @hand_number then @hand_number >= @data.length - 1 else nil end
234
+ sequence[turn.action_message.state.round] << turn.action_message.seat
235
+ if match_has_another_round?(sequence.length - 1, turn_index, turns_taken)
236
+ sequence << []
237
+ end
244
238
  end
245
239
 
246
- # @return [Array<ChipStack>] AcpcPokerTypes:: stacks.
247
- def chip_stacks
248
- @players.map { |player| player.chip_stack }
249
- end
240
+ sequence
241
+ end
250
242
 
251
- # return [Array<Integer>] Each player's current chip balance.
252
- def chip_balances
253
- @players.map { |player| player.chip_balance }
254
- end
243
+ def current_hand
244
+ if @hand_number then @data[@hand_number] else nil end
245
+ end
255
246
 
256
- # return [Array<Array<Integer>>] Each player's current chip contribution organized by round.
257
- def chip_contributions
258
- @players.map { |player| player.chip_contributions }
259
- end
247
+ def final_hand?
248
+ if @hand_number then @hand_number >= @data.length - 1 else nil end
249
+ end
260
250
 
261
- def opponents
262
- @players.reject { |other_player| player == other_player }
263
- end
264
- def active_players
265
- @players.select { |player_to_collect| player_to_collect.active? }
266
- end
267
- def non_folded_players
268
- @players.reject { |player_to_reject| player_to_reject.folded? }
269
- end
270
- def opponents_cards_visible?
271
- return false unless current_hand
251
+ # return [Array<Integer>] Each player's current chip balance.
252
+ def balances
253
+ @players.map { |player| player.balance }
254
+ end
272
255
 
273
- current_hand.current_match_state.list_of_hole_card_hands.reject_empty_elements.length > 1
274
- end
275
- def player_with_dealer_button
276
- return nil unless current_hand
256
+ def opponents_cards_visible?
257
+ return false unless current_hand
277
258
 
278
- @players.find do |plr|
279
- current_hand.current_match_state(plr.seat).position_relative_to_dealer == @players.length - 1
280
- end
281
- end
282
- # @return [Hash<AcpcPokerTypes::, #to_i] Relation from player to the blind that player paid.
283
- def player_blind_relation
284
- return nil unless current_hand
259
+ current_hand.current_match_state.opponents_cards_visible?
260
+ end
261
+ def player_with_dealer_button
262
+ return nil unless current_hand
285
263
 
286
- @players.inject({}) do |relation, plr|
287
- relation[plr] = @match_def.game_def.blinds[current_hand.current_match_state(plr.seat).position_relative_to_dealer]
288
- relation
289
- end
264
+ @players.find do |plr|
265
+ position_relative_to_dealer(plr) == @players.length - 1
290
266
  end
267
+ end
291
268
 
292
- # @todo Untested
293
- # @return [String] player acting sequence as a string.
294
- def player_acting_sequence_string
295
- (player_acting_sequence.map { |per_round| per_round.join('') }).join('/')
296
- end
297
- def users_turn_to_act?
298
- return false unless current_hand && current_hand.next_action
299
- current_hand.next_action.seat == @seat
269
+ def position_relative_to_dealer(plyr = player)
270
+ return nil unless current_hand && current_hand.current_match_state(plyr.seat)
271
+
272
+ current_hand.current_match_state(plyr.seat).position_relative_to_dealer
273
+ end
274
+
275
+ # @todo Untested
276
+ # @return [String] player acting sequence as a string.
277
+ def player_acting_sequence_string
278
+ (player_acting_sequence.map { |per_round| per_round.join('') }).join('/')
279
+ end
280
+ def users_turn_to_act?
281
+ return false unless current_hand && current_hand.next_action
282
+ current_hand.next_action.seat == @seat
283
+ end
284
+ def betting_sequence
285
+ sequence = [[]]
286
+
287
+ if (
288
+ @hand_number.nil? ||
289
+ current_hand.turn_number.nil? ||
290
+ current_hand.turn_number < 1
291
+ )
292
+ return sequence
300
293
  end
301
- def betting_sequence
302
- sequence = [[]]
294
+
295
+ turns_taken = current_hand.data[0..current_hand.turn_number-1]
296
+ turns_taken.each_with_index do |turn, turn_index|
297
+ next unless turn.action_message
298
+
299
+ sequence[turn.action_message.state.round] << turn.action_message.action
303
300
 
304
301
  if (
305
- @hand_number.nil? ||
306
- current_hand.turn_number.nil? ||
307
- current_hand.turn_number < 1
302
+ new_round?(sequence.length - 1 , turn_index) ||
303
+ players_all_in?(sequence.length - 1, turn_index, turns_taken)
308
304
  )
309
- return sequence
305
+ sequence << []
310
306
  end
307
+ end
311
308
 
312
- turns_taken = current_hand.data[0..current_hand.turn_number-1]
313
- turns_taken.each_with_index do |turn, turn_index|
314
- next unless turn.action_message
315
-
316
- sequence[turn.action_message.state.round] << turn.action_message.action
309
+ sequence
310
+ end
311
+ def betting_sequence_string
312
+ (betting_sequence.map do |per_round|
313
+ (per_round.map{|action| action.to_acpc}).join('')
314
+ end).join('/')
315
+ end
317
316
 
318
- if (
319
- new_round?(sequence.length - 1 , turn_index) ||
320
- players_all_in?(sequence.length - 1, turn_index, turns_taken)
321
- )
322
- sequence << []
323
- end
324
- end
317
+ protected
325
318
 
326
- sequence
327
- end
328
- def betting_sequence_string
329
- (betting_sequence.map do |per_round|
330
- (per_round.map{|action| action.to_acpc}).join('')
331
- end).join('/')
332
- end
333
- # @todo Test and implement this
334
- # def min_wager
335
- # return nil unless current_hand
336
-
337
- # @match_def.game_def.min_wagers[current_hand.next_state.round]
338
- # ChipStack.new [@min_wager.to_i, action_with_context.cost.to_i].max
339
- # end
340
-
341
- protected
342
-
343
- def initialize_players!
344
- @players = @match_def.player_names.length.times.map do |seat|
345
- AcpcPokerTypes::Player.join_match(
346
- @match_def.player_names[seat],
347
- AcpcPokerTypes::Seat.new(seat, @match_def.player_names.length),
348
- @match_def.game_def.chip_stacks[seat]
349
- )
350
- end
351
- self
319
+ def initialize_players!
320
+ @players = @match_def.player_names.length.times.map do |seat|
321
+ Player.new(
322
+ @match_def.player_names[seat],
323
+ Seat.new(seat, @match_def.player_names.length),
324
+ 0
325
+ )
352
326
  end
327
+ self
328
+ end
353
329
 
354
- def set_chip_distribution!(final_score)
355
- @chip_distribution = []
356
- final_score.each do |player_name, amount|
357
- begin
358
- @chip_distribution[@match_def.player_names.index(player_name.to_s)] = amount
359
- rescue TypeError => e
360
- raise NamesDoNotMatch.with_context(
361
- "Player name \"#{player_name.to_s}\" in match definition is not listed in final chip distribution",
362
- e
363
- )
364
- end
330
+ def set_chip_distribution!(final_score)
331
+ @chip_distribution = []
332
+ final_score.each do |player_name, amount|
333
+ begin
334
+ @chip_distribution[@match_def.player_names.index(player_name.to_s)] = amount
335
+ rescue TypeError => e
336
+ raise NamesDoNotMatch.with_context(
337
+ "Player name \"#{player_name.to_s}\" in match definition is not listed in final chip distribution",
338
+ e
339
+ )
365
340
  end
366
- self
367
341
  end
342
+ self
343
+ end
368
344
 
369
- def set_data!(parsed_action_messages, parsed_hand_results)
370
- @data = []
371
- parsed_action_messages.data.zip(parsed_hand_results.data).each do |action_messages_by_hand, hand_result|
372
- @data << AcpcPokerTypes::AcpcDealerData::HandData.new(
373
- @match_def,
374
- action_messages_by_hand,
375
- hand_result
376
- )
377
- end
378
- self
345
+ def set_data!(parsed_action_messages, parsed_hand_results)
346
+ @data = []
347
+ parsed_action_messages.data.zip(parsed_hand_results.data).each do |action_messages_by_hand, hand_result|
348
+ @data << AcpcDealerData::HandData.new(
349
+ @match_def,
350
+ action_messages_by_hand,
351
+ hand_result
352
+ )
379
353
  end
354
+ self
355
+ end
380
356
 
381
- private
357
+ private
382
358
 
383
- def players_all_in?(current_round, turn_index, turns_taken)
384
- current_hand.data.length == turn_index + 2 &&
385
- current_round < (@match_def.game_def.number_of_rounds - 1) &&
386
- (turns_taken[0..turn_index].count do |t|
387
- t.action_message.action.to_acpc_character == AcpcPokerTypes::PokerAction::FOLD
388
- end) != @players.length - 1
389
- end
390
- def new_round?(current_round, turn_index)
391
- current_hand.data.length > turn_index + 1 &&
392
- current_hand.data[turn_index + 1].action_message &&
393
- current_hand.data[turn_index + 1].action_message.state.round > current_round
394
- end
395
- def provide_players_with_new_hand!
396
- @players.each_with_index do |player, seat|
397
- player.start_new_hand!(
398
- @match_def.game_def.blinds[current_hand.data.first.state_messages[seat].position_relative_to_dealer],
399
- @match_def.game_def.chip_stacks[current_hand.data.first.state_messages[seat].position_relative_to_dealer],
400
- current_hand.data.first.state_messages[seat].users_hole_cards
401
- )
402
- end
403
- self
404
- end
405
- def init_or_increment_hand_num!
406
- if @hand_number
407
- @hand_number += 1
408
- else
409
- @hand_number = 0
410
- end
411
- self
359
+ def players_all_in?(current_round, turn_index, turns_taken)
360
+ current_hand.data.length == turn_index + 2 &&
361
+ current_round < (@match_def.game_def.number_of_rounds - 1) &&
362
+ (turns_taken[0..turn_index].count do |t|
363
+ t.action_message.action.to_acpc_character == PokerAction::FOLD
364
+ end) != @players.length - 1
365
+ end
366
+ def new_round?(current_round, turn_index)
367
+ current_hand.data.length > turn_index + 1 &&
368
+ current_hand.data[turn_index + 1].action_message &&
369
+ current_hand.data[turn_index + 1].action_message.state.round > current_round
370
+ end
371
+ def init_or_increment_hand_num!
372
+ if @hand_number
373
+ @hand_number += 1
374
+ else
375
+ @hand_number = 0
412
376
  end
377
+ self
413
378
  end
379
+ end
380
+ end
414
381
  end