acpc_poker_types 7.4.4 → 7.5.0
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 -1
- data/lib/acpc_poker_types.rb +72 -0
- data/lib/acpc_poker_types/pile_of_cards.rb +189 -1
- data/lib/acpc_poker_types/rank.rb +6 -0
- data/lib/acpc_poker_types/suit.rb +18 -0
- data/lib/acpc_poker_types/version.rb +1 -1
- data/spec/acpc_poker_types_spec.rb +155 -0
- data/spec/pile_of_cards_spec.rb +505 -9
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b1ae84329dfaa9dac79bbfb0cba092682f68b9
|
4
|
+
data.tar.gz: 32a4f028764cdf4bae820490b3dbc6d840404652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02df0c4f20beb7e2748f7bb87afafc693743d05759f5282ceb8ec8c4e5b3d9fa78360382d3cfaa2eae8ab37c1dfc7c45808b5543f12e597cfbd833f143080cb2
|
7
|
+
data.tar.gz: 83df022f017169e0b0085624c88506d36b298c92b2f8a8a547fe42bf310ae35227036d4a89e9281705c30d4cdfc908d3ce95b3a947bb3d82b06f49e619ade610
|
data/acpc_poker_types.gemspec
CHANGED
@@ -15,12 +15,13 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_dependency 'acpc_dealer', '~> 2.0'
|
16
16
|
s.add_dependency 'celluloid', '~> 0.14'
|
17
17
|
s.add_dependency 'contextual_exceptions', '~> 0.0'
|
18
|
+
s.add_dependency 'inflections', '~> 3.2'
|
18
19
|
|
19
20
|
s.files = Dir.glob("lib/**/*") + %w(Rakefile acpc_poker_types.gemspec README.md)
|
20
21
|
s.test_files = Dir.glob "spec/**/*"
|
21
22
|
s.require_paths = ["lib"]
|
22
23
|
|
23
|
-
s.add_development_dependency 'minitest', '~> 5.
|
24
|
+
s.add_development_dependency 'minitest', '~> 5.5'
|
24
25
|
s.add_development_dependency 'mocha', '~> 0.13'
|
25
26
|
s.add_development_dependency 'awesome_print', '~> 1.0'
|
26
27
|
s.add_development_dependency 'simplecov', '~> 0.7'
|
data/lib/acpc_poker_types.rb
CHANGED
@@ -14,4 +14,76 @@ require "acpc_poker_types/dealer_data"
|
|
14
14
|
require 'acpc_poker_types/seat'
|
15
15
|
|
16
16
|
module AcpcPokerTypes
|
17
|
+
# @todo Functionality (but not implementation) duplicated
|
18
|
+
# from AcpcPokerTypes::PlayersAtTheTable
|
19
|
+
def dealer_index(hand_number, game_def)
|
20
|
+
(hand_number + game_def.number_of_players - 1) % game_def.number_of_players
|
21
|
+
end
|
22
|
+
def big_blind_payer_index(hand_number, game_def)
|
23
|
+
(hand_number + game_def.blinds.index(game_def.blinds.max)) % game_def.number_of_players
|
24
|
+
end
|
25
|
+
def small_blind_payer_index(hand_number, game_def)
|
26
|
+
(hand_number + game_def.blinds.index(game_def.blinds.min)) % game_def.number_of_players
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_description(player)
|
30
|
+
"#{player} checks"
|
31
|
+
end
|
32
|
+
def call_description(player, poker_action)
|
33
|
+
"#{player} calls (#{poker_action.cost.to_i})"
|
34
|
+
end
|
35
|
+
def bet_description(player, poker_action)
|
36
|
+
d = "#{player} bets"
|
37
|
+
if poker_action.modifier
|
38
|
+
d + " by #{poker_action.cost.to_i} to #{poker_action.modifier}"
|
39
|
+
else
|
40
|
+
d
|
41
|
+
end
|
42
|
+
end
|
43
|
+
def limit_raise_description(
|
44
|
+
player,
|
45
|
+
poker_action,
|
46
|
+
num_wagers_so_far,
|
47
|
+
max_num_wagers
|
48
|
+
)
|
49
|
+
"#{player} calls and raises (##{num_wagers_so_far+1} of #{max_num_wagers})"
|
50
|
+
end
|
51
|
+
def no_limit_raise_description(player, poker_action, amount_to_call)
|
52
|
+
"#{player} calls (#{amount_to_call}) and raises by #{poker_action.cost.to_i} to #{poker_action.modifier}"
|
53
|
+
end
|
54
|
+
def fold_description(player)
|
55
|
+
"#{player} folds"
|
56
|
+
end
|
57
|
+
def hand_dealt_description(players, hand_number, game_def, number_of_hands)
|
58
|
+
raise unless players.length == game_def.number_of_players
|
59
|
+
big_blind_payer = players[big_blind_payer_index(
|
60
|
+
hand_number,
|
61
|
+
game_def
|
62
|
+
)]
|
63
|
+
small_blind_payer = players[small_blind_payer_index(
|
64
|
+
hand_number,
|
65
|
+
game_def
|
66
|
+
)]
|
67
|
+
dealer_player = players[dealer_index(
|
68
|
+
hand_number,
|
69
|
+
game_def
|
70
|
+
)]
|
71
|
+
"Hand ##{hand_number} of #{number_of_hands} dealt by #{dealer_player}, #{small_blind_payer} pays SB (#{game_def.blinds.min}), #{big_blind_payer} pays BB (#{game_def.blinds.max})"
|
72
|
+
end
|
73
|
+
def hand_win_description(player, amount_won, current_balance)
|
74
|
+
"#{player} wins #{amount_won}, bringing their balance to #{current_balance + amount_won}"
|
75
|
+
end
|
76
|
+
def split_pot_description(players, amount)
|
77
|
+
a = if players.length > 2
|
78
|
+
players[0..-2].join(', ') + ", and #{players.last}"
|
79
|
+
else
|
80
|
+
"#{players[0]} and #{players[1]}"
|
81
|
+
end
|
82
|
+
split_amount = (amount / players.length.to_r).round(2)
|
83
|
+
"#{a} split the pot, each winning " + if split_amount == split_amount.to_i
|
84
|
+
split_amount.to_i.to_s
|
85
|
+
else
|
86
|
+
sprintf("%0.2f", split_amount.to_f)
|
87
|
+
end
|
88
|
+
end
|
17
89
|
end
|
@@ -1,11 +1,199 @@
|
|
1
|
-
|
2
1
|
require 'hand_evaluator'
|
2
|
+
require 'inflections'
|
3
|
+
require 'active_support'
|
3
4
|
|
4
5
|
module AcpcPokerTypes
|
5
6
|
class PileOfCards < Array
|
7
|
+
POKER_HAND_STRENGTHS = {
|
8
|
+
royal_flush: 12115,
|
9
|
+
straight_flush: 12106,
|
10
|
+
four_of_a_kind: 11934,
|
11
|
+
full_house: 10921,
|
12
|
+
flush: 9634,
|
13
|
+
straight: 9623,
|
14
|
+
three_of_a_kind: 8606,
|
15
|
+
two_pair: 5291,
|
16
|
+
one_pair: 1287,
|
17
|
+
high_card: 0
|
18
|
+
}
|
19
|
+
|
6
20
|
# @return [Integer] The strength of the strongest poker hand that can be made from this pile of cards.
|
7
21
|
def to_poker_hand_strength
|
8
22
|
HandEvaluator.rank_hand map { |card| card.to_i }
|
9
23
|
end
|
24
|
+
|
25
|
+
def to_poker_hand_key
|
26
|
+
flattened_strengths = self.class().poker_hand_strengths_sorted_desc.flatten
|
27
|
+
flattened_strengths[
|
28
|
+
flattened_strengths.index do |e|
|
29
|
+
e.respond_to?(:to_i) && e.to_i <= to_poker_hand_strength
|
30
|
+
end - 1
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_poker_hand_description
|
35
|
+
case to_poker_hand_key
|
36
|
+
when :royal_flush
|
37
|
+
'royal flush'
|
38
|
+
when :straight_flush
|
39
|
+
"#{Rank.new(to_poker_hand_strength - POKER_HAND_STRENGTHS[:straight_flush] + 3).to_sym}-high straight flush"
|
40
|
+
when :four_of_a_kind
|
41
|
+
rank_with_quad = largest_rank(4)
|
42
|
+
|
43
|
+
m = "quad #{ActiveSupport::Inflector.pluralize(rank_with_quad.to_sym.to_s)}"
|
44
|
+
|
45
|
+
if length > 4
|
46
|
+
kicker = remaining_cards(rank_with_quad, 4).largest_rank
|
47
|
+
"#{m} with #{kicker.to_sym} kicker"
|
48
|
+
else
|
49
|
+
m
|
50
|
+
end
|
51
|
+
when :full_house
|
52
|
+
rank_with_trip = largest_rank(3)
|
53
|
+
rank_with_pair = remaining_cards(rank_with_trip, -1).largest_rank 2
|
54
|
+
"#{ActiveSupport::Inflector.pluralize(rank_with_trip.to_sym.to_s)} full of #{ActiveSupport::Inflector.pluralize(rank_with_pair.to_sym.to_s)}"
|
55
|
+
when :flush
|
56
|
+
flush_with_largest_rank = nil
|
57
|
+
largest_rank_so_far = -1
|
58
|
+
Suit.every_suit do |suit|
|
59
|
+
if count { |c| c.suit == suit } >= 5
|
60
|
+
r = largest_rank 1, [suit]
|
61
|
+
if r > largest_rank_so_far
|
62
|
+
flush_with_largest_rank = suit
|
63
|
+
largest_rank_so_far = r
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
cards = all_cards flush_with_largest_rank
|
68
|
+
r1 = cards.largest_rank
|
69
|
+
cards = cards.remaining_cards(r1)
|
70
|
+
r2 = cards.largest_rank
|
71
|
+
cards = cards.remaining_cards(r2)
|
72
|
+
r3 = cards.largest_rank
|
73
|
+
cards = cards.remaining_cards(r3)
|
74
|
+
r4 = cards.largest_rank
|
75
|
+
cards = cards.remaining_cards(r4)
|
76
|
+
r5 = cards.largest_rank
|
77
|
+
|
78
|
+
"#{r1.to_sym}, #{r2.to_sym}, #{r3.to_sym}, #{r4.to_sym}, #{r5.to_sym} flush"
|
79
|
+
when :straight
|
80
|
+
"#{Rank.new(to_poker_hand_strength - POKER_HAND_STRENGTHS[:straight] + 3).to_sym}-high straight"
|
81
|
+
when :three_of_a_kind
|
82
|
+
r = largest_rank 3
|
83
|
+
m = "trip #{ActiveSupport::Inflector.pluralize(r.to_sym.to_s)}"
|
84
|
+
|
85
|
+
if length > 3
|
86
|
+
cards = remaining_cards(r, 3)
|
87
|
+
r1 = cards.largest_rank
|
88
|
+
m += " with #{r1.to_sym}"
|
89
|
+
|
90
|
+
if length > 4
|
91
|
+
cards = cards.remaining_cards r1
|
92
|
+
r2 = cards.largest_rank
|
93
|
+
m += " and #{r2.to_sym}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
m
|
97
|
+
when :two_pair
|
98
|
+
first_pair = largest_rank 2
|
99
|
+
cards = remaining_cards first_pair, -1
|
100
|
+
second_pair = cards.largest_rank 2
|
101
|
+
|
102
|
+
m = "#{ActiveSupport::Inflector.pluralize(first_pair.to_sym.to_s)} and #{ActiveSupport::Inflector.pluralize(second_pair.to_sym.to_s)}"
|
103
|
+
|
104
|
+
if length > 4
|
105
|
+
cards = cards.remaining_cards second_pair, -1
|
106
|
+
"#{m} with #{cards.largest_rank.to_sym} kicker"
|
107
|
+
else
|
108
|
+
m
|
109
|
+
end
|
110
|
+
when :one_pair
|
111
|
+
pair = largest_rank 2
|
112
|
+
|
113
|
+
m = "pair of #{ActiveSupport::Inflector.pluralize(pair.to_sym.to_s)}"
|
114
|
+
|
115
|
+
if length > 2
|
116
|
+
cards = remaining_cards pair, -1
|
117
|
+
r1 = cards.largest_rank
|
118
|
+
m += " with #{r1.to_sym}"
|
119
|
+
|
120
|
+
if length > 3
|
121
|
+
cards = cards.remaining_cards r1, -1
|
122
|
+
r2 = cards.largest_rank
|
123
|
+
|
124
|
+
if length > 4
|
125
|
+
cards = cards.remaining_cards r2, -1
|
126
|
+
r3 = cards.largest_rank
|
127
|
+
m += ", #{r2.to_sym}, and #{r3.to_sym}"
|
128
|
+
else
|
129
|
+
m += " and #{r2.to_sym}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
m
|
134
|
+
when :high_card
|
135
|
+
cards = self
|
136
|
+
hand = [5, length].min.times.inject([]) do |h, i|
|
137
|
+
c = cards.largest_rank
|
138
|
+
h << c.to_sym
|
139
|
+
cards = cards.remaining_cards(c, -1)
|
140
|
+
h
|
141
|
+
end
|
142
|
+
|
143
|
+
if length == 1
|
144
|
+
"#{hand.first}"
|
145
|
+
elsif length == 2
|
146
|
+
"#{hand.first} and #{hand.last}"
|
147
|
+
else
|
148
|
+
"#{hand[0..-2].join(', ')}, and #{hand.last}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def all_cards(suit)
|
154
|
+
self.class().new(select { |c| c.suit == suit })
|
155
|
+
end
|
156
|
+
|
157
|
+
def remaining_cards(
|
158
|
+
rank_of_cards_to_remove,
|
159
|
+
number_of_cards_to_remove = 1
|
160
|
+
)
|
161
|
+
num_matched_cards = 0
|
162
|
+
reduce(self.class().new([])) do |cards, c|
|
163
|
+
if (
|
164
|
+
c.rank == rank_of_cards_to_remove && (
|
165
|
+
num_matched_cards < number_of_cards_to_remove ||
|
166
|
+
number_of_cards_to_remove < 0
|
167
|
+
)
|
168
|
+
)
|
169
|
+
num_matched_cards += 1
|
170
|
+
else
|
171
|
+
cards << c
|
172
|
+
end
|
173
|
+
cards
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def largest_rank(number_of_cards = 1, suits = Suit.all_suits)
|
178
|
+
rank = -1
|
179
|
+
each do |card|
|
180
|
+
if (
|
181
|
+
card.rank > rank &&
|
182
|
+
suits.include?(card.suit) &&
|
183
|
+
count { |c| c.rank == card.rank } >= number_of_cards &&
|
184
|
+
card.rank > rank
|
185
|
+
)
|
186
|
+
rank = card.rank
|
187
|
+
end
|
188
|
+
end
|
189
|
+
rank
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
# @return [Array<Array<Symbol,Integer>>]
|
195
|
+
def self.poker_hand_strengths_sorted_desc
|
196
|
+
POKER_HAND_STRENGTHS.sort { |a, b| b.last <=> a.last }
|
197
|
+
end
|
10
198
|
end
|
11
199
|
end
|
@@ -3,6 +3,8 @@ using ContextualExceptions::ClassRefinement
|
|
3
3
|
|
4
4
|
module AcpcPokerTypes
|
5
5
|
class Rank
|
6
|
+
include Comparable
|
7
|
+
|
6
8
|
exceptions :unrecognized_rank
|
7
9
|
|
8
10
|
DOMAIN = {
|
@@ -47,6 +49,10 @@ module AcpcPokerTypes
|
|
47
49
|
@symbol = AcpcPokerTypes::Rank.symbol_from_rank_token rank
|
48
50
|
end
|
49
51
|
|
52
|
+
def <=>(rank)
|
53
|
+
self.to_i <=> rank.to_i
|
54
|
+
end
|
55
|
+
|
50
56
|
def to_sym
|
51
57
|
@symbol
|
52
58
|
end
|
@@ -3,6 +3,8 @@ using ContextualExceptions::ClassRefinement
|
|
3
3
|
|
4
4
|
module AcpcPokerTypes
|
5
5
|
class Suit
|
6
|
+
include Comparable
|
7
|
+
|
6
8
|
exceptions :unrecognized_suit
|
7
9
|
|
8
10
|
DOMAIN = {
|
@@ -12,6 +14,18 @@ module AcpcPokerTypes
|
|
12
14
|
spades: {acpc_character: 's', html_character: '♠', number: 3}
|
13
15
|
}
|
14
16
|
|
17
|
+
def self.all_suits
|
18
|
+
DOMAIN.map do |suit, properties|
|
19
|
+
Suit.new(suit)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.every_suit
|
24
|
+
DOMAIN.each do |suit, properties|
|
25
|
+
yield Suit.new(suit)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
15
29
|
def self.hash_from_suit_token(suit)
|
16
30
|
if suit.kind_of?(Integer)
|
17
31
|
DOMAIN.find do |suit_symbol, properties|
|
@@ -38,6 +52,10 @@ module AcpcPokerTypes
|
|
38
52
|
@symbol = AcpcPokerTypes::Suit.symbol_from_suit_token suit
|
39
53
|
end
|
40
54
|
|
55
|
+
def <=>(suit)
|
56
|
+
self.to_i <=> suit.to_i
|
57
|
+
end
|
58
|
+
|
41
59
|
def to_sym
|
42
60
|
@symbol
|
43
61
|
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require_relative 'support/spec_helper.rb'
|
2
|
+
require_relative '../lib/acpc_poker_types.rb'
|
3
|
+
|
4
|
+
include AcpcPokerTypes
|
5
|
+
|
6
|
+
describe AcpcPokerTypes do
|
7
|
+
before do
|
8
|
+
@l_game_def = GameDefinition.parse(
|
9
|
+
'
|
10
|
+
GAMEDEF
|
11
|
+
limit
|
12
|
+
numPlayers = 2
|
13
|
+
numRounds = 4
|
14
|
+
blind = 10 5
|
15
|
+
raiseSize = 10 10 20 20
|
16
|
+
firstPlayer = 2 1 1 1
|
17
|
+
maxRaises = 3 4 4 4
|
18
|
+
numSuits = 4
|
19
|
+
numRanks = 13
|
20
|
+
numHoleCards = 2
|
21
|
+
numBoardCards = 0 3 1 1
|
22
|
+
END GAMEDEF
|
23
|
+
'.split("\n")
|
24
|
+
)
|
25
|
+
@nl_game_def = GameDefinition.parse(
|
26
|
+
'
|
27
|
+
GAMEDEF
|
28
|
+
nolimit
|
29
|
+
numPlayers = 2
|
30
|
+
numRounds = 4
|
31
|
+
stack = 20000 20000
|
32
|
+
blind = 100 50
|
33
|
+
firstPlayer = 2 1 1 1
|
34
|
+
numSuits = 4
|
35
|
+
numRanks = 13
|
36
|
+
numHoleCards = 2
|
37
|
+
numBoardCards = 0 3 1 1
|
38
|
+
END GAMEDEF
|
39
|
+
'.split("\n")
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'when player A calls a bet of 100 the log would say: A calls (100)' do
|
44
|
+
call_description(
|
45
|
+
'A',
|
46
|
+
PokerAction.new('c', cost: 100)
|
47
|
+
).must_equal 'A calls (100)'
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "no-limit hold'em" do
|
51
|
+
it 'when player A bets by 500 to 700: A bets by 500 to 700' do
|
52
|
+
bet_description(
|
53
|
+
'A',
|
54
|
+
PokerAction.new('b700', cost: 500)
|
55
|
+
).must_equal 'A bets by 500 to 700'
|
56
|
+
end
|
57
|
+
it 'when player B raises by 500 to 700 after player A bet by 100 to 200: B calls (100) and raises by 500 to 700' do
|
58
|
+
no_limit_raise_description(
|
59
|
+
'B',
|
60
|
+
PokerAction.new('r700', cost: 500),
|
61
|
+
100
|
62
|
+
).must_equal 'B calls (100) and raises by 500 to 700'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "limit hold'em" do
|
67
|
+
it 'when player A bets: A bets' do
|
68
|
+
bet_description(
|
69
|
+
'A',
|
70
|
+
PokerAction.new('b', cost: 500)
|
71
|
+
).must_equal 'A bets'
|
72
|
+
end
|
73
|
+
it 'when player B raises after player A bet in a round with a maximum of four wagers: B calls and raises (#2 of 4)' do
|
74
|
+
limit_raise_description(
|
75
|
+
'B',
|
76
|
+
PokerAction.new('r', cost: 500),
|
77
|
+
1,
|
78
|
+
4
|
79
|
+
).must_equal 'B calls and raises (#2 of 4)'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'when player A checks: A checks' do
|
84
|
+
check_description('A').must_equal 'A checks'
|
85
|
+
end
|
86
|
+
it 'when player A folds: A folds' do
|
87
|
+
fold_description('A').must_equal 'A folds'
|
88
|
+
end
|
89
|
+
it 'when the xth hand is dealt by player A, and A is small blind, while player B is big blind: Hand #x of y dealt by A, A pays SB (5), B pays BB (10)' do
|
90
|
+
x = 23
|
91
|
+
y = 100
|
92
|
+
p1 = 'A'
|
93
|
+
p2 = 'B'
|
94
|
+
hand_dealt_description(
|
95
|
+
[p1, p2],
|
96
|
+
x,
|
97
|
+
@l_game_def,
|
98
|
+
y
|
99
|
+
).must_equal "Hand ##{x} of #{y} dealt by #{p1}, #{p1} pays SB (#{@l_game_def.blinds.min}), #{p2} pays BB (#{@l_game_def.blinds.max})"
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'hand result messages' do
|
103
|
+
it 'when player A wins 1000 to increase their balance to 2000: A wins 1000, bringing their balance to 2000' do
|
104
|
+
player = 'A'
|
105
|
+
amount_won = 1000
|
106
|
+
current_balance = 2000
|
107
|
+
hand_win_description(
|
108
|
+
player,
|
109
|
+
amount_won,
|
110
|
+
current_balance
|
111
|
+
).must_equal "#{player} wins #{amount_won}, bringing their balance to #{current_balance + amount_won}"
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#split_pot_description' do
|
115
|
+
it 'when players A and B split the bot of 1000: A and B split the pot, each winning 500' do
|
116
|
+
split_pot_description(
|
117
|
+
['A', 'B'],
|
118
|
+
1000
|
119
|
+
).must_equal 'A and B split the pot, each winning 500'
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'when players A, B, and C split the bot of 1000: A, B, and C split the pot, each winning 333.' do
|
123
|
+
split_pot_description(
|
124
|
+
['A', 'B', 'C'],
|
125
|
+
1000
|
126
|
+
).must_equal 'A, B, and C split the pot, each winning 333.33'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#dealer_index, #big_blind_payer_index, and #small_blind_payer_index' do
|
132
|
+
it 'should return the index of the big blind on the first hand' do
|
133
|
+
dealer_index(0, @l_game_def).must_equal 1
|
134
|
+
big_blind_payer_index(0, @l_game_def).must_equal 0
|
135
|
+
small_blind_payer_index(0, @l_game_def).must_equal 1
|
136
|
+
end
|
137
|
+
it 'should work on every other hand' do
|
138
|
+
dealer_index(1, @l_game_def).must_equal 0
|
139
|
+
big_blind_payer_index(1, @l_game_def).must_equal 1
|
140
|
+
small_blind_payer_index(1, @l_game_def).must_equal 0
|
141
|
+
dealer_index(2, @l_game_def).must_equal 1
|
142
|
+
big_blind_payer_index(2, @l_game_def).must_equal 0
|
143
|
+
small_blind_payer_index(2, @l_game_def).must_equal 1
|
144
|
+
dealer_index(3, @l_game_def).must_equal 0
|
145
|
+
big_blind_payer_index(3, @l_game_def).must_equal 1
|
146
|
+
small_blind_payer_index(3, @l_game_def).must_equal 0
|
147
|
+
dealer_index(4, @l_game_def).must_equal 1
|
148
|
+
big_blind_payer_index(4, @l_game_def).must_equal 0
|
149
|
+
small_blind_payer_index(4, @l_game_def).must_equal 1
|
150
|
+
dealer_index(5, @l_game_def).must_equal 0
|
151
|
+
big_blind_payer_index(5, @l_game_def).must_equal 1
|
152
|
+
small_blind_payer_index(5, @l_game_def).must_equal 0
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/spec/pile_of_cards_spec.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
require File.expand_path('../support/spec_helper', __FILE__)
|
4
4
|
|
5
5
|
require 'hand_evaluator'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
require_relative '../lib/acpc_poker_types/card'
|
7
|
+
require_relative '../lib/acpc_poker_types/pile_of_cards'
|
8
|
+
require_relative '../lib/acpc_poker_types/rank'
|
9
|
+
require_relative '../lib/acpc_poker_types/suit'
|
10
10
|
|
11
11
|
describe AcpcPokerTypes::PileOfCards do
|
12
12
|
describe '#to_poker_hand_strength' do
|
@@ -39,12 +39,508 @@ describe AcpcPokerTypes::PileOfCards do
|
|
39
39
|
|
40
40
|
patient.to_poker_hand_strength.must_equal hand_strength
|
41
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#to_poker_hand_description' do
|
45
|
+
it 'works for royal flush' do
|
46
|
+
AcpcPokerTypes::PileOfCards.new(
|
47
|
+
[
|
48
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
49
|
+
AcpcPokerTypes::Card.from_acpc('Kh'),
|
50
|
+
AcpcPokerTypes::Card.from_acpc('Qh'),
|
51
|
+
AcpcPokerTypes::Card.from_acpc('Jh'),
|
52
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
53
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
54
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
55
|
+
]
|
56
|
+
).to_poker_hand_key.must_equal(:royal_flush)
|
57
|
+
end
|
58
|
+
describe 'straight flush' do
|
59
|
+
it 'works for the smallest straight flush' do
|
60
|
+
AcpcPokerTypes::PileOfCards.new(
|
61
|
+
[
|
62
|
+
AcpcPokerTypes::Card.from_acpc('5h'),
|
63
|
+
AcpcPokerTypes::Card.from_acpc('4h'),
|
64
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
65
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
66
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
67
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
68
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
69
|
+
]
|
70
|
+
).to_poker_hand_key.must_equal(:straight_flush)
|
71
|
+
end
|
72
|
+
it 'works for a larger straight flush' do
|
73
|
+
AcpcPokerTypes::PileOfCards.new(
|
74
|
+
[
|
75
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
76
|
+
AcpcPokerTypes::Card.from_acpc('9h'),
|
77
|
+
AcpcPokerTypes::Card.from_acpc('8h'),
|
78
|
+
AcpcPokerTypes::Card.from_acpc('7h'),
|
79
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
80
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
81
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
82
|
+
]
|
83
|
+
).to_poker_hand_key.must_equal(:straight_flush)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
describe 'four of a kind' do
|
87
|
+
it 'works for the smallest four of a kind' do
|
88
|
+
AcpcPokerTypes::PileOfCards.new(
|
89
|
+
[
|
90
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
91
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
92
|
+
AcpcPokerTypes::Card.from_acpc('2d'),
|
93
|
+
AcpcPokerTypes::Card.from_acpc('2s')
|
94
|
+
]
|
95
|
+
).to_poker_hand_key.must_equal(:four_of_a_kind)
|
96
|
+
end
|
97
|
+
it 'works for a larger four of a kind' do
|
98
|
+
AcpcPokerTypes::PileOfCards.new(
|
99
|
+
[
|
100
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
101
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
102
|
+
AcpcPokerTypes::Card.from_acpc('Td'),
|
103
|
+
AcpcPokerTypes::Card.from_acpc('Ts'),
|
104
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
105
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
106
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
107
|
+
]
|
108
|
+
).to_poker_hand_key.must_equal(:four_of_a_kind)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
describe 'full house' do
|
112
|
+
it 'works for the smallest full house' do
|
113
|
+
AcpcPokerTypes::PileOfCards.new(
|
114
|
+
[
|
115
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
116
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
117
|
+
AcpcPokerTypes::Card.from_acpc('2d'),
|
118
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
119
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
120
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
121
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
122
|
+
]
|
123
|
+
).to_poker_hand_key.must_equal(:full_house)
|
124
|
+
end
|
125
|
+
it 'works for a larger full house' do
|
126
|
+
AcpcPokerTypes::PileOfCards.new(
|
127
|
+
[
|
128
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
129
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
130
|
+
AcpcPokerTypes::Card.from_acpc('Td'),
|
131
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
132
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
133
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
134
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
135
|
+
]
|
136
|
+
).to_poker_hand_key.must_equal(:full_house)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
describe 'flush' do
|
140
|
+
it 'works for the smallest flush' do
|
141
|
+
AcpcPokerTypes::PileOfCards.new(
|
142
|
+
[
|
143
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
144
|
+
AcpcPokerTypes::Card.from_acpc('3c'),
|
145
|
+
AcpcPokerTypes::Card.from_acpc('4c'),
|
146
|
+
AcpcPokerTypes::Card.from_acpc('5c'),
|
147
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
148
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
149
|
+
AcpcPokerTypes::Card.from_acpc('Th')
|
150
|
+
]
|
151
|
+
).to_poker_hand_key.must_equal(:flush)
|
152
|
+
end
|
153
|
+
it 'works for a larger flush' do
|
154
|
+
AcpcPokerTypes::PileOfCards.new(
|
155
|
+
[
|
156
|
+
AcpcPokerTypes::Card.from_acpc('Qc'),
|
157
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
158
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
159
|
+
AcpcPokerTypes::Card.from_acpc('3c'),
|
160
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
161
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
162
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
163
|
+
]
|
164
|
+
).to_poker_hand_key.must_equal(:flush)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
describe 'straight' do
|
168
|
+
it 'works for the smallest straight' do
|
169
|
+
AcpcPokerTypes::PileOfCards.new(
|
170
|
+
[
|
171
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
172
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
173
|
+
AcpcPokerTypes::Card.from_acpc('4s'),
|
174
|
+
AcpcPokerTypes::Card.from_acpc('5d'),
|
175
|
+
AcpcPokerTypes::Card.from_acpc('Ac'),
|
176
|
+
AcpcPokerTypes::Card.from_acpc('8s'),
|
177
|
+
AcpcPokerTypes::Card.from_acpc('Th')
|
178
|
+
]
|
179
|
+
).to_poker_hand_key.must_equal(:straight)
|
180
|
+
end
|
181
|
+
it 'works for a larger straight' do
|
182
|
+
AcpcPokerTypes::PileOfCards.new(
|
183
|
+
[
|
184
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
185
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
186
|
+
AcpcPokerTypes::Card.from_acpc('9h'),
|
187
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
188
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
189
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
190
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
191
|
+
]
|
192
|
+
).to_poker_hand_key.must_equal(:straight)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
describe 'three of a kind' do
|
196
|
+
it 'works for the smallest three_of_a_kind' do
|
197
|
+
AcpcPokerTypes::PileOfCards.new(
|
198
|
+
[
|
199
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
200
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
201
|
+
AcpcPokerTypes::Card.from_acpc('2s')
|
202
|
+
]
|
203
|
+
).to_poker_hand_key.must_equal(:three_of_a_kind)
|
204
|
+
end
|
205
|
+
it 'works for a larger three_of_a_kind' do
|
206
|
+
AcpcPokerTypes::PileOfCards.new(
|
207
|
+
[
|
208
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
209
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
210
|
+
AcpcPokerTypes::Card.from_acpc('Jh'),
|
211
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
212
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
213
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
214
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
215
|
+
]
|
216
|
+
).to_poker_hand_key.must_equal(:three_of_a_kind)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
describe 'two pair' do
|
220
|
+
it 'works for the smallest two pair' do
|
221
|
+
AcpcPokerTypes::PileOfCards.new(
|
222
|
+
[
|
223
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
224
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
225
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
226
|
+
AcpcPokerTypes::Card.from_acpc('3d')
|
227
|
+
]
|
228
|
+
).to_poker_hand_key.must_equal(:two_pair)
|
229
|
+
end
|
230
|
+
it 'works for a larger two pair' do
|
231
|
+
AcpcPokerTypes::PileOfCards.new(
|
232
|
+
[
|
233
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
234
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
235
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
236
|
+
AcpcPokerTypes::Card.from_acpc('Ad'),
|
237
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
238
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
239
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
240
|
+
]
|
241
|
+
).to_poker_hand_key.must_equal(:two_pair)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
describe 'one pair' do
|
245
|
+
it 'works for the smallest one pair' do
|
246
|
+
AcpcPokerTypes::PileOfCards.new(
|
247
|
+
[
|
248
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
249
|
+
AcpcPokerTypes::Card.from_acpc('2h')
|
250
|
+
]
|
251
|
+
).to_poker_hand_key.must_equal(:one_pair)
|
252
|
+
end
|
253
|
+
it 'works for a larger one pair' do
|
254
|
+
AcpcPokerTypes::PileOfCards.new(
|
255
|
+
[
|
256
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
257
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
258
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
259
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
260
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
261
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
262
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
263
|
+
]
|
264
|
+
).to_poker_hand_key.must_equal(:one_pair)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
describe 'high card' do
|
268
|
+
it 'works for the smallest high card' do
|
269
|
+
AcpcPokerTypes::PileOfCards.new(
|
270
|
+
[
|
271
|
+
AcpcPokerTypes::Card.from_acpc('2c')
|
272
|
+
]
|
273
|
+
).to_poker_hand_key.must_equal(:high_card)
|
274
|
+
end
|
275
|
+
it 'works for a larger high card' do
|
276
|
+
AcpcPokerTypes::PileOfCards.new(
|
277
|
+
[
|
278
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
279
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
280
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
281
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
282
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
283
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
284
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
285
|
+
]
|
286
|
+
).to_poker_hand_key.must_equal(:high_card)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '#to_poker_hand_description' do
|
292
|
+
it 'works for royal flush' do
|
293
|
+
AcpcPokerTypes::PileOfCards.new(
|
294
|
+
[
|
295
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
296
|
+
AcpcPokerTypes::Card.from_acpc('Kh'),
|
297
|
+
AcpcPokerTypes::Card.from_acpc('Qh'),
|
298
|
+
AcpcPokerTypes::Card.from_acpc('Jh'),
|
299
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
300
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
301
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
302
|
+
]
|
303
|
+
).to_poker_hand_description.must_equal('royal flush')
|
304
|
+
end
|
305
|
+
describe 'straight flush' do
|
306
|
+
it 'works for the smallest straight flush' do
|
307
|
+
AcpcPokerTypes::PileOfCards.new(
|
308
|
+
[
|
309
|
+
AcpcPokerTypes::Card.from_acpc('5h'),
|
310
|
+
AcpcPokerTypes::Card.from_acpc('4h'),
|
311
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
312
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
313
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
314
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
315
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
316
|
+
]
|
317
|
+
).to_poker_hand_description.must_equal('five-high straight flush')
|
318
|
+
end
|
319
|
+
it 'works for a larger straight flush' do
|
320
|
+
AcpcPokerTypes::PileOfCards.new(
|
321
|
+
[
|
322
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
323
|
+
AcpcPokerTypes::Card.from_acpc('9h'),
|
324
|
+
AcpcPokerTypes::Card.from_acpc('8h'),
|
325
|
+
AcpcPokerTypes::Card.from_acpc('7h'),
|
326
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
327
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
328
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
329
|
+
]
|
330
|
+
).to_poker_hand_description.must_equal('ten-high straight flush')
|
331
|
+
end
|
332
|
+
end
|
333
|
+
describe 'four of a kind' do
|
334
|
+
it 'works for the smallest four of a kind' do
|
335
|
+
AcpcPokerTypes::PileOfCards.new(
|
336
|
+
[
|
337
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
338
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
339
|
+
AcpcPokerTypes::Card.from_acpc('2d'),
|
340
|
+
AcpcPokerTypes::Card.from_acpc('2s')
|
341
|
+
]
|
342
|
+
).to_poker_hand_description.must_equal("quad twos")
|
343
|
+
end
|
344
|
+
it 'works for a larger four of a kind' do
|
345
|
+
AcpcPokerTypes::PileOfCards.new(
|
346
|
+
[
|
347
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
348
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
349
|
+
AcpcPokerTypes::Card.from_acpc('Td'),
|
350
|
+
AcpcPokerTypes::Card.from_acpc('Ts'),
|
351
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
352
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
353
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
354
|
+
]
|
355
|
+
).to_poker_hand_description.must_equal("quad tens with six kicker")
|
356
|
+
end
|
357
|
+
end
|
358
|
+
describe 'full house' do
|
359
|
+
it 'works for the smallest full house' do
|
360
|
+
AcpcPokerTypes::PileOfCards.new(
|
361
|
+
[
|
362
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
363
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
364
|
+
AcpcPokerTypes::Card.from_acpc('2d'),
|
365
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
366
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
367
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
368
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
369
|
+
]
|
370
|
+
).to_poker_hand_description.must_equal("twos full of threes")
|
371
|
+
end
|
372
|
+
it 'works for a larger full house' do
|
373
|
+
AcpcPokerTypes::PileOfCards.new(
|
374
|
+
[
|
375
|
+
AcpcPokerTypes::Card.from_acpc('Th'),
|
376
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
377
|
+
AcpcPokerTypes::Card.from_acpc('Td'),
|
378
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
379
|
+
AcpcPokerTypes::Card.from_acpc('6h'),
|
380
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
381
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
382
|
+
]
|
383
|
+
).to_poker_hand_description.must_equal("tens full of sixes")
|
384
|
+
end
|
385
|
+
end
|
386
|
+
describe 'flush' do
|
387
|
+
it 'works for the smallest flush' do
|
388
|
+
AcpcPokerTypes::PileOfCards.new(
|
389
|
+
[
|
390
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
391
|
+
AcpcPokerTypes::Card.from_acpc('3c'),
|
392
|
+
AcpcPokerTypes::Card.from_acpc('4c'),
|
393
|
+
AcpcPokerTypes::Card.from_acpc('5c'),
|
394
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
395
|
+
AcpcPokerTypes::Card.from_acpc('6s'),
|
396
|
+
AcpcPokerTypes::Card.from_acpc('Th')
|
397
|
+
]
|
398
|
+
).to_poker_hand_description.must_equal("seven, five, four, three, two flush")
|
399
|
+
end
|
400
|
+
it 'works for a larger flush' do
|
401
|
+
AcpcPokerTypes::PileOfCards.new(
|
402
|
+
[
|
403
|
+
AcpcPokerTypes::Card.from_acpc('Qc'),
|
404
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
405
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
406
|
+
AcpcPokerTypes::Card.from_acpc('3c'),
|
407
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
408
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
409
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
410
|
+
]
|
411
|
+
).to_poker_hand_description.must_equal("queen, ten, five, three, two flush")
|
412
|
+
end
|
413
|
+
end
|
414
|
+
describe 'straight' do
|
415
|
+
it 'works for the smallest straight' do
|
416
|
+
AcpcPokerTypes::PileOfCards.new(
|
417
|
+
[
|
418
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
419
|
+
AcpcPokerTypes::Card.from_acpc('3h'),
|
420
|
+
AcpcPokerTypes::Card.from_acpc('4s'),
|
421
|
+
AcpcPokerTypes::Card.from_acpc('5d'),
|
422
|
+
AcpcPokerTypes::Card.from_acpc('Ac'),
|
423
|
+
AcpcPokerTypes::Card.from_acpc('8s'),
|
424
|
+
AcpcPokerTypes::Card.from_acpc('Th')
|
425
|
+
]
|
426
|
+
).to_poker_hand_description.must_equal("five-high straight")
|
427
|
+
end
|
428
|
+
it 'works for a larger straight' do
|
429
|
+
AcpcPokerTypes::PileOfCards.new(
|
430
|
+
[
|
431
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
432
|
+
AcpcPokerTypes::Card.from_acpc('Tc'),
|
433
|
+
AcpcPokerTypes::Card.from_acpc('9h'),
|
434
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
435
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
436
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
437
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
438
|
+
]
|
439
|
+
).to_poker_hand_description.must_equal("jack-high straight")
|
440
|
+
end
|
441
|
+
end
|
442
|
+
describe 'three of a kind' do
|
443
|
+
it 'works for the smallest three_of_a_kind' do
|
444
|
+
AcpcPokerTypes::PileOfCards.new(
|
445
|
+
[
|
446
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
447
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
448
|
+
AcpcPokerTypes::Card.from_acpc('2s')
|
449
|
+
]
|
450
|
+
).to_poker_hand_description.must_equal("trip twos")
|
451
|
+
end
|
452
|
+
it 'works for a larger three_of_a_kind' do
|
453
|
+
AcpcPokerTypes::PileOfCards.new(
|
454
|
+
[
|
455
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
456
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
457
|
+
AcpcPokerTypes::Card.from_acpc('Jh'),
|
458
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
459
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
460
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
461
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
462
|
+
]
|
463
|
+
).to_poker_hand_description.must_equal(
|
464
|
+
"trip jacks with eight and seven"
|
465
|
+
)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
describe 'two pair' do
|
469
|
+
it 'works for the smallest two pair' do
|
470
|
+
AcpcPokerTypes::PileOfCards.new(
|
471
|
+
[
|
472
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
473
|
+
AcpcPokerTypes::Card.from_acpc('2h'),
|
474
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
475
|
+
AcpcPokerTypes::Card.from_acpc('3d')
|
476
|
+
]
|
477
|
+
).to_poker_hand_description.must_equal('threes and twos')
|
478
|
+
end
|
479
|
+
it 'works for a larger two pair' do
|
480
|
+
AcpcPokerTypes::PileOfCards.new(
|
481
|
+
[
|
482
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
483
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
484
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
485
|
+
AcpcPokerTypes::Card.from_acpc('Ad'),
|
486
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
487
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
488
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
489
|
+
]
|
490
|
+
).to_poker_hand_description.must_equal('aces and jacks with seven kicker')
|
491
|
+
end
|
492
|
+
end
|
493
|
+
describe 'one pair' do
|
494
|
+
it 'works for the smallest one pair' do
|
495
|
+
AcpcPokerTypes::PileOfCards.new(
|
496
|
+
[
|
497
|
+
AcpcPokerTypes::Card.from_acpc('2c'),
|
498
|
+
AcpcPokerTypes::Card.from_acpc('2h')
|
499
|
+
]
|
500
|
+
).to_poker_hand_description.must_equal('pair of twos')
|
501
|
+
end
|
502
|
+
it 'works for a larger one pair' do
|
503
|
+
AcpcPokerTypes::PileOfCards.new(
|
504
|
+
[
|
505
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
506
|
+
AcpcPokerTypes::Card.from_acpc('Js'),
|
507
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
508
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
509
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
510
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
511
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
512
|
+
]
|
513
|
+
).to_poker_hand_description.must_equal('pair of jacks with ace, eight, and seven')
|
514
|
+
end
|
515
|
+
end
|
516
|
+
describe 'high card' do
|
517
|
+
it 'works for the smallest high card' do
|
518
|
+
AcpcPokerTypes::PileOfCards.new(
|
519
|
+
[
|
520
|
+
AcpcPokerTypes::Card.from_acpc('2c')
|
521
|
+
]
|
522
|
+
).to_poker_hand_description.must_equal('two')
|
523
|
+
end
|
524
|
+
it 'works for a larger high card' do
|
525
|
+
AcpcPokerTypes::PileOfCards.new(
|
526
|
+
[
|
527
|
+
AcpcPokerTypes::Card.from_acpc('Jc'),
|
528
|
+
AcpcPokerTypes::Card.from_acpc('3s'),
|
529
|
+
AcpcPokerTypes::Card.from_acpc('Ah'),
|
530
|
+
AcpcPokerTypes::Card.from_acpc('8d'),
|
531
|
+
AcpcPokerTypes::Card.from_acpc('7c'),
|
532
|
+
AcpcPokerTypes::Card.from_acpc('2s'),
|
533
|
+
AcpcPokerTypes::Card.from_acpc('5c')
|
534
|
+
]
|
535
|
+
).to_poker_hand_description.must_equal('ace, jack, eight, seven, and five')
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
42
539
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
540
|
+
def for_every_card
|
541
|
+
AcpcPokerTypes::Rank::DOMAIN.map do |rank, rank_properties|
|
542
|
+
AcpcPokerTypes::Suit::DOMAIN.map do |suit, suit_properties|
|
543
|
+
yield AcpcPokerTypes::Card.from_components(rank, suit)
|
48
544
|
end
|
49
545
|
end
|
50
546
|
end
|
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.
|
4
|
+
version: 7.5.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:
|
11
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: process_runner
|
@@ -66,20 +66,34 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: inflections
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ~>
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.
|
89
|
+
version: '5.5'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - ~>
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.
|
96
|
+
version: '5.5'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: mocha
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +184,7 @@ files:
|
|
170
184
|
- spec/hand_player_spec.rb
|
171
185
|
- spec/player_spec.rb
|
172
186
|
- spec/pile_of_cards_spec.rb
|
187
|
+
- spec/acpc_poker_types_spec.rb
|
173
188
|
- spec/hand_spec.rb
|
174
189
|
- spec/coverage/assets/0.7.1/magnify.png
|
175
190
|
- spec/coverage/assets/0.7.1/application.js
|
@@ -265,6 +280,7 @@ test_files:
|
|
265
280
|
- spec/hand_player_spec.rb
|
266
281
|
- spec/player_spec.rb
|
267
282
|
- spec/pile_of_cards_spec.rb
|
283
|
+
- spec/acpc_poker_types_spec.rb
|
268
284
|
- spec/hand_spec.rb
|
269
285
|
- spec/coverage/assets/0.7.1/magnify.png
|
270
286
|
- spec/coverage/assets/0.7.1/application.js
|