acpc_poker_types 7.1.4 → 7.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab072498a35c8b53f0602dd0a49453b0f33ae6cd
4
- data.tar.gz: 3cfc75533ff01304b4198c521e50deb79139007a
3
+ metadata.gz: 0f33148cb5695cca1690278ba5acc735404dc15f
4
+ data.tar.gz: 7007a378e311daa494788d1c5d2355b965ec00b9
5
5
  SHA512:
6
- metadata.gz: 0366232bc2cab9bf7b26e5519f39163aee7ef1d81ef82b9f8f7ef0306a01e1b1aa2ccbe58a27737a2f6b4bcef762391430d12fba962c09c38e5bd293bfc6eef0
7
- data.tar.gz: 1579a92a852dff1a767e8081838e6ff9814a9ea37dae4eefaa7ef3d175cf67dc94de6a5ce5680bc056ebaf53048210b3de0b84065a39be9653615eef9712fdfa
6
+ metadata.gz: 39b67ec1ac2532478e08cf4c26c8e51e990302b22b6c2826d428b4776ff0d6237b25463b11972044c566c108f449994cc0c447d6b4889809d7ca46ce0228c144
7
+ data.tar.gz: 2c2ccfc8eaba441ef3bc615005dd3f5c2d30cd69680eda6f0b071582706b6bec9be3aa572b5015e3951b2cdc2d1dd37a5f77327a1a715fb3d07511a30ca42be3
@@ -50,9 +50,16 @@ class HandPlayer
50
50
  end
51
51
 
52
52
  def contributions
53
- @actions.map do |actions_per_round|
53
+ contribution_list = @actions.map do |actions_per_round|
54
54
  actions_per_round.inject(0) { |sum, action| sum += action.cost }
55
- end.unshift @ante
55
+ end
56
+ if contribution_list.empty?
57
+ contribution_list << @ante
58
+ else
59
+ contribution_list[0] += @ante
60
+ end
61
+
62
+ contribution_list
56
63
  end
57
64
 
58
65
  def total_contribution
@@ -64,7 +71,7 @@ class HandPlayer
64
71
  # @return [Array<PokerAction>] The list of legal actions for this player. If a wager is legal,
65
72
  # the largest possible wager will be returned in the list.
66
73
  def legal_actions(
67
- round: round,
74
+ in_round: round,
68
75
  amount_to_call: ChipStack.new(0),
69
76
  wager_illegal: false
70
77
  )
@@ -72,12 +79,19 @@ class HandPlayer
72
79
  return l_actions if inactive?
73
80
 
74
81
  if amount_to_call.to_r > 0
75
- l_actions << PokerAction.new(PokerAction::CALL, cost: amount_to_call) << PokerAction.new(PokerAction::FOLD)
82
+ l_actions << PokerAction.new(PokerAction::CALL, cost: amount_to_call)
83
+ l_actions << PokerAction.new(PokerAction::FOLD)
76
84
  else
77
85
  l_actions << PokerAction.new(PokerAction::CHECK)
78
86
  end
79
87
  if !wager_illegal && stack > amount_to_call.to_r
80
- l_actions << if contributions[round] > 0 || amount_to_call.to_r > 0
88
+ l_actions << if (
89
+ (contributions.length > in_round) &&
90
+ (
91
+ contributions[in_round] > 0 ||
92
+ amount_to_call.to_r > 0
93
+ )
94
+ )
81
95
  PokerAction.new(PokerAction::RAISE, cost: stack - amount_to_call.to_r)
82
96
  else
83
97
  PokerAction.new(PokerAction::BET, cost: stack - amount_to_call.to_r)
@@ -79,7 +79,7 @@ class HandPlayerGroup < DelegateClass(Array)
79
79
  # @return [Array<PokerAction>] The legal actions for the next player to act.
80
80
  def legal_actions(acting_player_position, round, max_num_wagers)
81
81
  @players[acting_player_position].legal_actions(
82
- round: round,
82
+ in_round: round,
83
83
  amount_to_call: amount_to_call(acting_player_position),
84
84
  wager_illegal: num_wagers(round) >= max_num_wagers
85
85
  )
@@ -364,7 +364,13 @@ class MatchState < DelegateClass(String)
364
364
  game_def.min_wagers[current_round]
365
365
  )
366
366
 
367
- action = PokerAction.new(action.to_s, cost: cost) if cost > 0
367
+ action = PokerAction.new(
368
+ action.to_s(
369
+ pot_gained_chips: @players.inject(0) { |sum, player| sum += player.contributions[current_round].to_i } > 0,
370
+ player_sees_wager: @players.amount_to_call(acting_player_position) > 0
371
+ ),
372
+ cost: cost
373
+ )
368
374
 
369
375
  adjust_min_wager!(action, acting_player_position)
370
376
 
@@ -78,10 +78,11 @@ class PokerAction < DelegateClass(String)
78
78
  end
79
79
 
80
80
  # @return [String] String representation of this action.
81
- # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
81
+ # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action.
82
+ # Defaults to +pot_gained_chips?+.
82
83
  # @param player_sees_wager [Boolean] Whether or not the player is reacting to a wager.
83
- # Defaults to the value of +pot_gained_chips+.
84
- def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
84
+ # Defaults to the value of +player_sees_wager?+.
85
+ def to_s(pot_gained_chips: pot_gained_chips?, player_sees_wager: player_sees_wager?)
85
86
  combine_action_and_modifier(
86
87
  if @action == FOLD
87
88
  @action
@@ -102,6 +103,30 @@ class PokerAction < DelegateClass(String)
102
103
 
103
104
  private
104
105
 
106
+ def pot_gained_chips?
107
+ if @action == FOLD || @action == RAISE || @action == CALL
108
+ true
109
+ elsif @action == CHECK
110
+ # Could be true or false, but doesn't matter for the purpose of
111
+ # printing a check properly
112
+ nil
113
+ else
114
+ false
115
+ end
116
+ end
117
+
118
+ def player_sees_wager?
119
+ if @action == FOLD || @action == CALL
120
+ true
121
+ elsif @action == RAISE
122
+ # Could be true or false, but doesn't matter for the purpose of
123
+ # printing a raise properly
124
+ nil
125
+ else
126
+ false
127
+ end
128
+ end
129
+
105
130
  def combine_action_and_modifier(action=@action, modifier=@modifier)
106
131
  "#{action}#{modifier}"
107
132
  end
@@ -1,3 +1,3 @@
1
1
  module AcpcPokerTypes
2
- VERSION = '7.1.4'
2
+ VERSION = '7.1.5'
3
3
  end
@@ -44,9 +44,9 @@ describe HandPlayer do
44
44
  describe 'raises an exception if it is not active' do
45
45
  it 'if it has folded' do
46
46
  x_actions = [['c', 'r100'], ['r200', 'c'], ['f']]
47
- x_actions.each_with_index do |actions, round|
47
+ x_actions.each_with_index do |actions, in_round|
48
48
  actions.each do |action|
49
- patient.append_action! PokerAction.new(action), round
49
+ patient.append_action! PokerAction.new(action), in_round
50
50
  end
51
51
  end
52
52
 
@@ -63,9 +63,9 @@ describe HandPlayer do
63
63
  PokerAction.new('c', cost: INITIAL_CHIP_STACK - ANTE)
64
64
  ]
65
65
  ]
66
- x_actions.each_with_index do |actions, round|
66
+ x_actions.each_with_index do |actions, in_round|
67
67
  actions.each do |action|
68
- patient.append_action!(action, round)
68
+ patient.append_action!(action, in_round)
69
69
  end
70
70
  end
71
71
 
@@ -74,9 +74,9 @@ describe HandPlayer do
74
74
  end
75
75
  it 'works' do
76
76
  x_actions = [['c', 'r100'], ['r200', 'c'], ['f']]
77
- x_actions.each_with_index do |actions, round|
77
+ x_actions.each_with_index do |actions, in_round|
78
78
  actions.each do |action|
79
- patient.append_action! PokerAction.new(action), round
79
+ patient.append_action! PokerAction.new(action), in_round
80
80
  end
81
81
  end
82
82
 
@@ -86,9 +86,9 @@ describe HandPlayer do
86
86
  describe '#folded?' do
87
87
  it 'works' do
88
88
  x_actions = [['c', 'r100'], ['r200', 'c']]
89
- x_actions.each_with_index do |actions, round|
89
+ x_actions.each_with_index do |actions, in_round|
90
90
  actions.each do |action|
91
- patient.append_action!(PokerAction.new(action), round).folded?.must_equal false
91
+ patient.append_action!(PokerAction.new(action), in_round).folded?.must_equal false
92
92
  end
93
93
  end
94
94
 
@@ -106,9 +106,9 @@ describe HandPlayer do
106
106
  PokerAction.new('r400')
107
107
  ]
108
108
  ]
109
- x_actions.each_with_index do |actions, round|
109
+ x_actions.each_with_index do |actions, in_round|
110
110
  actions.each do |action|
111
- patient.append_action!(action, round).all_in?.must_equal false
111
+ patient.append_action!(action, in_round).all_in?.must_equal false
112
112
  end
113
113
  end
114
114
 
@@ -126,9 +126,9 @@ describe HandPlayer do
126
126
  PokerAction.new('r400')
127
127
  ]
128
128
  ]
129
- x_actions.each_with_index do |actions, round|
129
+ x_actions.each_with_index do |actions, in_round|
130
130
  actions.each do |action|
131
- patient.append_action!(action, round).inactive?.must_equal false
131
+ patient.append_action!(action, in_round).inactive?.must_equal false
132
132
  end
133
133
  end
134
134
 
@@ -144,9 +144,9 @@ describe HandPlayer do
144
144
  PokerAction.new('r400')
145
145
  ]
146
146
  ]
147
- x_actions.each_with_index do |actions, round|
147
+ x_actions.each_with_index do |actions, in_round|
148
148
  actions.each do |action|
149
- patient.append_action!(action, round).inactive?.must_equal false
149
+ patient.append_action!(action, in_round).inactive?.must_equal false
150
150
  end
151
151
  end
152
152
 
@@ -165,17 +165,18 @@ describe HandPlayer do
165
165
  PokerAction.new('c', cost: 0)
166
166
  ]
167
167
  ]
168
- x_actions.each_with_index do |actions, round|
168
+ x_actions.each_with_index do |actions, in_round|
169
169
  actions.each do |action|
170
- patient.append_action!(action, round)
170
+ patient.append_action!(action, in_round)
171
171
  end
172
172
  end
173
173
 
174
- patient.contributions.must_equal(
175
- x_actions.map do |actions|
176
- actions.inject(0) { |sum, action| sum += action.cost }
177
- end.unshift(ANTE)
178
- )
174
+ x_contributions = x_actions.map do |actions|
175
+ actions.inject(0) { |sum, action| sum += action.cost }
176
+ end
177
+ x_contributions[0] += ANTE
178
+
179
+ patient.contributions.must_equal(x_contributions)
179
180
  end
180
181
  end
181
182
  describe '#total_contribution' do
@@ -190,9 +191,9 @@ describe HandPlayer do
190
191
  PokerAction.new('c', cost: 0)
191
192
  ]
192
193
  ]
193
- x_actions.each_with_index do |actions, round|
194
+ x_actions.each_with_index do |actions, in_round|
194
195
  actions.each do |action|
195
- patient.append_action!(action, round)
196
+ patient.append_action!(action, in_round)
196
197
  end
197
198
  end
198
199
 
@@ -204,40 +205,40 @@ describe HandPlayer do
204
205
 
205
206
  describe '#legal_actions' do
206
207
  it 'works with fold' do
207
- patient.legal_actions(round: 0, amount_to_call: 100).sort.must_equal [
208
+ patient.legal_actions(in_round: 0, amount_to_call: 100).sort.must_equal [
208
209
  PokerAction.new(PokerAction::CALL),
209
210
  PokerAction.new(PokerAction::RAISE, cost: INITIAL_CHIP_STACK - (ANTE + 100)),
210
211
  PokerAction.new(PokerAction::FOLD)
211
212
  ].sort
212
213
  patient.append_action!(PokerAction.new('c', cost: 100))
213
- .legal_actions(round: 0, amount_to_call: 200).sort.must_equal [
214
+ .legal_actions(in_round: 0, amount_to_call: 200).sort.must_equal [
214
215
  PokerAction.new(PokerAction::CALL),
215
216
  PokerAction.new(PokerAction::RAISE, cost: INITIAL_CHIP_STACK - (ANTE + 200)),
216
217
  PokerAction.new(PokerAction::FOLD)
217
218
  ].sort
218
219
  patient.append_action!(PokerAction.new('f'))
219
- .legal_actions(round: 0).empty?.must_equal true
220
+ .legal_actions(in_round: 0).empty?.must_equal true
220
221
  end
221
222
  it 'works with all in' do
222
- patient.legal_actions(round: 0).sort.must_equal [
223
+ patient.legal_actions(in_round: 0).sort.must_equal [
223
224
  PokerAction.new(PokerAction::CHECK),
224
- PokerAction.new(PokerAction::BET, cost: INITIAL_CHIP_STACK - ANTE),
225
+ PokerAction.new(PokerAction::RAISE, cost: INITIAL_CHIP_STACK - ANTE),
225
226
  ].sort
226
227
  patient.append_action!(PokerAction.new('c', cost: 100))
227
- .legal_actions(round: 0).sort.must_equal [
228
+ .legal_actions(in_round: 0).sort.must_equal [
228
229
  PokerAction.new(PokerAction::CHECK),
229
- PokerAction.new(PokerAction::BET, cost: INITIAL_CHIP_STACK - (ANTE + 100)),
230
+ PokerAction.new(PokerAction::RAISE, cost: INITIAL_CHIP_STACK - (ANTE + 100)),
230
231
  ].sort
231
232
  patient.append_action!(PokerAction.new('c', cost: INITIAL_CHIP_STACK - (ANTE + 100)))
232
- .legal_actions(round: 0).empty?.must_equal true
233
+ .legal_actions(in_round: 0).empty?.must_equal true
233
234
  end
234
235
  it 'works when an opponent is all in' do
235
236
  patient.append_action!(PokerAction.new('c', cost: 100))
236
- .legal_actions(round: 0).sort.must_equal [
237
+ .legal_actions(in_round: 0).sort.must_equal [
237
238
  PokerAction.new(PokerAction::CHECK),
238
239
  PokerAction.new(PokerAction::RAISE, cost: INITIAL_CHIP_STACK - (ANTE + 100))
239
240
  ].sort
240
- patient.legal_actions(round: 0, amount_to_call: INITIAL_CHIP_STACK - (ANTE + 100))
241
+ patient.legal_actions(in_round: 0, amount_to_call: INITIAL_CHIP_STACK - (ANTE + 100))
241
242
  .sort.must_equal [
242
243
  PokerAction.new(PokerAction::CALL),
243
244
  PokerAction.new(PokerAction::FOLD)
@@ -245,16 +246,16 @@ describe HandPlayer do
245
246
  end
246
247
  it 'works when no more raises are allowed' do
247
248
  patient.append_action!(PokerAction.new('c', cost: 100))
248
- .legal_actions(round: 0, wager_illegal: true).must_equal [
249
+ .legal_actions(in_round: 0, wager_illegal: true).must_equal [
249
250
  PokerAction.new(PokerAction::CHECK)
250
251
  ]
251
- patient.legal_actions(round: 0, amount_to_call: INITIAL_CHIP_STACK - (ANTE + 100))
252
+ patient.legal_actions(in_round: 0, amount_to_call: INITIAL_CHIP_STACK - (ANTE + 100))
252
253
  .sort.must_equal [
253
254
  PokerAction.new(PokerAction::CALL),
254
255
  PokerAction.new(PokerAction::FOLD)
255
256
  ].sort
256
257
  end
257
- it 'works without round argument' do
258
+ it 'works without in_round argument' do
258
259
  patient.append_action!(PokerAction.new('c', cost: 100))
259
260
  .legal_actions(wager_illegal: true).must_equal [
260
261
  PokerAction.new(PokerAction::CHECK)
@@ -479,9 +479,11 @@ describe MatchState do
479
479
  ]
480
480
  ]
481
481
  x_contributions = x_actions.map_with_index do |actions_per_player, i|
482
- actions_per_player.map do |actions_per_round|
482
+ player_contribs = actions_per_player.map do |actions_per_round|
483
483
  actions_per_round.inject(0) { |sum, action| sum += action.cost }
484
- end.unshift(x_game_def.blinds[i])
484
+ end
485
+ player_contribs[0] += x_game_def.blinds[i]
486
+ player_contribs
485
487
  end
486
488
  x_winnings = [0, 0, x_contributions.flatten.inject(:+)]
487
489
  x_stacks = x_game_def.chip_stacks.map_with_index do |chip_stack, i|
@@ -897,6 +899,16 @@ describe MatchState do
897
899
  PokerAction.new(PokerAction::BET, cost: game_definition.min_wagers[1])
898
900
  ]
899
901
  end
902
+ it 'should work properly when a new round begins and the other players check' do
903
+ game_definition = GameDefinition.parse_file(AcpcDealer::GAME_DEFINITION_FILE_PATHS[2][:limit])
904
+
905
+ MatchState.parse("MATCHSTATE:1:0:cc/rrrrc/rrc/c:|2hQc/QhQsJs/2s/Kh").legal_actions(
906
+ game_definition
907
+ ).must_equal [
908
+ PokerAction.new(PokerAction::CHECK, cost: 0),
909
+ PokerAction.new(PokerAction::BET, cost: game_definition.min_wagers[3])
910
+ ]
911
+ end
900
912
  end
901
913
  end
902
914
 
@@ -64,22 +64,9 @@ describe AcpcPokerTypes::PokerAction do
64
64
  end
65
65
  end
66
66
  describe '#to_s' do
67
- it "prints in the dealer's canonical representation by default" do
67
+ it "prints in the given format by default" do
68
68
  AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
69
- AcpcPokerTypes::PokerAction.new(a).to_s.must_equal (
70
- case a
71
- when AcpcPokerTypes::PokerAction::BET
72
- AcpcPokerTypes::PokerAction::RAISE
73
- when AcpcPokerTypes::PokerAction::CALL
74
- AcpcPokerTypes::PokerAction::CALL
75
- when AcpcPokerTypes::PokerAction::CHECK
76
- AcpcPokerTypes::PokerAction::CALL
77
- when AcpcPokerTypes::PokerAction::FOLD
78
- AcpcPokerTypes::PokerAction::FOLD
79
- when AcpcPokerTypes::PokerAction::RAISE
80
- AcpcPokerTypes::PokerAction::RAISE
81
- end
82
- )
69
+ AcpcPokerTypes::PokerAction.new(a).to_s.must_equal a
83
70
  end
84
71
  end
85
72
  it 'works properly when no chips have been added to the pot' do
@@ -89,7 +76,7 @@ describe AcpcPokerTypes::PokerAction do
89
76
  when AcpcPokerTypes::PokerAction::BET
90
77
  AcpcPokerTypes::PokerAction::BET
91
78
  when AcpcPokerTypes::PokerAction::CALL
92
- AcpcPokerTypes::PokerAction::CHECK
79
+ AcpcPokerTypes::PokerAction::CALL
93
80
  when AcpcPokerTypes::PokerAction::CHECK
94
81
  AcpcPokerTypes::PokerAction::CHECK
95
82
  when AcpcPokerTypes::PokerAction::FOLD
@@ -105,7 +92,7 @@ describe AcpcPokerTypes::PokerAction do
105
92
  AcpcPokerTypes::PokerAction.new(a).to_s(player_sees_wager: false).must_equal (
106
93
  case a
107
94
  when AcpcPokerTypes::PokerAction::BET
108
- AcpcPokerTypes::PokerAction::RAISE
95
+ AcpcPokerTypes::PokerAction::BET
109
96
  when AcpcPokerTypes::PokerAction::CALL
110
97
  AcpcPokerTypes::PokerAction::CHECK
111
98
  when AcpcPokerTypes::PokerAction::CHECK
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_poker_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.4
4
+ version: 7.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill