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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/acpc_poker_types.gemspec +3 -2
- data/lib/acpc_poker_types.rb +1 -1
- data/lib/acpc_poker_types/acpc_dealer_data/hand_results.rb +5 -5
- data/lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb +290 -323
- data/lib/acpc_poker_types/game_definition.rb +54 -37
- data/lib/acpc_poker_types/hand_player.rb +119 -0
- data/lib/acpc_poker_types/match_state.rb +323 -204
- data/lib/acpc_poker_types/player_group.rb +62 -0
- data/lib/acpc_poker_types/poker_action.rb +13 -6
- data/lib/acpc_poker_types/version.rb +1 -1
- data/spec/game_definition_spec.rb +23 -4
- data/spec/hand_player_spec.rb +254 -0
- data/spec/match_state_spec.rb +655 -112
- data/spec/player_group_spec.rb +57 -0
- data/spec/poker_match_data_spec.rb +24 -21
- data/spec/support/spec_helper.rb +2 -16
- metadata +68 -148
- data/lib/acpc_poker_types/player.rb +0 -182
- data/spec/coverage/assets/0.7.1/application.css +0 -1110
- data/spec/coverage/assets/0.7.1/application.js +0 -626
- data/spec/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
- data/spec/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
- data/spec/coverage/assets/0.7.1/favicon_green.png +0 -0
- data/spec/coverage/assets/0.7.1/favicon_red.png +0 -0
- data/spec/coverage/assets/0.7.1/favicon_yellow.png +0 -0
- data/spec/coverage/assets/0.7.1/loading.gif +0 -0
- data/spec/coverage/assets/0.7.1/magnify.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/coverage/index.html +0 -72
- data/spec/match_state_perf.rb +0 -14
- data/spec/player_spec.rb +0 -372
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3381e33e9879dcca0d128817498cb80ef96155f7
|
4
|
+
data.tar.gz: f1a3fd8a83746913f6a395d715fa5aaa1c085529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cd00ac46a327928b2bee5e2a92c87001ff01f3d0e8afe9c3ab6792d4f72cc1651322fcd0dc485b2691286858461c2135015dd743c9cd439e96410a0da6d11b1
|
7
|
+
data.tar.gz: abee379aa7a779b73b344997bba3fb036852211493f3abcc72fb4fa528d2f2e1518bdd40cf2ce0cd81a16f6ac16e651dcc85c3488b7c4bd0a7b4e5d119defaaa
|
data/Rakefile
CHANGED
data/acpc_poker_types.gemspec
CHANGED
@@ -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 '
|
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
|
data/lib/acpc_poker_types.rb
CHANGED
@@ -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].
|
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].
|
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 =
|
61
|
+
@match_def = AcpcPokerTypes::AcpcDealerData::MatchDefinition.parse(log_line, player_names, game_def_directory)
|
62
62
|
else
|
63
|
-
parsed_message =
|
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 =
|
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
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
114
|
+
if parsed_action_messages.final_score != parsed_hand_results.final_score
|
115
|
+
raise FinalScoresDoNotMatch
|
116
|
+
end
|
119
117
|
|
120
|
-
|
121
|
-
set_chip_distribution! parsed_hand_results.final_score
|
122
|
-
end
|
118
|
+
@match_def = parsed_hand_results.match_def
|
123
119
|
|
124
|
-
|
120
|
+
if parsed_hand_results.final_score
|
121
|
+
set_chip_distribution! parsed_hand_results.final_score
|
122
|
+
end
|
125
123
|
|
126
|
-
|
127
|
-
@seat = 0
|
124
|
+
set_data! parsed_action_messages, parsed_hand_results
|
128
125
|
|
129
|
-
|
130
|
-
|
126
|
+
# Zero-indexed seat
|
127
|
+
@seat = 0
|
131
128
|
|
132
|
-
|
133
|
-
|
134
|
-
@seat = seat
|
129
|
+
initialize_players!
|
130
|
+
end
|
135
131
|
|
136
|
-
|
132
|
+
def for_every_seat!
|
133
|
+
match_def.game_def.number_of_players.times do |seat|
|
134
|
+
@seat = seat
|
137
135
|
|
138
|
-
|
139
|
-
end
|
136
|
+
initialize_players!
|
140
137
|
|
141
|
-
|
138
|
+
yield seat
|
142
139
|
end
|
143
140
|
|
144
|
-
|
141
|
+
self
|
142
|
+
end
|
145
143
|
|
146
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
146
|
+
def next_hand!
|
147
|
+
init_or_increment_hand_num!
|
148
|
+
current_hand.start_hand! @seat
|
156
149
|
|
157
|
-
|
158
|
-
|
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
|
-
|
162
|
-
|
163
|
-
next_hand!
|
164
|
-
yield @hand_number
|
165
|
-
current_hand.end_hand!
|
166
|
-
end
|
159
|
+
self
|
160
|
+
end
|
167
161
|
|
168
|
-
|
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
|
-
|
172
|
-
|
168
|
+
@hand_number = nil
|
169
|
+
self
|
170
|
+
end
|
173
171
|
|
174
|
-
|
175
|
-
|
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
|
-
|
175
|
+
@players.map { |p| hand_player(p).balance }
|
176
|
+
end
|
179
177
|
|
180
|
-
|
181
|
-
|
178
|
+
def hand_player(plyr = player)
|
179
|
+
return nil unless current_hand && current_hand.current_match_state
|
182
180
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
201
|
-
|
202
|
-
next_turn!
|
203
|
-
yield current_hand.turn_number
|
204
|
-
end
|
191
|
+
end_match!
|
192
|
+
end
|
205
193
|
|
206
|
-
|
207
|
-
|
194
|
+
def next_turn!
|
195
|
+
current_hand.next_turn!
|
208
196
|
|
209
|
-
|
210
|
-
|
211
|
-
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
221
|
-
|
211
|
+
self
|
212
|
+
end
|
222
213
|
|
223
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
219
|
+
def hand_started?
|
220
|
+
@hand_number &&
|
221
|
+
current_hand.turn_number &&
|
222
|
+
current_hand.turn_number > 0
|
223
|
+
end
|
228
224
|
|
229
|
-
|
230
|
-
|
231
|
-
sequence << []
|
232
|
-
end
|
233
|
-
end
|
225
|
+
def player_acting_sequence
|
226
|
+
sequence = [[]]
|
234
227
|
|
235
|
-
|
236
|
-
end
|
228
|
+
return sequence unless hand_started?
|
237
229
|
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
-
|
243
|
-
if
|
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
|
-
|
247
|
-
|
248
|
-
@players.map { |player| player.chip_stack }
|
249
|
-
end
|
240
|
+
sequence
|
241
|
+
end
|
250
242
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
243
|
+
def current_hand
|
244
|
+
if @hand_number then @data[@hand_number] else nil end
|
245
|
+
end
|
255
246
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
247
|
+
def final_hand?
|
248
|
+
if @hand_number then @hand_number >= @data.length - 1 else nil end
|
249
|
+
end
|
260
250
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
-
|
274
|
-
|
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
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
287
|
-
|
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
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
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
|
-
|
302
|
-
|
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
|
-
|
306
|
-
|
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
|
-
|
305
|
+
sequence << []
|
310
306
|
end
|
307
|
+
end
|
311
308
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
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
|
-
|
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
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
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
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
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
|
-
|
357
|
+
private
|
382
358
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
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
|