euler_poker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 006bcaa584aea2730f6321f36e756b4ac45aedc7
4
- data.tar.gz: d528d36fc097becdec5f17cb918537fb6f7582ef
3
+ metadata.gz: 38b3301dbaf9bda8a4c633827de7e2a288dc7409
4
+ data.tar.gz: 2611b9ecd1f325c881dbb2d782ca5893f6a0a5e3
5
5
  SHA512:
6
- metadata.gz: e076703a9c5bbdf0332d187d6d310dd934b5a1575e6d92d88e01b1c5dd48a140eb29e44d8e3f368dba8ca5acb90cc3c332216be3955685f9a800f43795002605
7
- data.tar.gz: 80c2b1989aa4463c28617791bdbe22bd2f6edc508f60d9101e24af2453abbdc841e99cb51ce26c12ac035ddfd64272beb57498853c1d1f4fa4e0e1245bc3b75a
6
+ metadata.gz: f85b4798a5d5b60c3ae8127df8e82c92ad78d37e9fe744e968c9f515f35fe1c3264a286e06586d80940fecb2059d238956b7f8c15cf66eff0f694d25bd85fd82
7
+ data.tar.gz: 4bc4e6155453b205bb79bc771baed5b50d6187b99c3b66da82fab6f1cb6742cdb890c5a66ccb582cc897235b4374ae53a7104295044f2bd6dc6b60808c5d63ed
@@ -1,6 +1,6 @@
1
- require 'euler_poker/hand'
2
- require 'euler_poker/card'
1
+ require 'euler_poker/handable'
3
2
  require 'euler_poker/hand_factory'
3
+ require 'euler_poker/card'
4
4
  require 'euler_poker/round'
5
5
  require 'euler_poker/cli'
6
6
 
@@ -1,5 +1,5 @@
1
1
  module EulerPoker
2
- class Hand
2
+ module Handable
3
3
  include Comparable
4
4
 
5
5
  def initialize(cards)
@@ -7,13 +7,20 @@ module EulerPoker
7
7
  end
8
8
 
9
9
  def <=>(other)
10
- ranking <=> other.ranking
10
+ class_result = class_comparison(other)
11
+ return class_result unless class_result == 0
12
+
13
+ return instance_comparison(other)
11
14
  end
12
15
 
13
16
  def ranking
14
17
  RANKED_HANDS.reverse.index(self.class)
15
18
  end
16
19
 
20
+ def class_comparison(other)
21
+ ranking <=> other.ranking
22
+ end
23
+
17
24
  def ranks
18
25
  @cards.map(&:rank)
19
26
  end
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class Flush < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class Flush
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  descending_ranks <=> other.descending_ranks
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class FourOfAKind < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class FourOfAKind
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  return quartet_rank <=> other.quartet_rank
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class FullHouse < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class FullHouse
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  if triplet_rank == other.triplet_rank
7
7
  return pair_rank <=> other.pair_rank
8
8
  else
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class HighCard < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class HighCard
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  descending_ranks <=> other.descending_ranks
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class OnePair < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class OnePair
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  if pair_rank != other.pair_rank
7
7
  pair_rank <=> other.pair_rank
8
8
  else
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class Straight < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class Straight
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  return ranks.max <=> other.ranks.max
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class StraightFlush < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class StraightFlush
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  return ranks.max <=> other.ranks.max
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class ThreeOfAKind < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class ThreeOfAKind
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  if triplet_rank == other.triplet_rank
7
7
  return ranked_extra_cards <=> other.ranked_extra_cards
8
8
  else
@@ -1,8 +1,8 @@
1
1
  module EulerPoker
2
- class TwoPair < Hand
3
- def <=>(other)
4
- return super unless super == 0
2
+ class TwoPair
3
+ include Handable
5
4
 
5
+ def instance_comparison(other)
6
6
  if high_pair_rank != other.high_pair_rank
7
7
  high_pair_rank <=> other.high_pair_rank
8
8
  elsif low_pair_rank != other.low_pair_rank
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euler_poker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A solution to problem 54 of Project Euler
14
14
  email: rico@toasterlovin.com
@@ -21,8 +21,8 @@ files:
21
21
  - lib/euler_poker.rb
22
22
  - lib/euler_poker/card.rb
23
23
  - lib/euler_poker/cli.rb
24
- - lib/euler_poker/hand.rb
25
24
  - lib/euler_poker/hand_factory.rb
25
+ - lib/euler_poker/handable.rb
26
26
  - lib/euler_poker/hands/flush.rb
27
27
  - lib/euler_poker/hands/four_of_a_kind.rb
28
28
  - lib/euler_poker/hands/full_house.rb