the_gambler 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0
4
+
5
+ Got seven-card hands working.
6
+
7
+ ## 1.0.0
8
+
9
+ Got accurate poker hande valuations for all cases.
10
+
11
+ ## 0.1.0
12
+
13
+ Poker hand evaluation barely working.
data/README.md CHANGED
@@ -27,6 +27,7 @@ Right now, the following stuff works. Assume anything not mentioned in this list
27
27
 
28
28
  * Blackjack hand evaluation
29
29
  * Poker hand evaluation
30
+ * 5 or 7 card hands
30
31
 
31
32
  ## Contributing to `the_gambler`
32
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -95,17 +95,24 @@ module TheGambler
95
95
  end
96
96
 
97
97
  def straight?
98
- values = contents.map(&:numerical_value).sort
99
- values == (values.min..values.max).to_a or values == [2, 3, 4, 5, 14]
98
+ # values = contents.map(&:numerical_value).sort
99
+ # values == (values.min..values.max).to_a or values == [2, 3, 4, 5, 14]
100
+ nums = contents.map(&:numerical_value)
101
+ return true if nums.sort == [2, 3, 4, 5, 14]
102
+
103
+ (2..14).each_cons(5) do |straight|
104
+ return true if (nums & straight).count == 5
105
+ end
100
106
  end
101
107
 
102
108
  def flush?
103
- contents.map(&:suit).uniq.count == 1
109
+ c = contents.group_by(&:suit)
110
+ !! contents.group_by(&:suit).values.detect{|k| k.count == 5}
104
111
  end
105
112
 
106
113
  def full_house?
107
- as_string = contents.sort_by(&:numerical_value).map(&:to_s).join
108
- as_string =~ %r{(.{1,2})[SCHD]\1[SCHD]\1[SCHD](.{1,2})[SCHD]\2[SCHD]} or as_string =~ %r{(.{1,2})[SCHD]\1[SCHD](.{1,2})[SCHD]\2[SCHD]\2[SCHD]}
114
+ c = contents.group_by(&:numerical_value).values.map(&:count)
115
+ c.any?{|x| x == 3} and c.select{|x| x >= 2}.count >= 2
109
116
  end
110
117
 
111
118
  def four_of_a_kind?
@@ -117,7 +124,7 @@ module TheGambler
117
124
  end
118
125
 
119
126
  def royal_flush?
120
- contents.sort_by(&:numerical_value).map(&:to_s).join =~ %r{\A10([SCHD])J\1Q\1K\1A\1\Z}i
127
+ contents.sort_by(&:numerical_value).map(&:to_s).join =~ %r{10([SCHD])J\1Q\1K\1A\1}i
121
128
  end
122
129
 
123
130
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ module TheGambler
4
+ describe Hand do
5
+ context 'seven-card hands' do
6
+ it 'should recognize a royal flush within a seven-card hand' do
7
+ Hand.new(*%w{2D QH KH 4C JH 10H AH}).royal_flush?.should be_true
8
+ end
9
+
10
+ it 'should recognize a straight flush within a seven-card hand' do
11
+ Hand.new(*%w{9H QH KH 4C JH 10H 7D}).straight_flush?.should be_true
12
+ end
13
+
14
+ context 'with four of a kind' do
15
+ it 'should recognize a four of a kind within a seven-card hand' do
16
+ Hand.new(*%w{9D 9H 9C 4C 9S 10H 7D}).four_of_a_kind?.should be_true
17
+ end
18
+
19
+ it 'should recognize four of a kind and three of a kind at the same time as four of a kind only' do
20
+ Hand.new(*%w{9D 9H 9C 4C 9S 4H 4D}).four_of_a_kind?.should be_true
21
+ end
22
+ end
23
+
24
+ context 'with a full house' do
25
+ it 'should recognize a full house within a seven-card hand' do
26
+ Hand.new(*%w{9D 9H 9H 4C 4H 10H 7D}).full_house?.should be_true
27
+ end
28
+
29
+ it 'should recognize a full house within a seven-card hand' do
30
+ Hand.new(*%w{9D 9H 9H 4C 4H 4H 7D}).full_house?.should be_true
31
+ end
32
+ end
33
+
34
+ it 'should recognize a flush within a seven-card hand' do
35
+ Hand.new(*%w{9H QH KH 4C 6H 10H 7D}).flush?.should be_true
36
+ end
37
+
38
+ context 'with a straight' do
39
+ it 'should recognize a straight within a seven-card hand' do
40
+ Hand.new(*%w{9D QH KH JC 6H 10H 7D}).straight?.should be_true
41
+ end
42
+ end
43
+
44
+ it 'should recognize a three of a kind within a seven-card hand' do
45
+ Hand.new(*%w{QD QH QC 4C JH 10H 7D}).three_of_a_kind?.should be_true
46
+ end
47
+
48
+ it 'should recognize a two pair within a seven-card hand' do
49
+ Hand.new(*%w{9D QH 9H 4C 4H 10H QD}).two_pair?.should be_true
50
+ end
51
+
52
+ it 'should recognize a pair within a seven-card hand' do
53
+ Hand.new(*%w{KD QH KH 4C JH 10H 7D}).one_pair?.should be_true
54
+ end
55
+
56
+ it 'should recognize a high card within a seven-card hand' do
57
+ Hand.new(*%w{9D QH KH 4C 2H 10H 7D}).high_card?.should be_true
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "the_gambler"
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["max thom stahl"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ "CHANGELOG.md",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
45
46
  "spec/hands/poker/hand_three_of_a_kind_spec.rb",
46
47
  "spec/hands/poker/hand_two_pair_spec.rb",
47
48
  "spec/hands/poker/kicker_cards_spec.rb",
49
+ "spec/hands/seven_or_nine_card_spec.rb",
48
50
  "spec/players/player_spec.rb",
49
51
  "spec/spec_helper.rb",
50
52
  "spec/support/shared_examples/shared_poker_hands.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_gambler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -118,6 +118,7 @@ extra_rdoc_files:
118
118
  files:
119
119
  - .document
120
120
  - .rspec
121
+ - CHANGELOG.md
121
122
  - Gemfile
122
123
  - Gemfile.lock
123
124
  - LICENSE.txt
@@ -144,6 +145,7 @@ files:
144
145
  - spec/hands/poker/hand_three_of_a_kind_spec.rb
145
146
  - spec/hands/poker/hand_two_pair_spec.rb
146
147
  - spec/hands/poker/kicker_cards_spec.rb
148
+ - spec/hands/seven_or_nine_card_spec.rb
147
149
  - spec/players/player_spec.rb
148
150
  - spec/spec_helper.rb
149
151
  - spec/support/shared_examples/shared_poker_hands.rb
@@ -164,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  segments:
166
168
  - 0
167
- hash: 3691939105348010071
169
+ hash: 9032265535672364
168
170
  required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  none: false
170
172
  requirements: