acpc_poker_types 7.0.0 → 7.1.0

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: 78f0bab62893fa563b2b696c90844c647533403e
4
- data.tar.gz: 3462780103b206dd0c9b1952bb06d5e43760c24b
3
+ metadata.gz: 7ca00e6a41dab80ef2f33c8f10c3ffaff6e2c0e1
4
+ data.tar.gz: c09333d7db8f948d5e328357a59536e70e44a68b
5
5
  SHA512:
6
- metadata.gz: 4418652bec1d5c84b867e72fabd230132fa50d14b64f6a4f4bf3ed68149f68f947aad717fd533b33e2ed61e49d3a0c5cd03d59e070e15bd832ac4a08e36a186f
7
- data.tar.gz: ab329609151c04988b321aeb400b2c14a8b09b64722e172ce1438e683ddc2055769614cf857e8d5114e4782117fcdaf3c1b795735b64b896cb0155f2549f8a5d
6
+ metadata.gz: cc1c019653c1e5671db05f44a355feb8a465052c83d2b8bd5b1930a5ece33d42b25128840de95ad717383136fd36a2a035e83670d5d3edd2e3661d729ae037ee
7
+ data.tar.gz: 412ac972e9c336b2dd5e6ff3b674372c799ea9f046ded2bb6f455bae1a173cf0f9a6d536feb4cbe7cd1205f311e28b14a1c062bc26785aa75c0cf51aa8961bc3
@@ -64,5 +64,23 @@ class HandPlayerGroup < DelegateClass(Array)
64
64
  next_player_position(acting_player_position)
65
65
  )
66
66
  end
67
+
68
+ # @return [Integer] The number of wagers this round
69
+ def num_wagers(round)
70
+ inject(0) do |sum, pl|
71
+ sum += pl.actions[round].count do |ac|
72
+ PokerAction::MODIFIABLE_ACTIONS.include?(ac.action)
73
+ end
74
+ end
75
+ end
76
+
77
+ # @return [Array<PokerAction>] The legal actions for the next player to act.
78
+ def legal_actions(acting_player_position, round, max_num_wagers)
79
+ @players[acting_player_position].legal_actions(
80
+ round: round,
81
+ amount_to_call: amount_to_call(acting_player_position),
82
+ wager_illegal: num_wagers(round) >= max_num_wagers
83
+ )
84
+ end
67
85
  end
68
86
  end
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  require 'acpc_poker_types/board_cards'
2
4
  require 'acpc_poker_types/hand'
3
5
  require 'acpc_poker_types/rank'
@@ -35,7 +37,7 @@ using AcpcPokerTypes::Indices
35
37
  module AcpcPokerTypes
36
38
 
37
39
  # Model to parse and manage information from a given match state string.
38
- class MatchState
40
+ class MatchState < DelegateClass(String)
39
41
  # @return [Integer] The position relative to the dealer of the player that
40
42
  # received the match state string, indexed from 0, modulo the
41
43
  # number of players.
@@ -104,6 +106,8 @@ class MatchState
104
106
  @community_cards_string = $5
105
107
  end
106
108
  @min_wager_by = nil
109
+
110
+ super to_s
107
111
  end
108
112
 
109
113
  # @return [String] The MatchState in raw text form.
@@ -319,6 +323,15 @@ class MatchState
319
323
  @min_wager_by
320
324
  end
321
325
 
326
+ # @return [Array<PokerAction>] The legal actions for the next player to act.
327
+ def legal_actions(game_def)
328
+ players(game_def).legal_actions(
329
+ next_to_act(game_def),
330
+ round,
331
+ game_def.max_number_of_wagers[round]
332
+ )
333
+ end
334
+
322
335
  private
323
336
 
324
337
  def walk_over_betting_sequence!(game_def)
@@ -1,3 +1,4 @@
1
+ require 'delegate'
1
2
  require 'set'
2
3
 
3
4
  require 'acpc_poker_types/chip_stack'
@@ -30,115 +31,119 @@ module BlankRefinement
30
31
  end
31
32
  using BlankRefinement
32
33
 
34
+
33
35
  module AcpcPokerTypes
34
- class PokerAction
35
- exceptions :illegal_action, :illegal_modification
36
36
 
37
- BET = 'b'
38
- CALL = 'c'
39
- CHECK = 'k'
40
- FOLD = 'f'
41
- RAISE = 'r'
37
+ class PokerAction < DelegateClass(String)
38
+ exceptions :illegal_action, :illegal_modification
42
39
 
43
- ACTIONS = Set.new [BET, CALL, CHECK, FOLD, RAISE]
40
+ BET = 'b'
41
+ CALL = 'c'
42
+ CHECK = 'k'
43
+ FOLD = 'f'
44
+ RAISE = 'r'
44
45
 
45
- # @return [Set<String>] The set of legal ACPC action characters.
46
- CANONICAL_ACTIONS = Set.new [CALL, FOLD, RAISE]
46
+ ACTIONS = Set.new [BET, CALL, CHECK, FOLD, RAISE]
47
47
 
48
- MODIFIABLE_ACTIONS = Set.new [BET, RAISE]
48
+ # @return [Set<String>] The set of legal ACPC action characters.
49
+ CANONICAL_ACTIONS = Set.new [CALL, FOLD, RAISE]
49
50
 
50
- CONCATONATED_ACTIONS = ACTIONS.to_a.join
51
+ MODIFIABLE_ACTIONS = Set.new [BET, RAISE]
51
52
 
52
- # @return [Rational] The amount that the player taking this action needs to put in the pot.
53
- # Could be negative to imply the acting player takes chips from the pot.
54
- attr_reader :cost
53
+ CONCATONATED_ACTIONS = ACTIONS.to_a.join
55
54
 
56
- # @return [String] A modifier for the action (i.e. a bet or raise size).
57
- attr_reader :modifier
55
+ # @return [Rational] The amount that the player taking this action needs to put in the pot.
56
+ # Could be negative to imply the acting player takes chips from the pot.
57
+ attr_reader :cost
58
58
 
59
- # @return [String] Action character
60
- attr_reader :action
61
- alias_method :to_acpc_character, :action
59
+ # @return [String] A modifier for the action (i.e. a bet or raise size).
60
+ attr_reader :modifier
62
61
 
63
- # @return [Boolean] Whether or not the pot has been added to this round before this action.
64
- attr_reader :pot_gained_chips
62
+ # @return [String] Action character
63
+ attr_reader :action
64
+ alias_method :to_acpc_character, :action
65
65
 
66
- # @param [Symbol, String] action A representation of this action.
67
- # @param modifier [String] A modifier to attach to this action such as a wager size.
68
- # @param cost [#to_f] The amount this action costs to the acting player.
69
- # @raise IllegalAction
70
- def initialize(action, modifier: nil, cost: 0)
71
- validate_action!(action, modifier.strip)
72
- @cost = cost.to_f
73
- end
66
+ # @return [Boolean] Whether or not the pot has been added to this round before this action.
67
+ attr_reader :pot_gained_chips
74
68
 
75
- def ==(other_action)
76
- 0 == (self <=> other_action)
77
- end
69
+ # @param [Symbol, String] action A representation of this action.
70
+ # @param modifier [String] A modifier to attach to this action such as a wager size.
71
+ # @param cost [#to_f] The amount this action costs to the acting player.
72
+ # @raise IllegalAction
73
+ def initialize(action, modifier: nil, cost: 0)
74
+ validate_action!(action, modifier.strip)
75
+ @cost = cost.to_f
78
76
 
79
- def <=>(other_action)
80
- to_s <=> other_action.to_s
81
- end
77
+ super to_s
78
+ end
82
79
 
83
- # @return [String] String representation of this action.
84
- # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
85
- # @param player_sees_wager [Boolean] Whether or not the player is reacting to a wager.
86
- # Defaults to the value of +pot_gained_chips+.
87
- def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
88
- combine_action_and_modifier(
89
- if @action == FOLD
90
- @action
91
- elsif @action == BET || @action == RAISE
92
- if pot_gained_chips then RAISE else BET end
93
- elsif @action == CALL || @action == CHECK
94
- if player_sees_wager then CALL else CHECK end
95
- end
96
- )
97
- end
80
+ # def ==(other_action)
81
+ # 0 == (self <=> other_action)
82
+ # end
83
+
84
+ # def <=>(other_action)
85
+ # to_s <=> other_action.to_s
86
+ # end
87
+
88
+ # @return [String] String representation of this action.
89
+ # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
90
+ # @param player_sees_wager [Boolean] Whether or not the player is reacting to a wager.
91
+ # Defaults to the value of +pot_gained_chips+.
92
+ def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
93
+ combine_action_and_modifier(
94
+ if @action == FOLD
95
+ @action
96
+ elsif @action == BET || @action == RAISE
97
+ if pot_gained_chips then RAISE else BET end
98
+ elsif @action == CALL || @action == CHECK
99
+ if player_sees_wager then CALL else CHECK end
100
+ end
101
+ )
102
+ end
98
103
 
99
- alias_method :to_acpc, :to_s
100
- alias_method :to_str, :to_s
104
+ alias_method :to_acpc, :to_s
105
+ alias_method :to_str, :to_s
101
106
 
102
- # @return [Boolean] +true+ if this action has a modifier, +false+ otherwise.
103
- def has_modifier?
104
- !@modifier.blank?
105
- end
107
+ # @return [Boolean] +true+ if this action has a modifier, +false+ otherwise.
108
+ def has_modifier?
109
+ !@modifier.blank?
110
+ end
106
111
 
107
- private
112
+ private
108
113
 
109
- def combine_action_and_modifier(action=@action, modifier=@modifier)
110
- "#{action}#{modifier}"
111
- end
114
+ def combine_action_and_modifier(action=@action, modifier=@modifier)
115
+ "#{action}#{modifier}"
116
+ end
112
117
 
113
- def validate_action!(action, given_modifier)
114
- action_string = action.to_s
115
- raise IllegalAction if action_string.empty?
116
- @action = action_string[0]
117
- raise IllegalAction unless ACTIONS.include?(@action)
118
- @modifier = action_string[1..-1].strip unless action_string.length < 2
119
-
120
- if !given_modifier.blank? && !@modifier.blank?
121
- raise(
122
- IllegalModification,
123
- "in-place modifier: #{@modifier}, explicit modifier: #{given_modifier}"
124
- )
125
- end
118
+ def validate_action!(action, given_modifier)
119
+ action_string = action.to_s
120
+ raise IllegalAction if action_string.empty?
121
+ @action = action_string[0]
122
+ raise IllegalAction unless ACTIONS.include?(@action)
123
+ @modifier = action_string[1..-1].strip unless action_string.length < 2
124
+
125
+ if !given_modifier.blank? && !@modifier.blank?
126
+ raise(
127
+ IllegalModification,
128
+ "in-place modifier: #{@modifier}, explicit modifier: #{given_modifier}"
129
+ )
130
+ end
126
131
 
127
- @modifier = if !@modifier.blank?
128
- @modifier
129
- elsif !given_modifier.blank?
130
- given_modifier
131
- end
132
+ @modifier = if !@modifier.blank?
133
+ @modifier
134
+ elsif !given_modifier.blank?
135
+ given_modifier
136
+ end
132
137
 
133
- validate_modifier
138
+ validate_modifier
134
139
 
135
- self
136
- end
140
+ self
141
+ end
137
142
 
138
- def validate_modifier
139
- unless @modifier.blank? || MODIFIABLE_ACTIONS.include?(@action)
140
- raise(IllegalModification, "Illegal modifier: #{@modifier}")
141
- end
143
+ def validate_modifier
144
+ unless @modifier.blank? || MODIFIABLE_ACTIONS.include?(@action)
145
+ raise(IllegalModification, "Illegal modifier: #{@modifier}")
142
146
  end
143
147
  end
148
+ end
144
149
  end
@@ -1,3 +1,3 @@
1
1
  module AcpcPokerTypes
2
- VERSION = '7.0.0'
2
+ VERSION = '7.1.0'
3
3
  end
@@ -222,7 +222,7 @@ describe MatchState do
222
222
  log_description.results_file_path,
223
223
  log_description.player_names,
224
224
  AcpcDealer::DEALER_DIRECTORY,
225
- 20
225
+ 10
226
226
  )
227
227
  match.for_every_seat! do |seat|
228
228
  match.for_every_hand! do
@@ -878,6 +878,17 @@ describe MatchState do
878
878
  end
879
879
  end
880
880
  end
881
+ describe 'players legal actions' do
882
+ it 'should work properly when facing a wager' do
883
+ game_definition = GameDefinition.parse_file(AcpcDealer::GAME_DEFINITION_FILE_PATHS[2][:limit])
884
+ MatchState.parse("MATCHSTATE:0:3:crc/rrrr:Qh9s|/KdQc7c").legal_actions(
885
+ game_definition
886
+ ).must_equal [
887
+ PokerAction.new(PokerAction::CALL, cost: game_definition.min_wagers[2]),
888
+ PokerAction.new(PokerAction::FOLD)
889
+ ]
890
+ end
891
+ end
881
892
  end
882
893
 
883
894
  def for_every_card
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_poker_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-07 00:00:00.000000000 Z
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: process_runner