hands 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hands/hand_detection.rb +12 -0
- data/lib/hands/version.rb +1 -1
- data/lib/hands.rb +5 -2
- data/test/units/hand_detection_test.rb +13 -0
- metadata +3 -3
data/lib/hands/hand_detection.rb
CHANGED
@@ -103,6 +103,18 @@ module Hands
|
|
103
103
|
self.straight
|
104
104
|
end
|
105
105
|
|
106
|
+
# @return [Array, Nil] Array of {Card} objects with the royal flush in decending order or `nil` if there isn't a straight flush in the {Hand}
|
107
|
+
def royal_flush
|
108
|
+
# Require a straight flush first
|
109
|
+
sf = self.straight_flush
|
110
|
+
return nil unless sf
|
111
|
+
|
112
|
+
# Make sure the highest card is an ace
|
113
|
+
return nil unless sf.first.value == 'a'
|
114
|
+
|
115
|
+
sf
|
116
|
+
end
|
117
|
+
|
106
118
|
# Hand's index
|
107
119
|
#
|
108
120
|
# Mainly used for internal reasons when comparing {Hand}.
|
data/lib/hands/version.rb
CHANGED
data/lib/hands.rb
CHANGED
@@ -8,7 +8,7 @@ require 'hands/table'
|
|
8
8
|
# See <http://www.pagat.com/poker/rules/ranking.html> for ranking references.
|
9
9
|
module Hands
|
10
10
|
# All card values
|
11
|
-
VALUES = %w{
|
11
|
+
VALUES = %w{2 3 4 5 6 7 8 9 10 j q k a}
|
12
12
|
|
13
13
|
# All card value descriptions
|
14
14
|
VALUE_DESCRIPTIONS = %w{two three four five six seven eight nine ten jack queen king ace}
|
@@ -17,5 +17,8 @@ module Hands
|
|
17
17
|
SUITS = [:clubs, :diamonds, :hearts, :spades]
|
18
18
|
|
19
19
|
# Ranks of poker hands
|
20
|
-
HAND_ORDER = [
|
20
|
+
HAND_ORDER = [
|
21
|
+
:high_card, :pair, :two_pair, :three_of_a_kind, :straight, :flush, :full_house,
|
22
|
+
:four_of_a_kind, :straight_flush, :royal_flush
|
23
|
+
]
|
21
24
|
end
|
@@ -162,4 +162,17 @@ class HandDetectionTest < Hands::TestCase
|
|
162
162
|
hand << Hands::Card[6, :hearts]
|
163
163
|
assert_equal :straight_flush, hand.best_hand[:type]
|
164
164
|
end
|
165
|
+
|
166
|
+
|
167
|
+
#### Royal Flush
|
168
|
+
|
169
|
+
def test_royal_flush
|
170
|
+
hand = Hands::Hand.new
|
171
|
+
hand << Hands::Card[10, :hearts]
|
172
|
+
hand << Hands::Card['j', :hearts]
|
173
|
+
hand << Hands::Card['q', :hearts]
|
174
|
+
hand << Hands::Card['k', :hearts]
|
175
|
+
hand << Hands::Card['a', :hearts]
|
176
|
+
assert_equal :royal_flush, hand.best_hand[:type]
|
177
|
+
end
|
165
178
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
segments:
|
58
58
|
- 0
|
59
|
-
hash:
|
59
|
+
hash: 2894117233871191635
|
60
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
segments:
|
67
67
|
- 0
|
68
|
-
hash:
|
68
|
+
hash: 2894117233871191635
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
71
|
rubygems_version: 1.8.23
|