acpc_poker_types 2.0.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/acpc_poker_types.gemspec +2 -2
  3. data/lib/acpc_poker_types/acpc_dealer_data/action_messages.rb +1 -3
  4. data/lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb +1 -1
  5. data/lib/acpc_poker_types/board_cards.rb +38 -37
  6. data/lib/acpc_poker_types/card.rb +40 -54
  7. data/lib/acpc_poker_types/chip_stack.rb +25 -25
  8. data/lib/acpc_poker_types/game_definition.rb +286 -284
  9. data/lib/acpc_poker_types/hand.rb +19 -17
  10. data/lib/acpc_poker_types/match_state.rb +208 -235
  11. data/lib/acpc_poker_types/pile_of_cards.rb +6 -4
  12. data/lib/acpc_poker_types/player.rb +138 -133
  13. data/lib/acpc_poker_types/poker_action.rb +80 -90
  14. data/lib/acpc_poker_types/rank.rb +51 -49
  15. data/lib/acpc_poker_types/suit.rb +45 -43
  16. data/lib/acpc_poker_types/version.rb +1 -1
  17. data/spec/card_spec.rb +0 -5
  18. data/spec/coverage/index.html +1 -1
  19. data/spec/match_state_spec.rb +8 -10
  20. data/spec/player_spec.rb +12 -19
  21. data/spec/poker_action_spec.rb +105 -171
  22. data/spec/support/spec_helper.rb +0 -1
  23. metadata +121 -219
  24. data/spec/coverage/assets/0.5.3/app.js +0 -88
  25. data/spec/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  26. data/spec/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  27. data/spec/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  28. data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  29. data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  30. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  31. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  32. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  33. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  34. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  35. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  36. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  37. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  38. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  39. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  40. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  41. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  42. data/spec/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  43. data/spec/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  44. data/spec/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  45. data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
  46. data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  47. data/spec/coverage/assets/0.5.3/favicon_green.png +0 -0
  48. data/spec/coverage/assets/0.5.3/favicon_red.png +0 -0
  49. data/spec/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  50. data/spec/coverage/assets/0.5.3/highlight.css +0 -129
  51. data/spec/coverage/assets/0.5.3/highlight.pack.js +0 -1
  52. data/spec/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
  53. data/spec/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
  54. data/spec/coverage/assets/0.5.3/jquery.timeago.js +0 -141
  55. data/spec/coverage/assets/0.5.3/jquery.url.js +0 -174
  56. data/spec/coverage/assets/0.5.3/loading.gif +0 -0
  57. data/spec/coverage/assets/0.5.3/magnify.png +0 -0
  58. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  59. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  60. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  61. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  62. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  63. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  64. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  65. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  66. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  67. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  68. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  69. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  70. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  71. data/spec/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
  72. data/spec/coverage/assets/0.5.3/stylesheet.css +0 -383
@@ -1,9 +1,11 @@
1
1
 
2
2
  require 'hand_evaluator'
3
3
 
4
- class AcpcPokerTypes::PileOfCards < Array
5
- # @return [Integer] The strength of the strongest poker hand that can be made from this pile of cards.
6
- def to_poker_hand_strength
7
- HandEvaluator.rank_hand map { |card| card.to_i }
4
+ module AcpcPokerTypes
5
+ class PileOfCards < Array
6
+ # @return [Integer] The strength of the strongest poker hand that can be made from this pile of cards.
7
+ def to_poker_hand_strength
8
+ HandEvaluator.rank_hand map { |card| card.to_i }
9
+ end
8
10
  end
9
11
  end
@@ -5,172 +5,177 @@ require 'acpc_poker_types/chip_stack'
5
5
  require 'acpc_poker_types/hand'
6
6
 
7
7
  # Class to model a player.
8
- class AcpcPokerTypes::Player
9
- exceptions :incorrect_number_of_player_names
10
-
11
- def self.create_players(player_names, game_def)
12
- if game_def.number_of_players != player_names.length
13
- raise(
14
- IncorrectNumberOfPlayerNames,
15
- "#{player_names.length} names for #{game_def.number_of_players} players"
16
- )
17
- end
18
-
19
- game_def.number_of_players.times.inject([]) do |players, seat|
20
- players << AcpcPokerTypes::Player.join_match(
21
- player_names[seat],
22
- seat,
23
- AcpcPokerTypes::ChipStack.new(game_def.chip_stacks[seat])
24
- )
8
+ module AcpcPokerTypes
9
+ class Player
10
+ exceptions :incorrect_number_of_player_names
11
+
12
+ def self.create_players(player_names, game_def)
13
+ if game_def.number_of_players != player_names.length
14
+ raise(
15
+ IncorrectNumberOfPlayerNames,
16
+ "#{player_names.length} names for #{game_def.number_of_players} players"
17
+ )
18
+ end
19
+
20
+ game_def.number_of_players.times.inject([]) do |players, seat|
21
+ players << AcpcPokerTypes::Player.join_match(
22
+ player_names[seat],
23
+ seat,
24
+ AcpcPokerTypes::ChipStack.new(game_def.chip_stacks[seat])
25
+ )
26
+ end
25
27
  end
26
- end
27
28
 
28
- # @return [String] The name of this player.
29
- attr_reader :name
29
+ # @return [String] The name of this player.
30
+ attr_reader :name
30
31
 
31
- # @return [Integer] This player's seat. This is a 0 indexed
32
- # number that represents the order that this player joined the dealer.
33
- attr_reader :seat
32
+ # @return [Integer] This player's seat. This is a 0 indexed
33
+ # number that represents the order that this player joined the dealer.
34
+ attr_reader :seat
34
35
 
35
- # @return [AcpcPokerTypes::ChipStack] This player's chip stack.
36
- attr_reader :chip_stack
36
+ # @return [AcpcPokerTypes::ChipStack] This player's chip stack.
37
+ attr_reader :chip_stack
37
38
 
38
- # @return [Array<AcpcPokerTypes::ChipStack>] This player's contribution to the pot in the
39
- # current hand, organized by round.
40
- attr_reader :chip_contributions
39
+ # @return [Array<AcpcPokerTypes::ChipStack>] This player's contribution to the pot in the
40
+ # current hand, organized by round.
41
+ attr_reader :chip_contributions
41
42
 
42
- # @return [Integer] The amount this player has won or lost in the current
43
- # match. During a hand, this is a projected amount assuming that this
44
- # player loses. Positive amounts are winnings, negative amounts are losses.
45
- attr_reader :chip_balance
43
+ # @return [Integer] The amount this player has won or lost in the current
44
+ # match. During a hand, this is a projected amount assuming that this
45
+ # player loses. Positive amounts are winnings, negative amounts are losses.
46
+ attr_reader :chip_balance
46
47
 
47
- # @return [Hand] This player's hole cards or nil if this player is not
48
- # holding cards.
49
- # @example (see MatchState#users_hole_cards)
50
- attr_reader :hole_cards
48
+ # @return [Hand] This player's hole cards or nil if this player is not
49
+ # holding cards.
50
+ # @example (see MatchState#users_hole_cards)
51
+ attr_reader :hole_cards
51
52
 
52
- # @return [Array<Array<PokerAction>>] The list of actions this player has taken in
53
- # the current hand, separated by round.
54
- attr_reader :actions_taken_this_hand
53
+ # @return [Array<Array<String>>] The list of actions this player has taken in
54
+ # the current hand, separated by round.
55
+ attr_reader :actions_taken_this_hand
55
56
 
56
- alias_new :join_match
57
+ alias_new :join_match
57
58
 
58
- # @todo These comments don't work as expected
59
- # @param [String] name This players name.
60
- # @param [Integer] seat (see #seat)
61
- # @param [#to_i] chip_stack (see #chip_stack)
62
- def initialize(name, seat, chip_stack)
63
- @name = name
64
- @seat = seat
65
- @chip_balance = 0
66
- @chip_stack = chip_stack
67
- @chip_contributions = [0]
59
+ # @todo These comments don't work as expected
60
+ # @param [String] name This players name.
61
+ # @param [Integer] seat (see #seat)
62
+ # @param [#to_i] chip_stack (see #chip_stack)
63
+ def initialize(name, seat, chip_stack)
64
+ @name = name
65
+ @seat = seat
66
+ @chip_balance = 0
67
+ @chip_stack = chip_stack
68
+ @chip_contributions = [0]
68
69
 
69
- @actions_taken_this_hand = [[]]
70
- end
70
+ @actions_taken_this_hand = [[]]
71
+ end
71
72
 
72
- def ==(other)
73
- equal_on_public_info?(other) &&
74
- @hole_cards == other.hole_cards
75
- end
73
+ def ==(other)
74
+ equal_on_public_info?(other) &&
75
+ @hole_cards == other.hole_cards
76
+ end
76
77
 
77
- def equal_on_public_info?(other)
78
- @name == other.name &&
79
- @seat == other.seat &&
80
- @chip_stack == other.chip_stack &&
81
- @chip_contributions == other.chip_contributions &&
82
- @chip_balance == other.chip_balance &&
83
- @actions_taken_this_hand == other.actions_taken_this_hand
84
- end
78
+ def equal_on_public_info?(other)
79
+ @name == other.name &&
80
+ @seat == other.seat &&
81
+ @chip_stack == other.chip_stack &&
82
+ @chip_contributions == other.chip_contributions &&
83
+ @chip_balance == other.chip_balance &&
84
+ @actions_taken_this_hand == other.actions_taken_this_hand
85
+ end
85
86
 
86
- # @param [#to_i] blind_amount The blind amount for this player to pay.
87
- # @param [#to_i] chip_stack (see #chip_stack)
88
- # @param [Hand] hole_cards (see #hole_cards)
89
- def start_new_hand!(blind=AcpcPokerTypes::ChipStack.new(0), chip_stack=@chip_stack, hole_cards=AcpcPokerTypes::Hand.new)
90
- @chip_stack = chip_stack
91
- @hole_cards = hole_cards
92
- @actions_taken_this_hand = []
93
- @chip_contributions = []
87
+ # @param [#to_i] blind_amount The blind amount for this player to pay.
88
+ # @param [#to_i] chip_stack (see #chip_stack)
89
+ # @param [Hand] hole_cards (see #hole_cards)
90
+ def start_new_hand!(blind=AcpcPokerTypes::ChipStack.new(0), chip_stack=@chip_stack, hole_cards=AcpcPokerTypes::Hand.new)
91
+ @chip_stack = chip_stack
92
+ @hole_cards = hole_cards
93
+ @actions_taken_this_hand = []
94
+ @chip_contributions = []
94
95
 
95
- start_new_round!
96
+ start_new_round!
96
97
 
97
- pay_blind! blind
98
- end
98
+ pay_blind! blind
99
+ end
99
100
 
100
- def start_new_round!
101
- @actions_taken_this_hand << []
102
- @chip_contributions << 0
101
+ def start_new_round!
102
+ @actions_taken_this_hand << []
103
+ @chip_contributions << 0
103
104
 
104
- self
105
- end
105
+ self
106
+ end
106
107
 
107
- # @param [PokerAction] action The action to take.
108
- def take_action!(action)
109
- @actions_taken_this_hand.last << action
108
+ # @param [PokerAction] action The action to take.
109
+ # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
110
+ # @param sees_wager [Boolean] Whether or not the player is reacting to a wager.
111
+ # Defaults to the value of +pot_gained_chips+.
112
+ def take_action!(action, pot_gained_chips: true, sees_wager: pot_gained_chips)
113
+ @actions_taken_this_hand.last << action.to_s(pot_gained_chips: pot_gained_chips, player_sees_wager: sees_wager)
110
114
 
111
- take_from_chip_stack! action.amount_to_put_in_pot
112
- end
115
+ take_from_chip_stack! action.cost.to_r
116
+ end
113
117
 
114
- # @return [Boolean] Reports whether or not this player has folded.
115
- def folded?
116
- @actions_taken_this_hand.any? do |actions|
117
- actions.any? { |action| action.to_sym == :fold }
118
+ # @return [Boolean] Reports whether or not this player has folded.
119
+ def folded?
120
+ @actions_taken_this_hand.any? do |actions|
121
+ actions.any? { |action| action == AcpcPokerTypes::PokerAction::FOLD }
122
+ end
118
123
  end
119
- end
120
124
 
121
- # @return [Boolean] Reports whether or not this player is all-in.
122
- def all_in?
123
- 0 == @chip_stack
124
- end
125
+ # @return [Boolean] Reports whether or not this player is all-in.
126
+ def all_in?
127
+ 0 == @chip_stack
128
+ end
125
129
 
126
- # @return [Boolean] Whether or not this player is active (has not folded
127
- # or gone all-in). +true+ if this player is active, +false+ otherwise.
128
- def active?
129
- !(folded? || all_in?)
130
- end
130
+ # @return [Boolean] Whether or not this player is active (has not folded
131
+ # or gone all-in). +true+ if this player is active, +false+ otherwise.
132
+ def active?
133
+ !(folded? || all_in?)
134
+ end
131
135
 
132
- # @return [Integer] The current round, zero indexed.
133
- def round
134
- @actions_taken_this_hand.length - 1
135
- end
136
+ # @return [Integer] The current round, zero indexed.
137
+ def round
138
+ @actions_taken_this_hand.length - 1
139
+ end
136
140
 
137
- # Adjusts this player's state when it takes chips from the pot.
138
- # @param [Integer] chips The number of chips this player has won from the pot.
139
- def take_winnings!(chips)
140
- @chip_contributions << 0
141
+ # Adjusts this player's state when it takes chips from the pot.
142
+ # @param [Integer] chips The number of chips this player has won from the pot.
143
+ def take_winnings!(chips)
144
+ @chip_contributions << 0
141
145
 
142
- add_to_stack! chips
143
- end
146
+ add_to_stack! chips
147
+ end
144
148
 
145
- def assign_cards!(hole_cards)
146
- @hole_cards = hole_cards
149
+ def assign_cards!(hole_cards)
150
+ @hole_cards = hole_cards
147
151
 
148
- self
149
- end
152
+ self
153
+ end
150
154
 
151
- private
155
+ private
152
156
 
153
- # @param [#to_i] blind_amount The blind amount for this player to pay.
154
- def pay_blind!(blind_amount)
155
- take_from_chip_stack! blind_amount
156
- end
157
+ # @param [#to_i] blind_amount The blind amount for this player to pay.
158
+ def pay_blind!(blind_amount)
159
+ take_from_chip_stack! blind_amount
160
+ end
157
161
 
158
- def add_to_stack!(chips)
159
- @chip_stack += chips
160
- @chip_balance += chips.to_r
161
- @chip_contributions[-1] -= chips.to_r
162
+ def add_to_stack!(chips)
163
+ @chip_stack += chips
164
+ @chip_balance += chips.to_r
165
+ @chip_contributions[-1] -= chips.to_r
162
166
 
163
- self
164
- end
167
+ self
168
+ end
165
169
 
166
- # Take chips away from this player's chip stack.
167
- # @param (see AcpcPokerTypes::ChipStack#-)
168
- # @raise (see AcpcPokerTypes::ChipStack#-)
169
- def take_from_chip_stack!(number_of_chips)
170
- @chip_stack -= number_of_chips
171
- @chip_balance -= number_of_chips.to_r
172
- @chip_contributions[-1] += number_of_chips.to_r
170
+ # Take chips away from this player's chip stack.
171
+ # @param (see AcpcPokerTypes::ChipStack#-)
172
+ # @raise (see AcpcPokerTypes::ChipStack#-)
173
+ def take_from_chip_stack!(number_of_chips)
174
+ @chip_stack -= number_of_chips
175
+ @chip_balance -= number_of_chips.to_r
176
+ @chip_contributions[-1] += number_of_chips.to_r
173
177
 
174
- self
178
+ self
179
+ end
175
180
  end
176
- end
181
+ end
@@ -4,118 +4,108 @@ require 'dmorrill10-utils/class'
4
4
 
5
5
  require 'acpc_poker_types/chip_stack'
6
6
 
7
- class AcpcPokerTypes::PokerAction
7
+ module AcpcPokerTypes
8
+ class PokerAction
9
+ exceptions :illegal_action, :illegal_modification
8
10
 
9
- exceptions :illegal_action, :illegal_amount
11
+ BET = 'b'
12
+ CALL = 'c'
13
+ CHECK = 'k'
14
+ FOLD = 'f'
15
+ RAISE = 'r'
10
16
 
11
- # @return The amount that the player taking this action needs to put in the pot.
12
- # Could be negative to imply the acting player takes chips from the pot.
13
- attr_reader :amount_to_put_in_pot
17
+ ACTIONS = Set.new [BET, CALL, CHECK, FOLD, RAISE]
14
18
 
15
- # @return A modifier for the action (i.e. a bet or raise size).
16
- attr_reader :modifier
19
+ # @return [Set<String>] The set of legal ACPC action characters.
20
+ CANONICAL_ACTIONS = Set.new [CALL, FOLD, RAISE]
17
21
 
18
- # @return [Hash<Symbol, String>] Representations of legal actions.
19
- LEGAL_ACTIONS = {bet: 'b', call: 'c', check: 'k', fold: 'f', raise: 'r'}
22
+ MODIFIABLE_ACTIONS = Set.new [BET, RAISE]
20
23
 
21
- # @return [Set<Symbol>] The set of legal action symbols.
22
- LEGAL_SYMBOLS = Set.new LEGAL_ACTIONS.keys
24
+ CONCATONATED_ACTIONS = ACTIONS.to_a.join
23
25
 
24
- # @return [Set<String>] The set of legal action strings.
25
- LEGAL_STRINGS = Set.new LEGAL_ACTIONS.keys.map { |action| action.to_s }
26
+ # @return [Rational] The amount that the player taking this action needs to put in the pot.
27
+ # Could be negative to imply the acting player takes chips from the pot.
28
+ attr_reader :cost
26
29
 
27
- # @return [Set<String>] The set of legal ACPC action characters.
28
- LEGAL_ACPC_CHARACTERS = Set.new LEGAL_ACTIONS.values
30
+ # @return [String] A modifier for the action (i.e. a bet or raise size).
31
+ attr_reader :modifier
29
32
 
30
- # @return [Hash<Symbol, String>] Representations of the legal ACPC action characters that may be accompanied by a modifier.
31
- MODIFIABLE_ACTIONS = LEGAL_ACTIONS.select { |sym, char| 'r' == char || 'b' == char }
33
+ # @return [String] Action character
34
+ attr_reader :action
35
+ alias_method :to_acpc_character, :action
32
36
 
33
- # @return [Hash] Map of general actions to more specific actions (e.g. call to check and raise to bet).
34
- HIGH_RESOLUTION_ACTION_CONVERSION = {call: :check, raise: :bet, fold: :fold, check: :check, bet: :bet}
37
+ # @return [Boolean] Whether or not the pot has been added to this round before this action.
38
+ attr_reader :pot_gained_chips
35
39
 
36
- # @param [Symbol, String] action A representation of this action.
37
- # @param [Hash] context The context in which this action is being made. Recognized keys include +:modifier+,
38
- # +:acting_player_sees_wager+, and +:amount_to_put_in_pot+.
39
- # @raise IllegalAction
40
- def initialize(action, context={})
41
- (@symbol, @modifier) = validate_action(
42
- action,
43
- context[:modifier],
44
- if context[:acting_player_sees_wager].nil?
45
- true
46
- else
47
- context[:acting_player_sees_wager]
48
- end
49
- )
50
- @amount_to_put_in_pot = context[:amount_to_put_in_pot].to_i
51
- end
52
-
53
- def ==(other_action)
54
- to_sym == other_action.to_sym && to_s == other_action.to_s && to_acpc == other_action.to_acpc && @modifier == other_action.modifier
55
- end
56
-
57
- # @return [Boolean] +true+ if this action has a modifier, +false+ otherwise.
58
- def has_modifier?
59
- !@modifier.nil?
60
- end
61
-
62
- # @return [Symbol]
63
- def to_sym
64
- @symbol
65
- end
66
-
67
- # @return [String] String representation of this action.
68
- def to_s
69
- @symbol.to_s + @modifier.to_s
70
- end
40
+ # @param [Symbol, String] action A representation of this action.
41
+ # @param [Hash] context The context in which this action is being made. Recognized keys include +:modifier+,
42
+ # +:pot_gained_chips+, and +:cost+.
43
+ # @raise IllegalAction
44
+ def initialize(action, modifier: nil, cost: AcpcPokerTypes::ChipStack.new(0))
45
+ validate_action!(action, modifier)
46
+ @cost = cost
47
+ end
71
48
 
72
- # @return [String] Full ACPC representation of this action.
73
- def to_acpc
74
- LEGAL_ACTIONS[@symbol] + @modifier.to_s
75
- end
49
+ def ==(other_action)
50
+ to_s == other_action.to_s
51
+ end
76
52
 
77
- # @return [String] ACPC character representation of this action.
78
- def to_acpc_character
79
- LEGAL_ACTIONS[@symbol]
80
- end
53
+ # @return [String] String representation of this action.
54
+ # @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
55
+ # @param player_sees_wager [Boolean] Whether or not the player is reacting to a wager.
56
+ # Defaults to the value of +pot_gained_chips+.
57
+ def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
58
+ combine_action_and_modifier(
59
+ if @action == FOLD
60
+ @action
61
+ elsif @action == BET || @action == RAISE
62
+ if pot_gained_chips then RAISE else BET end
63
+ elsif @action == CALL || @action == CHECK
64
+ if player_sees_wager then CALL else CHECK end
65
+ end
66
+ )
67
+ end
81
68
 
82
- private
69
+ alias_method :to_acpc, :to_s
83
70
 
84
- def validate_action(action, modifier, acting_player_sees_wager)
85
- if action.to_s.match(/^(#{(LEGAL_SYMBOLS.to_a.map{ |sym| sym.to_s }).join('|')})\s*(\d*)$/)
86
- elsif action.to_s.match(/^(#{LEGAL_STRINGS.to_a.join('|')})\s*(\d*)$/)
87
- elsif action.to_s.match(/^([#{LEGAL_ACPC_CHARACTERS.to_a.join('')}])\s*(\d*)$/)
88
- else
89
- raise(IllegalAction, action.to_s)
71
+ # @return [Boolean] +true+ if this action has a modifier, +false+ otherwise.
72
+ def has_modifier?
73
+ !@modifier.nil?
90
74
  end
91
- action_type, in_place_modifier = $1, $2
92
75
 
93
- raise(IllegalAmount, "in-place modifier: #{in_place_modifier}, explicit modifier: #{modifier}") if modifier && !in_place_modifier.empty?
76
+ private
94
77
 
95
- modifier_to_use = if modifier
96
- modifier
97
- elsif !in_place_modifier.empty?
98
- AcpcPokerTypes::ChipStack.new in_place_modifier.to_i
78
+ def combine_action_and_modifier(action=@action, modifier=@modifier)
79
+ action + modifier.to_s
99
80
  end
100
81
 
101
- symbol_betting_type = LEGAL_ACTIONS.key(action_type) || action_type.to_sym
102
- action_symbol = increase_resolution_of_action(symbol_betting_type, acting_player_sees_wager)
82
+ def validate_action!(action, given_modifier)
83
+ if action.to_s.match(/^([#{CONCATONATED_ACTIONS}])\s*(\d*)$/)
84
+ else
85
+ raise IllegalAction, action.to_s
86
+ end
87
+ @action, @modifier = $1, $2
88
+
89
+ if given_modifier && !@modifier.empty?
90
+ raise(
91
+ IllegalModification,
92
+ "in-place modifier: #{@modifier}, explicit modifier: #{given_modifier}"
93
+ )
94
+ end
103
95
 
104
- raise(IllegalAction, 'Players may only fold if they are faced with a wager.') if :fold == symbol_betting_type && !acting_player_sees_wager
96
+ @modifier = if !@modifier.empty?
97
+ @modifier
98
+ elsif given_modifier
99
+ given_modifier
100
+ end
105
101
 
106
- action_modifier = validate_modifier(modifier_to_use, action_symbol)
107
- [action_symbol, action_modifier]
108
- end
102
+ validate_modifier
109
103
 
110
- def validate_modifier(modifier, action_symbol)
111
- raise(IllegalAmount, modifier.to_s) unless modifier.nil? || MODIFIABLE_ACTIONS.keys.include?(action_symbol)
112
- modifier
113
- end
104
+ self
105
+ end
114
106
 
115
- def increase_resolution_of_action(action, acting_player_sees_wager)
116
- if acting_player_sees_wager
117
- return action
107
+ def validate_modifier
108
+ raise(IllegalModification, "Illegal modifier: #{@modifier}") unless @modifier.nil? || AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.include?(@action)
118
109
  end
119
- HIGH_RESOLUTION_ACTION_CONVERSION[action]
120
110
  end
121
- end
111
+ end