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.
- checksums.yaml +4 -4
- data/acpc_poker_types.gemspec +2 -2
- data/lib/acpc_poker_types/acpc_dealer_data/action_messages.rb +1 -3
- data/lib/acpc_poker_types/acpc_dealer_data/poker_match_data.rb +1 -1
- data/lib/acpc_poker_types/board_cards.rb +38 -37
- data/lib/acpc_poker_types/card.rb +40 -54
- data/lib/acpc_poker_types/chip_stack.rb +25 -25
- data/lib/acpc_poker_types/game_definition.rb +286 -284
- data/lib/acpc_poker_types/hand.rb +19 -17
- data/lib/acpc_poker_types/match_state.rb +208 -235
- data/lib/acpc_poker_types/pile_of_cards.rb +6 -4
- data/lib/acpc_poker_types/player.rb +138 -133
- data/lib/acpc_poker_types/poker_action.rb +80 -90
- data/lib/acpc_poker_types/rank.rb +51 -49
- data/lib/acpc_poker_types/suit.rb +45 -43
- data/lib/acpc_poker_types/version.rb +1 -1
- data/spec/card_spec.rb +0 -5
- data/spec/coverage/index.html +1 -1
- data/spec/match_state_spec.rb +8 -10
- data/spec/player_spec.rb +12 -19
- data/spec/poker_action_spec.rb +105 -171
- data/spec/support/spec_helper.rb +0 -1
- metadata +121 -219
- data/spec/coverage/assets/0.5.3/app.js +0 -88
- data/spec/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
- data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/coverage/assets/0.5.3/favicon_green.png +0 -0
- data/spec/coverage/assets/0.5.3/favicon_red.png +0 -0
- data/spec/coverage/assets/0.5.3/favicon_yellow.png +0 -0
- data/spec/coverage/assets/0.5.3/highlight.css +0 -129
- data/spec/coverage/assets/0.5.3/highlight.pack.js +0 -1
- data/spec/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
- data/spec/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
- data/spec/coverage/assets/0.5.3/jquery.timeago.js +0 -141
- data/spec/coverage/assets/0.5.3/jquery.url.js +0 -174
- data/spec/coverage/assets/0.5.3/loading.gif +0 -0
- data/spec/coverage/assets/0.5.3/magnify.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/coverage/assets/0.5.3/stylesheet.css +0 -383
@@ -1,67 +1,69 @@
|
|
1
1
|
|
2
2
|
require 'dmorrill10-utils'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module AcpcPokerTypes
|
5
|
+
class Rank
|
6
|
+
exceptions :unrecognized_rank
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
DOMAIN = {
|
9
|
+
two: {acpc_character: '2', text: '2', number: 0},
|
10
|
+
three: {acpc_character: '3', text: '3', number: 1},
|
11
|
+
four: {acpc_character: '4', text: '4', number: 2},
|
12
|
+
five: {acpc_character: '5', text: '5', number: 3},
|
13
|
+
six: {acpc_character: '6', text: '6', number: 4},
|
14
|
+
seven: {acpc_character: '7', text: '7', number: 5},
|
15
|
+
eight: {acpc_character: '8', text: '8', number: 6},
|
16
|
+
nine: {acpc_character: '9', text: '9', number: 7},
|
17
|
+
ten: {acpc_character: 'T', text: '10', number: 8},
|
18
|
+
jack: {acpc_character: 'J', text: 'J', number: 9},
|
19
|
+
queen: {acpc_character: 'Q', text: 'Q', number: 10},
|
20
|
+
king: {acpc_character: 'K', text: 'K', number: 11},
|
21
|
+
ace: {acpc_character: 'A', text: 'A', number: 12}
|
22
|
+
}
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def self.hash_from_rank_token(rank)
|
25
|
+
if rank.kind_of?(Integer)
|
26
|
+
DOMAIN.find do |rank_symbol, properties|
|
27
|
+
properties[:number] == rank
|
28
|
+
end
|
29
|
+
else
|
30
|
+
DOMAIN.find do |rank_symbol, properties|
|
31
|
+
rank_symbol == rank.to_sym ||
|
31
32
|
properties[:acpc_character] == rank.to_s ||
|
32
33
|
properties[:text] == rank.to_s
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
def self.symbol_from_rank_token(rank)
|
39
|
+
rank_hash = hash_from_rank_token rank
|
39
40
|
|
40
|
-
|
41
|
+
raise UnrecognizedRank, rank.to_s unless rank_hash
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
rank_hash.first
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def initialize(rank)
|
47
|
+
@symbol = AcpcPokerTypes::Rank.symbol_from_rank_token rank
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def to_sym
|
51
|
+
@symbol
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def to_i
|
55
|
+
DOMAIN[@symbol][:number]
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
def to_acpc
|
59
|
+
DOMAIN[@symbol][:acpc_character]
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
def to_s
|
63
|
+
DOMAIN[@symbol][:text]
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
66
|
+
alias_method :to_html, :to_s
|
67
|
+
alias_method :to_str, :to_s
|
68
|
+
end
|
69
|
+
end
|
@@ -1,58 +1,60 @@
|
|
1
1
|
|
2
2
|
require 'dmorrill10-utils'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
module AcpcPokerTypes
|
5
|
+
class Suit
|
6
|
+
exceptions :unrecognized_suit
|
7
|
+
|
8
|
+
DOMAIN = {
|
9
|
+
clubs: {acpc_character: 'c', html_character: '♣', number: 0},
|
10
|
+
diamonds: {acpc_character: 'd', html_character: '♦', number: 1},
|
11
|
+
hearts: {acpc_character: 'h', html_character: '♥', number: 2},
|
12
|
+
spades: {acpc_character: 's', html_character: '♠', number: 3}
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.hash_from_suit_token(suit)
|
16
|
+
if suit.kind_of?(Integer)
|
17
|
+
DOMAIN.find do |suit_symbol, properties|
|
18
|
+
properties[:number] == suit
|
19
|
+
end
|
20
|
+
else
|
21
|
+
DOMAIN.find do |suit_symbol, properties|
|
22
|
+
suit_symbol == suit.to_sym ||
|
23
|
+
properties[:acpc_character] == suit.to_s ||
|
24
|
+
properties[:html_character] == suit.to_s
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
def self.symbol_from_suit_token(suit)
|
30
|
+
suit_hash = hash_from_suit_token suit
|
30
31
|
|
31
|
-
|
32
|
+
raise UnrecognizedSuit, suit.to_s unless suit_hash
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
suit_hash.first
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def initialize(suit)
|
38
|
+
@symbol = AcpcPokerTypes::Suit.symbol_from_suit_token suit
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def to_sym
|
42
|
+
@symbol
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def to_i
|
46
|
+
DOMAIN[@symbol][:number]
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def to_acpc
|
50
|
+
DOMAIN[@symbol][:acpc_character]
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
alias_method :to_s, :to_acpc
|
54
|
+
alias_method :to_str, :to_s
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
def to_html
|
57
|
+
DOMAIN[@symbol][:html_character]
|
58
|
+
end
|
57
59
|
end
|
58
|
-
end
|
60
|
+
end
|
data/spec/card_spec.rb
CHANGED
@@ -6,11 +6,6 @@ require 'acpc_poker_types/card'
|
|
6
6
|
|
7
7
|
describe AcpcPokerTypes::Card do
|
8
8
|
describe '::from_acpc' do
|
9
|
-
it 'raises an exception if the given ACPC card string could not be parsed properly' do
|
10
|
-
-> do
|
11
|
-
AcpcPokerTypes::Card.from_acpc('not a card')
|
12
|
-
end.must_raise(AcpcPokerTypes::Card::ParseError)
|
13
|
-
end
|
14
9
|
it 'works properly in all cases' do
|
15
10
|
for_every_card! do
|
16
11
|
@patient = AcpcPokerTypes::Card.from_acpc @acpc
|
data/spec/coverage/index.html
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<img src="./assets/0.7.1/loading.gif" alt="loading"/>
|
15
15
|
</div>
|
16
16
|
<div id="wrapper" style="display:none;">
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="2013-05-
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2013-05-05T16:00:29-07:00">2013-05-05T16:00:29-07:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
data/spec/match_state_spec.rb
CHANGED
@@ -37,10 +37,10 @@ describe AcpcPokerTypes::MatchState do
|
|
37
37
|
it "parses every possible limit action" do
|
38
38
|
partial_match_state = AcpcPokerTypes::MatchState::LABEL + ":1:1:"
|
39
39
|
hole_cards = arbitrary_hole_card_hand
|
40
|
-
AcpcPokerTypes::PokerAction::
|
40
|
+
AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |action|
|
41
41
|
match_state = partial_match_state + action + ":" + hole_cards.to_acpc
|
42
42
|
patient = test_match_state_success match_state
|
43
|
-
patient.last_action.
|
43
|
+
patient.last_action.to_s.must_equal action
|
44
44
|
end
|
45
45
|
end
|
46
46
|
it "parses every possible hole card hand" do
|
@@ -105,7 +105,7 @@ describe AcpcPokerTypes::MatchState do
|
|
105
105
|
end
|
106
106
|
it "parses a valid two player final match state" do
|
107
107
|
partial_match_state = AcpcPokerTypes::MatchState::LABEL + ":20:22:"
|
108
|
-
all_actions = AcpcPokerTypes::PokerAction::
|
108
|
+
all_actions = AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.to_a.join ''
|
109
109
|
betting = all_actions
|
110
110
|
number_of_rounds = 100
|
111
111
|
(number_of_rounds-1).times do
|
@@ -120,7 +120,7 @@ describe AcpcPokerTypes::MatchState do
|
|
120
120
|
end
|
121
121
|
it "parses a valid three player final match state" do
|
122
122
|
partial_match_state = AcpcPokerTypes::MatchState::LABEL + ":20:22:"
|
123
|
-
all_actions = AcpcPokerTypes::PokerAction::
|
123
|
+
all_actions = AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.to_a.join ''
|
124
124
|
betting = all_actions
|
125
125
|
number_of_rounds = 100
|
126
126
|
(number_of_rounds-1).times do
|
@@ -179,9 +179,9 @@ describe AcpcPokerTypes::MatchState do
|
|
179
179
|
patient.first_state_of_first_round?.must_equal true
|
180
180
|
end
|
181
181
|
it 'works properly if a previous action exists' do
|
182
|
-
AcpcPokerTypes::PokerAction::
|
183
|
-
AcpcPokerTypes::PokerAction::
|
184
|
-
AcpcPokerTypes::PokerAction::
|
182
|
+
AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |first_action|
|
183
|
+
AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |second_action|
|
184
|
+
AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |third_action|
|
185
185
|
partial_match_state = "#{AcpcPokerTypes::MatchState::LABEL}:1:1:"
|
186
186
|
|
187
187
|
partial_match_state += first_action
|
@@ -228,14 +228,12 @@ def for_every_hand
|
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
231
|
-
|
232
231
|
def test_match_state_initialization_error(incomplete_match_state)
|
233
232
|
->{AcpcPokerTypes::MatchState.parse incomplete_match_state}.must_raise(AcpcPokerTypes::MatchState::IncompleteMatchState)
|
234
233
|
end
|
235
234
|
def test_match_state_success(match_state)
|
236
235
|
patient = AcpcPokerTypes::MatchState.parse match_state
|
237
236
|
patient.to_s.must_equal match_state
|
238
|
-
|
239
237
|
patient
|
240
238
|
end
|
241
239
|
def arbitrary_flop
|
@@ -263,7 +261,7 @@ end
|
|
263
261
|
|
264
262
|
# Construct an arbitrary hole card hand.
|
265
263
|
#
|
266
|
-
# @return [
|
264
|
+
# @return [AcpcPokerTypes::Hand] An arbitrary hole card hand.
|
267
265
|
def arbitrary_hole_card_hand
|
268
266
|
AcpcPokerTypes::Hand.from_acpc(
|
269
267
|
AcpcPokerTypes::Rank::DOMAIN[:two][:acpc_character] +
|
data/spec/player_spec.rb
CHANGED
@@ -119,7 +119,7 @@ describe AcpcPokerTypes::Player do
|
|
119
119
|
end
|
120
120
|
describe 'reports it is not active if' do
|
121
121
|
it 'it has folded' do
|
122
|
-
action = AcpcPokerTypes::PokerAction.new
|
122
|
+
action = AcpcPokerTypes::PokerAction.new AcpcPokerTypes::PokerAction::FOLD
|
123
123
|
|
124
124
|
@patient.start_new_hand! BLIND, INITIAL_CHIP_STACK
|
125
125
|
@patient.take_action! action
|
@@ -137,7 +137,7 @@ describe AcpcPokerTypes::Player do
|
|
137
137
|
check_patient
|
138
138
|
end
|
139
139
|
it 'it is all-in' do
|
140
|
-
action = AcpcPokerTypes::PokerAction.new
|
140
|
+
action = AcpcPokerTypes::PokerAction.new AcpcPokerTypes::PokerAction::RAISE, cost: INITIAL_CHIP_STACK - BLIND
|
141
141
|
|
142
142
|
hand = default_hand
|
143
143
|
@patient.start_new_hand! BLIND, INITIAL_CHIP_STACK, hand
|
@@ -186,7 +186,7 @@ describe AcpcPokerTypes::Player do
|
|
186
186
|
"#{dealer_log_directory}/#{log_description.results_file_name}",
|
187
187
|
log_description.player_names,
|
188
188
|
AcpcDealer::DEALER_DIRECTORY,
|
189
|
-
|
189
|
+
120
|
190
190
|
)
|
191
191
|
match.for_every_seat! do |seat|
|
192
192
|
@patient = AcpcPokerTypes::Player.join_match(
|
@@ -325,24 +325,17 @@ end
|
|
325
325
|
yield modifier
|
326
326
|
end
|
327
327
|
end
|
328
|
-
def instantiate_each_action_from_symbols(
|
329
|
-
|
330
|
-
|
331
|
-
|
328
|
+
def instantiate_each_action_from_symbols(
|
329
|
+
cost=0, modifier=nil
|
330
|
+
)
|
331
|
+
AcpcPokerTypes::PokerAction::CANONICAL_ACTIONS.each do |action|
|
332
|
+
modifier = if AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.include? action
|
332
333
|
modifier
|
333
334
|
else
|
334
335
|
nil
|
335
336
|
end
|
336
337
|
|
337
|
-
action
|
338
|
-
action.stubs(:to_sym).returns(sym)
|
339
|
-
action.stubs(:to_s).returns(sym.to_s + modifier.to_s)
|
340
|
-
action.stubs(:to_acpc).returns(AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[sym] + modifier.to_s)
|
341
|
-
action.stubs(:to_acpc_character).returns(AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[sym])
|
342
|
-
action.stubs(:amount_to_put_in_pot).returns(amount_to_put_in_pot)
|
343
|
-
action.stubs(:modifier).returns(modifier)
|
344
|
-
|
345
|
-
yield action
|
338
|
+
yield AcpcPokerTypes::PokerAction.new(action, cost: cost, modifier: modifier)
|
346
339
|
end
|
347
340
|
end
|
348
341
|
def test_sequence_of_non_fold_actions(hole_cards=default_hand)
|
@@ -364,10 +357,10 @@ end
|
|
364
357
|
end
|
365
358
|
|
366
359
|
various_actions do |action|
|
367
|
-
next if
|
360
|
+
next if AcpcPokerTypes::PokerAction::FOLD == action.to_s
|
368
361
|
|
369
|
-
chip_stack_adjustment = if @chip_stack - action.
|
370
|
-
action.
|
362
|
+
chip_stack_adjustment = if @chip_stack - action.cost >= 0
|
363
|
+
action.cost
|
371
364
|
else @chip_stack end
|
372
365
|
|
373
366
|
@chip_balance -= chip_stack_adjustment
|
data/spec/poker_action_spec.rb
CHANGED
@@ -5,202 +5,136 @@ require_relative 'support/spec_helper'
|
|
5
5
|
require 'acpc_poker_types/poker_action'
|
6
6
|
|
7
7
|
describe AcpcPokerTypes::PokerAction do
|
8
|
-
|
9
|
-
|
10
|
-
AcpcPokerTypes::PokerAction::LEGAL_ACTIONS.wont_be_empty
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'in symbol format' do
|
14
|
-
AcpcPokerTypes::PokerAction::LEGAL_SYMBOLS.wont_be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'in string format' do
|
18
|
-
AcpcPokerTypes::PokerAction::LEGAL_STRINGS.wont_be_empty
|
19
|
-
end
|
8
|
+
DEFAULT_MODIFIER = '9001'
|
9
|
+
DEFAULT_COST = 9002
|
20
10
|
|
21
|
-
|
22
|
-
|
11
|
+
describe 'legal actions can be retrieved' do
|
12
|
+
it 'with ::legal_actions' do
|
13
|
+
AcpcPokerTypes::PokerAction::ACTIONS.wont_be_empty
|
23
14
|
end
|
24
15
|
end
|
25
|
-
|
26
16
|
describe '#new' do
|
27
17
|
it 'raises an exception if the given action is invalid' do
|
28
|
-
->{AcpcPokerTypes::PokerAction.new(
|
18
|
+
->{AcpcPokerTypes::PokerAction.new('not_an_action')}.must_raise(AcpcPokerTypes::PokerAction::IllegalAction)
|
29
19
|
end
|
30
20
|
it 'raises an exception if a modifier accompanies an unmodifiable action' do
|
31
|
-
unmodifiable_actions = AcpcPokerTypes::PokerAction::
|
32
|
-
unmodifiable_actions.each do |
|
33
|
-
->{AcpcPokerTypes::PokerAction.new(
|
21
|
+
unmodifiable_actions = AcpcPokerTypes::PokerAction::ACTIONS - AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS
|
22
|
+
unmodifiable_actions.each do |a|
|
23
|
+
->{AcpcPokerTypes::PokerAction.new(a, modifier: DEFAULT_MODIFIER)}.must_raise(AcpcPokerTypes::PokerAction::IllegalModification)
|
34
24
|
end
|
35
25
|
end
|
36
26
|
it 'raise an exception if a modifier is given both implicitly and explicitly' do
|
37
|
-
->{AcpcPokerTypes::PokerAction.new('r9001',
|
38
|
-
end
|
39
|
-
it 'raise an exception if a fold action is given when no wager is seen by the acting player' do
|
40
|
-
->{AcpcPokerTypes::PokerAction.new('f', {acting_player_sees_wager: false})}.must_raise(AcpcPokerTypes::PokerAction::IllegalAction)
|
27
|
+
->{AcpcPokerTypes::PokerAction.new('r9001', modifier: DEFAULT_MODIFIER)}.must_raise(AcpcPokerTypes::PokerAction::IllegalModification)
|
41
28
|
end
|
42
29
|
describe 'creates actions properly' do
|
43
|
-
it '
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
amount,
|
68
|
-
actual_modifier
|
69
|
-
end
|
70
|
-
instantiate_each_action_from_modified_acpc_characters(amount, modifier) do |char, actual_modifier|
|
71
|
-
check_patient_data AcpcPokerTypes::PokerAction::LEGAL_ACTIONS.key(char),
|
72
|
-
AcpcPokerTypes::PokerAction::LEGAL_ACTIONS.key(char).to_s + actual_modifier.to_s,
|
73
|
-
char + actual_modifier.to_s,
|
74
|
-
char,
|
75
|
-
amount,
|
76
|
-
actual_modifier
|
77
|
-
end
|
78
|
-
instantiate_each_action_from_modified_strings(amount, modifier) do |string, actual_modifier|
|
79
|
-
check_patient_data string.to_sym,
|
80
|
-
string + actual_modifier.to_s,
|
81
|
-
AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[string.to_sym] + actual_modifier.to_s,
|
82
|
-
AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[string.to_sym],
|
83
|
-
amount,
|
84
|
-
actual_modifier
|
85
|
-
end
|
30
|
+
it 'without modifiers' do
|
31
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
32
|
+
AcpcPokerTypes::PokerAction.new(a)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
it 'with an explicit modifier' do
|
36
|
+
AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.each do |a|
|
37
|
+
AcpcPokerTypes::PokerAction.new(a, modifier: DEFAULT_MODIFIER)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
it 'with an implicit modifier' do
|
41
|
+
AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.each do |a|
|
42
|
+
AcpcPokerTypes::PokerAction.new(a + DEFAULT_MODIFIER)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe 'with explicit cost' do
|
46
|
+
it 'when the cost is positive' do
|
47
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
48
|
+
AcpcPokerTypes::PokerAction.new(a, cost: DEFAULT_COST).cost.must_equal DEFAULT_COST
|
49
|
+
end
|
50
|
+
end
|
51
|
+
it 'when the cost is negative' do
|
52
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
53
|
+
AcpcPokerTypes::PokerAction.new(a, cost: -DEFAULT_COST).cost.must_equal -DEFAULT_COST
|
86
54
|
end
|
87
55
|
end
|
88
56
|
end
|
89
57
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
next if :fold == imprecise_action
|
95
|
-
imprecise_action_character = AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[imprecise_action]
|
96
|
-
precise_action_character = AcpcPokerTypes::PokerAction::LEGAL_ACTIONS[precise_action]
|
97
|
-
if AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.values.include? imprecise_action_character
|
98
|
-
modifier = default_modifier
|
99
|
-
expected_acpc_form = precise_action_character + modifier.to_s
|
100
|
-
else
|
101
|
-
modifier = nil
|
102
|
-
expected_acpc_form = precise_action_character
|
58
|
+
it 'performs reasonably well' do
|
59
|
+
1000.times do
|
60
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
61
|
+
AcpcPokerTypes::PokerAction.new(a)
|
103
62
|
end
|
104
|
-
AcpcPokerTypes::PokerAction.new(imprecise_action_character, {modifier: modifier, acting_player_sees_wager: false}).to_acpc.must_equal(expected_acpc_form)
|
105
63
|
end
|
106
64
|
end
|
107
65
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def check_patient_data(expected_sym,
|
126
|
-
expected_string,
|
127
|
-
expected_acpc,
|
128
|
-
expected_acpc_character,
|
129
|
-
amount_to_put_in_pot=0,
|
130
|
-
modifier=nil)
|
131
|
-
@patient.to_sym.must_equal expected_sym
|
132
|
-
@patient.to_s.must_equal expected_string
|
133
|
-
@patient.to_acpc.must_equal expected_acpc
|
134
|
-
@patient.to_acpc_character.must_equal expected_acpc_character
|
135
|
-
@patient.amount_to_put_in_pot.must_equal amount_to_put_in_pot
|
136
|
-
|
137
|
-
has_modifier = !modifier.nil?
|
138
|
-
@patient.has_modifier?.must_equal has_modifier
|
139
|
-
end
|
140
|
-
def instantiate_each_action_from_symbols(amount_to_put_in_pot=0,
|
141
|
-
modifier=nil)
|
142
|
-
AcpcPokerTypes::PokerAction::LEGAL_SYMBOLS.each do |sym|
|
143
|
-
modifier = if AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.keys.include? sym
|
144
|
-
modifier
|
145
|
-
else
|
146
|
-
nil
|
66
|
+
describe '#to_s' do
|
67
|
+
it "prints in the dealer's canonical representation by default" do
|
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
|
+
)
|
147
83
|
end
|
148
|
-
|
149
|
-
@patient = AcpcPokerTypes::PokerAction.new(sym, {amount_to_put_in_pot: amount_to_put_in_pot, modifier: modifier})
|
150
|
-
yield sym, modifier
|
151
84
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
85
|
+
it 'works properly when no chips have been added to the pot' do
|
86
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
87
|
+
AcpcPokerTypes::PokerAction.new(a).to_s(pot_gained_chips: false).must_equal (
|
88
|
+
case a
|
89
|
+
when AcpcPokerTypes::PokerAction::BET
|
90
|
+
AcpcPokerTypes::PokerAction::BET
|
91
|
+
when AcpcPokerTypes::PokerAction::CALL
|
92
|
+
AcpcPokerTypes::PokerAction::CHECK
|
93
|
+
when AcpcPokerTypes::PokerAction::CHECK
|
94
|
+
AcpcPokerTypes::PokerAction::CHECK
|
95
|
+
when AcpcPokerTypes::PokerAction::FOLD
|
96
|
+
AcpcPokerTypes::PokerAction::FOLD
|
97
|
+
when AcpcPokerTypes::PokerAction::RAISE
|
98
|
+
AcpcPokerTypes::PokerAction::BET
|
99
|
+
end
|
100
|
+
)
|
160
101
|
end
|
161
|
-
|
162
|
-
@patient = AcpcPokerTypes::PokerAction.new(string, {amount_to_put_in_pot: amount_to_put_in_pot, modifier: modifier})
|
163
|
-
yield string, modifier
|
164
|
-
end
|
165
|
-
end
|
166
|
-
def instantiate_each_action_from_modified_strings(amount_to_put_in_pot=0,
|
167
|
-
modifier=nil)
|
168
|
-
unless modifier
|
169
|
-
modifier = mock('AcpcPokerTypes::ChipStack')
|
170
|
-
modifier.stubs(:to_s).returns('9001')
|
171
102
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
103
|
+
it 'works properly when the player is not facing a wager' do
|
104
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
105
|
+
AcpcPokerTypes::PokerAction.new(a).to_s(player_sees_wager: false).must_equal (
|
106
|
+
case a
|
107
|
+
when AcpcPokerTypes::PokerAction::BET
|
108
|
+
AcpcPokerTypes::PokerAction::RAISE
|
109
|
+
when AcpcPokerTypes::PokerAction::CALL
|
110
|
+
AcpcPokerTypes::PokerAction::CHECK
|
111
|
+
when AcpcPokerTypes::PokerAction::CHECK
|
112
|
+
AcpcPokerTypes::PokerAction::CHECK
|
113
|
+
when AcpcPokerTypes::PokerAction::FOLD
|
114
|
+
AcpcPokerTypes::PokerAction::FOLD
|
115
|
+
when AcpcPokerTypes::PokerAction::RAISE
|
116
|
+
AcpcPokerTypes::PokerAction::RAISE
|
117
|
+
end
|
118
|
+
)
|
187
119
|
end
|
188
|
-
|
189
|
-
@patient = AcpcPokerTypes::PokerAction.new(char, {amount_to_put_in_pot: amount_to_put_in_pot, modifier: modifier})
|
190
|
-
yield char, modifier
|
191
120
|
end
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
121
|
+
it 'works properly when the player is not facing a wager, nor have chips been added to the pot' do
|
122
|
+
AcpcPokerTypes::PokerAction::ACTIONS.each do |a|
|
123
|
+
AcpcPokerTypes::PokerAction.new(a).to_s(player_sees_wager: false, pot_gained_chips: false).must_equal (
|
124
|
+
case a
|
125
|
+
when AcpcPokerTypes::PokerAction::BET
|
126
|
+
AcpcPokerTypes::PokerAction::BET
|
127
|
+
when AcpcPokerTypes::PokerAction::CALL
|
128
|
+
AcpcPokerTypes::PokerAction::CHECK
|
129
|
+
when AcpcPokerTypes::PokerAction::CHECK
|
130
|
+
AcpcPokerTypes::PokerAction::CHECK
|
131
|
+
when AcpcPokerTypes::PokerAction::FOLD
|
132
|
+
AcpcPokerTypes::PokerAction::FOLD
|
133
|
+
when AcpcPokerTypes::PokerAction::RAISE
|
134
|
+
AcpcPokerTypes::PokerAction::BET
|
135
|
+
end
|
136
|
+
)
|
137
|
+
end
|
204
138
|
end
|
205
139
|
end
|
206
|
-
end
|
140
|
+
end
|