poker-ranking 1.0.8 → 1.1.0
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.
- data/lib/hand.rb +5 -0
- data/lib/hand_type/base.rb +39 -0
- data/lib/hand_type/flush.rb +6 -2
- data/lib/hand_type/four_of_a_kind.rb +4 -0
- data/lib/hand_type/full_house.rb +4 -0
- data/lib/hand_type/high_card.rb +4 -0
- data/lib/hand_type/pair.rb +4 -0
- data/lib/hand_type/straight.rb +4 -33
- data/lib/hand_type/straight_flush.rb +5 -35
- data/lib/hand_type/three_of_a_kind.rb +3 -0
- data/lib/hand_type/two_pair.rb +5 -1
- data/lib/poker_ranking.rb +1 -1
- metadata +17 -1
data/lib/hand.rb
CHANGED
|
@@ -57,6 +57,10 @@ module PokerRanking
|
|
|
57
57
|
hand_type.name
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
def cards_used
|
|
61
|
+
hand_type.cards_used.sort_by! { |card| card.value }
|
|
62
|
+
end
|
|
63
|
+
|
|
60
64
|
def ==(other)
|
|
61
65
|
cards == other.cards
|
|
62
66
|
end
|
|
@@ -64,6 +68,7 @@ module PokerRanking
|
|
|
64
68
|
def data
|
|
65
69
|
{
|
|
66
70
|
cards: @cards.map { |card| card.data },
|
|
71
|
+
cards_used: cards_used.map { |card| card.data },
|
|
67
72
|
rank: rank,
|
|
68
73
|
value: value,
|
|
69
74
|
second_value: second_value,
|
data/lib/hand_type/base.rb
CHANGED
|
@@ -52,7 +52,46 @@ module PokerRanking
|
|
|
52
52
|
kickers[0..number_of_kickers-1]
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def cards_for_values_and_kickers(*values)
|
|
56
|
+
result = cards.select { |card| not values.include? card.value }
|
|
57
|
+
values.reverse.each do |value|
|
|
58
|
+
result += cards.select { |card| card.value == value }
|
|
59
|
+
end
|
|
60
|
+
result[-5..-1]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def straight_value_of(card_set)
|
|
64
|
+
cards_in_straight = cards_in_straight(card_set)
|
|
65
|
+
|
|
66
|
+
cards_in_straight.empty? ? 0 : cards_in_straight[-1].value
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def cards_in_straight(card_set)
|
|
70
|
+
return [] if card_set.empty?
|
|
71
|
+
|
|
72
|
+
cards_in_streak = []
|
|
73
|
+
cards_in_straight = []
|
|
74
|
+
last_value = 0
|
|
55
75
|
|
|
76
|
+
if card_set[-1].rank == 'Ace'
|
|
77
|
+
cards_in_streak << card_set[-1]
|
|
78
|
+
last_value = 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
card_set.each do |card|
|
|
82
|
+
if cards_in_streak.empty? or card.value == last_value + 1
|
|
83
|
+
cards_in_streak << card
|
|
84
|
+
elsif card.value > last_value
|
|
85
|
+
cards_in_streak = [card]
|
|
86
|
+
end
|
|
87
|
+
last_value = cards_in_streak[-1].value
|
|
88
|
+
|
|
89
|
+
if cards_in_streak.length >= 5
|
|
90
|
+
cards_in_straight = cards_in_streak.clone
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
cards_in_straight
|
|
94
|
+
end
|
|
56
95
|
end
|
|
57
96
|
end
|
|
58
97
|
end
|
data/lib/hand_type/flush.rb
CHANGED
|
@@ -6,7 +6,7 @@ module PokerRanking
|
|
|
6
6
|
|
|
7
7
|
def handles?
|
|
8
8
|
count = { 'Hearts' => 0, 'Clubs' => 0, 'Diamonds' => 0, 'Spades' => 0 }
|
|
9
|
-
|
|
9
|
+
cards.each do |card|
|
|
10
10
|
count[card.suit] += 1
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -27,7 +27,7 @@ module PokerRanking
|
|
|
27
27
|
#only use kickers that are of the suit
|
|
28
28
|
def kickers
|
|
29
29
|
kick = []
|
|
30
|
-
|
|
30
|
+
cards.reverse.each do |card|
|
|
31
31
|
if card.suit == @flush_suit
|
|
32
32
|
kick << card.value
|
|
33
33
|
end
|
|
@@ -42,6 +42,10 @@ module PokerRanking
|
|
|
42
42
|
def name
|
|
43
43
|
'flush'
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
def cards_used
|
|
47
|
+
cards.select { |card| card.suit == @flush_suit }[-5..-1]
|
|
48
|
+
end
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
end
|
data/lib/hand_type/full_house.rb
CHANGED
data/lib/hand_type/high_card.rb
CHANGED
data/lib/hand_type/pair.rb
CHANGED
data/lib/hand_type/straight.rb
CHANGED
|
@@ -3,7 +3,7 @@ module PokerRanking
|
|
|
3
3
|
class Straight < Base
|
|
4
4
|
|
|
5
5
|
def handles?
|
|
6
|
-
|
|
6
|
+
value > 0
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def rank
|
|
@@ -11,45 +11,16 @@ module PokerRanking
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def value
|
|
14
|
-
|
|
14
|
+
straight_value_of cards
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def name
|
|
18
18
|
'straight'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def straight_value
|
|
24
|
-
count = 1
|
|
25
|
-
last_value = 0
|
|
26
|
-
value = 0
|
|
27
|
-
|
|
28
|
-
if has_ace()
|
|
29
|
-
count += 1
|
|
30
|
-
last_value = 1
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
@cards.each do |card|
|
|
34
|
-
if card.value == last_value + 1
|
|
35
|
-
count += 1
|
|
36
|
-
else
|
|
37
|
-
count = 1
|
|
38
|
-
end
|
|
39
|
-
last_value = card.value
|
|
40
|
-
|
|
41
|
-
if count >= 5
|
|
42
|
-
value = card.value
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
value
|
|
21
|
+
def cards_used
|
|
22
|
+
cards_in_straight(cards)[-5..-1]
|
|
46
23
|
end
|
|
47
|
-
|
|
48
|
-
def has_ace
|
|
49
|
-
@cards[-1].rank == 'Ace'
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
|
|
53
24
|
end
|
|
54
25
|
end
|
|
55
26
|
end
|
|
@@ -14,7 +14,7 @@ module PokerRanking
|
|
|
14
14
|
|
|
15
15
|
def value
|
|
16
16
|
SUITS.each do |suit|
|
|
17
|
-
value_for_suit =
|
|
17
|
+
value_for_suit = straight_value_of(cards.select { |card| card.suit == suit })
|
|
18
18
|
return value_for_suit if value_for_suit > 0
|
|
19
19
|
end
|
|
20
20
|
0
|
|
@@ -24,41 +24,11 @@ module PokerRanking
|
|
|
24
24
|
'straight flush'
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
last_value = 0
|
|
32
|
-
value = 0
|
|
33
|
-
|
|
34
|
-
if has_ace_of_suit(suit)
|
|
35
|
-
count += 1
|
|
36
|
-
last_value = 1
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
cards.each do |card|
|
|
40
|
-
if card.suit == suit
|
|
41
|
-
if card.value == last_value + 1
|
|
42
|
-
count += 1
|
|
43
|
-
else
|
|
44
|
-
count = 1
|
|
45
|
-
end
|
|
46
|
-
last_value = card.value
|
|
47
|
-
|
|
48
|
-
if count >= 5
|
|
49
|
-
value = card.value
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
value
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def has_ace_of_suit(suit)
|
|
57
|
-
cards.each do |card|
|
|
58
|
-
return true if card.value == 14 && card.suit == suit
|
|
27
|
+
def cards_used
|
|
28
|
+
SUITS.each do |suit|
|
|
29
|
+
straight_in_suite = cards_in_straight(cards.select { |card| card.suit == suit })
|
|
30
|
+
return straight_in_suite[-5..-1] if straight_in_suite.length >= 5
|
|
59
31
|
end
|
|
60
|
-
|
|
61
|
-
false
|
|
62
32
|
end
|
|
63
33
|
end
|
|
64
34
|
end
|
data/lib/hand_type/two_pair.rb
CHANGED
|
@@ -31,12 +31,16 @@ module PokerRanking
|
|
|
31
31
|
'two pairs'
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def cards_used
|
|
35
|
+
cards_for_values_and_kickers value, second_value
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
private
|
|
35
39
|
|
|
36
40
|
def has_two_pair?
|
|
37
41
|
pair_count = 0
|
|
38
42
|
last_value = 0
|
|
39
|
-
|
|
43
|
+
cards.each do |card|
|
|
40
44
|
if card.value == last_value
|
|
41
45
|
pair_count += 1
|
|
42
46
|
end
|
data/lib/poker_ranking.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: poker-ranking
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -44,6 +44,22 @@ dependencies:
|
|
|
44
44
|
- - ! '>='
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
46
|
version: '0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: codeclimate-test-reporter
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
47
63
|
description: Created for the lean poker project
|
|
48
64
|
email: rafael@ordog.tk
|
|
49
65
|
executables: []
|