ruby-poker 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/lib/ruby-poker/poker_hand.rb +12 -6
- data/ruby-poker.gemspec +2 -2
- data/test/test_full_house.rb +32 -0
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75efea8a8c606fa75f028780bdefac44f3855d2f
|
4
|
+
data.tar.gz: 3f20045773339569ba68d5bc94ea2308245cd110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a9b9fe4f0e15e16981cc377ff0ba96f172537c9c9ea619b2f076515570c29bc27fccdb7d7a0e550cbf4d61581db8181aaac572a007254b6cd84e350ee629f62
|
7
|
+
data.tar.gz: e90a2a1661cfbc8457ff3bac50c945cea85071b6dd3611a98d4f52d947553cbccb8aa474153e142849bf8c5bc540af1269c955e9e51b9d9fd99f07a0dc5fec05
|
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Poker library in Ruby
|
1
|
+
= Poker library in Ruby {<img src="https://travis-ci.org/robolson/ruby-poker.png?branch=master" alt="Build Status" />}[https://travis-ci.org/robolson/ruby-poker]
|
2
2
|
===
|
3
3
|
|
4
4
|
Author:: {Rob Olson}[https://github.com/robolson]
|
@@ -39,7 +39,7 @@ Place that line near the beginning of your program. The change is program wide s
|
|
39
39
|
|
40
40
|
== Compatibility
|
41
41
|
|
42
|
-
Ruby-Poker is compatible with Ruby 1.8, Ruby 1.9, Ruby 2.
|
42
|
+
Ruby-Poker is compatible with Ruby 1.8, Ruby 1.9, and Ruby 2.X.
|
43
43
|
|
44
44
|
== RDoc
|
45
45
|
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ Rake::TestTask.new do |t|
|
|
3
3
|
t.libs = ['lib']
|
4
4
|
t.verbose = true
|
5
5
|
t.warning = true
|
6
|
-
t.test_files = FileList['test/test_card.rb', 'test/test_poker_hand.rb']
|
6
|
+
t.test_files = FileList['test/test_card.rb', 'test/test_poker_hand.rb', 'test/test_full_house.rb']
|
7
7
|
end
|
8
8
|
|
9
9
|
task :default => :test
|
@@ -105,15 +105,13 @@ class PokerHand
|
|
105
105
|
|
106
106
|
def full_house?
|
107
107
|
if (md = (by_face =~ /(.). \1. \1. (.*)(.). \3./))
|
108
|
-
arranged_hand =
|
109
|
-
md.pre_match + ' ' + md[2] + ' ' + md.post_match)
|
108
|
+
arranged_hand = rearrange_full_house(by_face.cards)
|
110
109
|
[
|
111
110
|
[7, Card::face_value(md[1]), Card::face_value(md[3])],
|
112
111
|
arranged_hand
|
113
112
|
]
|
114
113
|
elsif (md = (by_face =~ /((.). \2.) (.*)((.). \5. \5.)/))
|
115
|
-
arranged_hand =
|
116
|
-
md.pre_match + ' ' + md[3] + ' ' + md.post_match)
|
114
|
+
arranged_hand = rearrange_full_house(by_face.cards)
|
117
115
|
[
|
118
116
|
[7, Card::face_value(md[5]), Card::face_value(md[2])],
|
119
117
|
arranged_hand
|
@@ -139,7 +137,6 @@ class PokerHand
|
|
139
137
|
end
|
140
138
|
|
141
139
|
def straight?
|
142
|
-
result = false
|
143
140
|
if hand.size >= 5
|
144
141
|
transform = delta_transform
|
145
142
|
# note we can have more than one delta 0 that we
|
@@ -154,9 +151,10 @@ class PokerHand
|
|
154
151
|
if (md = (/.(.). 1.. 1.. 1.. 1../.match(transform)))
|
155
152
|
high_card = Card::face_value(md[1])
|
156
153
|
arranged_hand = fix_low_ace_display(md[0] + ' ' + md.pre_match + ' ' + md.post_match)
|
157
|
-
|
154
|
+
return [[5, high_card], arranged_hand]
|
158
155
|
end
|
159
156
|
end
|
157
|
+
false
|
160
158
|
end
|
161
159
|
|
162
160
|
def three_of_a_kind?
|
@@ -505,4 +503,12 @@ class PokerHand
|
|
505
503
|
arranged_hand.gsub(/\s+$/, '')
|
506
504
|
end
|
507
505
|
|
506
|
+
def rearrange_full_house(cards)
|
507
|
+
card_array = cards.split.uniq
|
508
|
+
card_hash = Hash[card_array.collect{|c| [c[0], card_array.count{|n| n[0] == c[0]}]}]
|
509
|
+
arranged_hand = card_array.select{|c| c if c[0] == card_hash.key(3)}
|
510
|
+
arranged_hand += card_array.select{|c| c if c[0] == card_hash.key(2)}
|
511
|
+
(arranged_hand + (card_array - arranged_hand)).join(" ")
|
512
|
+
end
|
513
|
+
|
508
514
|
end
|
data/ruby-poker.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ruby-poker"
|
3
|
-
s.version = "1.0.
|
3
|
+
s.version = "1.0.1"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "Poker library in Ruby"
|
6
6
|
s.description = "Ruby library for comparing poker hands and determining the winner."
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
"Rakefile",
|
19
19
|
"README.rdoc",
|
20
20
|
"ruby-poker.gemspec"]
|
21
|
-
s.test_files = ["test/test_helper.rb", "test/test_card.rb", "test/test_poker_hand.rb"]
|
21
|
+
s.test_files = ["test/test_helper.rb", "test/test_card.rb", "test/test_poker_hand.rb", "test/test_full_house.rb"]
|
22
22
|
s.require_paths << 'lib'
|
23
23
|
|
24
24
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class TestFullHouse < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A Full House should return the correct cards from sort_using_rank" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@fh_high_pair = PokerHand.new("8h 8d 8c Qh Td Kd Ks")
|
9
|
+
@fh_low_pair = PokerHand.new("8h 8d 8c Qh Td 4h 4d")
|
10
|
+
@fh_high_trips = PokerHand.new("Kh Kd Kc Qh Td 8h 8d")
|
11
|
+
@fh_low_trips = PokerHand.new("4h 4d 4c Qh Td Kd Ks")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "full house #sort_using_rank from seven cards (high pair) should return correct cards" do
|
15
|
+
assert_equal("8h 8d 8c Ks Kd Qh Td", @fh_high_pair.sort_using_rank)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "full house #sort_using_rank from seven cards (low pair) should return correct cards" do
|
19
|
+
assert_equal("8h 8d 8c 4h 4d Qh Td", @fh_low_pair.sort_using_rank)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "full house #sort_using_rank from seven cards (high trips) should return correct cards" do
|
23
|
+
assert_equal("Kh Kd Kc 8h 8d Qh Td", @fh_high_trips.sort_using_rank)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "full house #sort_using_rank from seven cards (low trips) should return correct cards" do
|
27
|
+
assert_equal("4h 4d 4c Ks Kd Qh Td", @fh_low_trips.sort_using_rank)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-poker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda-context
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.1'
|
27
27
|
description: Ruby library for comparing poker hands and determining the winner.
|
@@ -34,17 +34,18 @@ extra_rdoc_files:
|
|
34
34
|
- LICENSE
|
35
35
|
files:
|
36
36
|
- CHANGELOG
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
37
40
|
- examples/deck.rb
|
38
41
|
- examples/quick_example.rb
|
39
42
|
- lib/ruby-poker.rb
|
40
43
|
- lib/ruby-poker/card.rb
|
41
44
|
- lib/ruby-poker/poker_hand.rb
|
42
|
-
- LICENSE
|
43
|
-
- Rakefile
|
44
|
-
- README.rdoc
|
45
45
|
- ruby-poker.gemspec
|
46
|
-
- test/test_helper.rb
|
47
46
|
- test/test_card.rb
|
47
|
+
- test/test_full_house.rb
|
48
|
+
- test/test_helper.rb
|
48
49
|
- test/test_poker_hand.rb
|
49
50
|
homepage: https://github.com/robolson/ruby-poker
|
50
51
|
licenses:
|
@@ -52,28 +53,28 @@ licenses:
|
|
52
53
|
metadata: {}
|
53
54
|
post_install_message:
|
54
55
|
rdoc_options:
|
55
|
-
- --title
|
56
|
+
- "--title"
|
56
57
|
- Ruby Poker Documentation
|
57
|
-
- --main
|
58
|
+
- "--main"
|
58
59
|
- README.rdoc
|
59
|
-
- --inline-source
|
60
|
-
- -q
|
60
|
+
- "--inline-source"
|
61
|
+
- "-q"
|
61
62
|
require_paths:
|
62
63
|
- lib
|
63
64
|
- lib
|
64
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- -
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
69
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
71
|
requirements:
|
71
|
-
- -
|
72
|
+
- - ">="
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
requirements: []
|
75
76
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.2.2
|
77
78
|
signing_key:
|
78
79
|
specification_version: 4
|
79
80
|
summary: Poker library in Ruby
|
@@ -81,3 +82,4 @@ test_files:
|
|
81
82
|
- test/test_helper.rb
|
82
83
|
- test/test_card.rb
|
83
84
|
- test/test_poker_hand.rb
|
85
|
+
- test/test_full_house.rb
|