hands 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Sam Soffes
1
+ Copyright (c) 2011-2013 Sam Soffes
2
2
 
3
3
  MIT License
4
4
 
@@ -4,7 +4,7 @@ Simple library for calculating poker hands.
4
4
 
5
5
  Currently this gem is very limited. I plan on adding outs, odds, and other actually useful stuff. I started writing this on a plane as a personal challenge. It's current state is crude, although tested and works.
6
6
 
7
- [![Dependency Status](https://gemnasium.com/soffes/hands.png)](https://gemnasium.com/soffes/hands)
7
+ [![Build Status](https://travis-ci.org/soffes/hands.png?branch=master)](undefined) [![Dependency Status](https://gemnasium.com/soffes/hands.png)](https://gemnasium.com/soffes/hands) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/soffes/hands)
8
8
 
9
9
  ## Installation
10
10
 
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- Read the [documentation](http://rubydoc.info/github/samsoffes/hands/master/frames).
27
+ Read the [documentation](http://rubydoc.info/github/soffes/hands/frames/file/Readme.markdown).
28
28
 
29
29
  ``` ruby
30
30
  # Best hand detection
@@ -34,7 +34,7 @@ straight << Hands::Card[2, :spades]
34
34
  straight << Hands::Card[3, :diamonds]
35
35
  straight << Hands::Card[4, :hearts]
36
36
  straight << Hands::Card[5, :clubs]
37
- straight.best_hand[:type] # 'straight'
37
+ straight.best_hand[:type] # :straight
38
38
 
39
39
  # Hand comparison
40
40
  pair = Hands::Hand.new
@@ -8,14 +8,14 @@ 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{ 2 3 4 5 6 7 8 9 10 j q k a }.freeze
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
- VALUE_DESCRIPTIONS = %w{ two three four five six seven eight nine ten jack queen king ace }
14
+ VALUE_DESCRIPTIONS = %w{two three four five six seven eight nine ten jack queen king ace}
15
15
 
16
16
  # Reverse alphabetically ordered suits
17
- SUITES = [:clubs, :diamonds, :hearts, :spades].freeze
17
+ SUITS = [:clubs, :diamonds, :hearts, :spades]
18
18
 
19
19
  # Ranks of poker hands
20
- HAND_ORDER = %w{ high_card pair two_pair three_of_a_kind straight flush full_house four_of_a_kind straight_flush }.freeze
20
+ HAND_ORDER = [:high_card, :pair, :two_pair, :three_of_a_kind, :straight, :flush, :full_house, :four_of_a_kind, :straight_flush]
21
21
  end
@@ -7,7 +7,7 @@ module Hands
7
7
  include Comparable
8
8
 
9
9
  # @return [Symbol] Card's suit
10
- # @see SUITES
10
+ # @see SUITS
11
11
  attr_accessor :suit
12
12
 
13
13
  # Card's value
@@ -68,7 +68,7 @@ module Hands
68
68
  end
69
69
 
70
70
  def suit=(suit)
71
- if (suit.is_a?(String) or suit.is_a?(Symbol)) and SUITES.include?(suit.to_sym)
71
+ if (suit.is_a?(String) or suit.is_a?(Symbol)) and SUITS.include?(suit.to_sym)
72
72
  @suit = suit.to_sym
73
73
  else
74
74
  @suit = nil
@@ -88,7 +88,7 @@ module Hands
88
88
 
89
89
  # @return [Boolean] Does the receiver contain a valid value and suit combination
90
90
  def is_valid?
91
- SUITES.include?(@suit) and VALUES.include?(@value.to_s.downcase)
91
+ SUITS.include?(@suit) and VALUES.include?(@value.to_s.downcase)
92
92
  end
93
93
 
94
94
  # @return [Boolean] Does the receiver contain an invalid value and suit combination
@@ -114,7 +114,7 @@ module Hands
114
114
  # @param [Card] other_card the card to compare the receiver to
115
115
  # @param [Boolean] check_suit a boolean indicating if the suit should be accounted for
116
116
  # @return [Integer] `-1` if `other_card` is less than the receiver, `0` for equal to, and `1` for greater than
117
- # @see SUITES
117
+ # @see SUITS
118
118
  def <=>(other_card, check_suit = false)
119
119
  # TODO: Handle invalid cards
120
120
  result = self.value_index <=> other_card.value_index
@@ -122,14 +122,14 @@ module Hands
122
122
  result
123
123
  end
124
124
 
125
- # Suite's index
125
+ # Suit's index
126
126
  #
127
127
  # Mainly used for internal reasons when comparing cards.
128
128
  #
129
129
  # @return [Integer] index of the card's suit
130
- # @see SUITES
130
+ # @see SUITS
131
131
  def suit_index
132
- SUITES.index(self.suit.downcase)
132
+ SUITS.index(self.suit.downcase)
133
133
  end
134
134
 
135
135
  # Values's index
@@ -7,7 +7,7 @@ module Hands
7
7
  def initialize
8
8
  @cards = []
9
9
  VALUES.each do |value|
10
- SUITES.each do |suit|
10
+ SUITS.each do |suit|
11
11
  @cards << Card[value, suit]
12
12
  end
13
13
  end
@@ -4,6 +4,7 @@ module Hands
4
4
  # Represents a poker hand.
5
5
  class Hand
6
6
  include Comparable
7
+ include HandDetection
7
8
 
8
9
  # @return [Array] {Card}s in the {Hand}
9
10
  attr_accessor :cards
@@ -1,5 +1,5 @@
1
1
  module Hands
2
- class Hand
2
+ module HandDetection
3
3
  # @return [Hash] A hash with `:type` and `:cards` keys.
4
4
  def best_hand
5
5
  response = {}
@@ -115,7 +115,7 @@ module Hands
115
115
  HAND_ORDER.index(best[:type].to_s)
116
116
  end
117
117
 
118
- protected
118
+ protected
119
119
 
120
120
  def duplicates
121
121
  pairs = self.cards.collect(&:value)
@@ -1,4 +1,4 @@
1
1
  module Hands
2
2
  # Gem version
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -9,7 +9,7 @@ class HandDetectionTest < Hands::TestCase
9
9
  hand << Hands::Card[4, :diamonds]
10
10
  hand << Hands::Card[9, :hearts]
11
11
  hand << Hands::Card[9, :clubs]
12
- assert_equal 'two_pair', hand.best_hand[:type]
12
+ assert_equal :two_pair, hand.best_hand[:type]
13
13
  end
14
14
 
15
15
 
@@ -65,7 +65,7 @@ class HandDetectionTest < Hands::TestCase
65
65
  hand << Hands::Card[7, :diamonds]
66
66
  hand << Hands::Card[3, :hearts]
67
67
  hand << Hands::Card[9, :clubs]
68
- assert_equal 'three_of_a_kind', hand.best_hand[:type]
68
+ assert_equal :three_of_a_kind, hand.best_hand[:type]
69
69
  end
70
70
 
71
71
 
@@ -78,7 +78,7 @@ class HandDetectionTest < Hands::TestCase
78
78
  hand << Hands::Card[4, :diamonds]
79
79
  hand << Hands::Card[5, :hearts]
80
80
  hand << Hands::Card[6, :clubs]
81
- assert_equal 'straight', hand.best_hand[:type]
81
+ assert_equal :straight, hand.best_hand[:type]
82
82
  end
83
83
 
84
84
  def test_straight_when_ace_is_low
@@ -88,7 +88,7 @@ class HandDetectionTest < Hands::TestCase
88
88
  hand << Hands::Card[3, :diamonds]
89
89
  hand << Hands::Card[4, :hearts]
90
90
  hand << Hands::Card[5, :clubs]
91
- assert_equal 'straight', hand.best_hand[:type]
91
+ assert_equal :straight, hand.best_hand[:type]
92
92
  end
93
93
 
94
94
  def test_straight_when_ace_is_high
@@ -98,7 +98,7 @@ class HandDetectionTest < Hands::TestCase
98
98
  hand << Hands::Card['Q', :diamonds]
99
99
  hand << Hands::Card['K', :hearts]
100
100
  hand << Hands::Card['A', :clubs]
101
- assert_equal 'straight', hand.best_hand[:type]
101
+ assert_equal :straight, hand.best_hand[:type]
102
102
  end
103
103
 
104
104
  def test_straights_dont_wrap_around
@@ -108,7 +108,7 @@ class HandDetectionTest < Hands::TestCase
108
108
  hand << Hands::Card['K', :hearts]
109
109
  hand << Hands::Card['A', :clubs]
110
110
  hand << Hands::Card[2, :hearts]
111
- assert_equal 'high_card', hand.best_hand[:type]
111
+ assert_equal :high_card, hand.best_hand[:type]
112
112
  end
113
113
 
114
114
 
@@ -121,7 +121,7 @@ class HandDetectionTest < Hands::TestCase
121
121
  hand << Hands::Card[8, :hearts]
122
122
  hand << Hands::Card[2, :hearts]
123
123
  hand << Hands::Card[4, :hearts]
124
- assert_equal 'flush', hand.best_hand[:type]
124
+ assert_equal :flush, hand.best_hand[:type]
125
125
  end
126
126
 
127
127
 
@@ -134,7 +134,7 @@ class HandDetectionTest < Hands::TestCase
134
134
  hand << Hands::Card[7, :diamonds]
135
135
  hand << Hands::Card[9, :spades]
136
136
  hand << Hands::Card[9, :clubs]
137
- assert_equal 'full_house', hand.best_hand[:type]
137
+ assert_equal :full_house, hand.best_hand[:type]
138
138
  end
139
139
 
140
140
 
@@ -147,7 +147,7 @@ class HandDetectionTest < Hands::TestCase
147
147
  hand << Hands::Card[7, :diamonds]
148
148
  hand << Hands::Card[7, :clubs]
149
149
  hand << Hands::Card[9, :clubs]
150
- assert_equal 'four_of_a_kind', hand.best_hand[:type]
150
+ assert_equal :four_of_a_kind, hand.best_hand[:type]
151
151
  end
152
152
 
153
153
 
@@ -160,6 +160,6 @@ class HandDetectionTest < Hands::TestCase
160
160
  hand << Hands::Card[4, :hearts]
161
161
  hand << Hands::Card[5, :hearts]
162
162
  hand << Hands::Card[6, :hearts]
163
- assert_equal 'straight_flush', hand.best_hand[:type]
163
+ assert_equal :straight_flush, hand.best_hand[:type]
164
164
  end
165
165
  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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .travis.yml
22
23
  - .yardopts
23
24
  - Gemfile
24
25
  - LICENSE
@@ -55,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
56
  version: '0'
56
57
  segments:
57
58
  - 0
58
- hash: 3489635347020004355
59
+ hash: -798106606953081479
59
60
  required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  none: false
61
62
  requirements:
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  version: '0'
65
66
  segments:
66
67
  - 0
67
- hash: 3489635347020004355
68
+ hash: -798106606953081479
68
69
  requirements: []
69
70
  rubyforge_project:
70
71
  rubygems_version: 1.8.23