ofcp_scoring 0.0.2

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.autotest +8 -0
  4. data/.gitignore +2 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +27 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +59 -0
  11. data/Rakefile +1 -0
  12. data/lib/.DS_Store +0 -0
  13. data/lib/ofcp_scoring/chinese_poker_hand.rb +22 -0
  14. data/lib/ofcp_scoring/flush.rb +11 -0
  15. data/lib/ofcp_scoring/four_of_a_kind.rb +10 -0
  16. data/lib/ofcp_scoring/full_house.rb +4 -0
  17. data/lib/ofcp_scoring/hand_categorizer.rb +30 -0
  18. data/lib/ofcp_scoring/hand_evaluator.rb +50 -0
  19. data/lib/ofcp_scoring/hand_factory.rb +12 -0
  20. data/lib/ofcp_scoring/hand_organizer.rb +45 -0
  21. data/lib/ofcp_scoring/high_card.rb +6 -0
  22. data/lib/ofcp_scoring/organized_hand.rb +37 -0
  23. data/lib/ofcp_scoring/pair.rb +16 -0
  24. data/lib/ofcp_scoring/ranked_hand.rb +35 -0
  25. data/lib/ofcp_scoring/royal_flush.rb +3 -0
  26. data/lib/ofcp_scoring/royalties_calculator.rb +38 -0
  27. data/lib/ofcp_scoring/scoring_engine.rb +9 -0
  28. data/lib/ofcp_scoring/straight.rb +14 -0
  29. data/lib/ofcp_scoring/straight_flush.rb +2 -0
  30. data/lib/ofcp_scoring/three_of_a_kind.rb +10 -0
  31. data/lib/ofcp_scoring/two_pair.rb +22 -0
  32. data/lib/ofcp_scoring/version.rb +3 -0
  33. data/lib/ofcp_scoring.rb +9 -0
  34. data/ofcp_scoring-0.0.1.gem +0 -0
  35. data/ofcp_scoring.gemspec +24 -0
  36. data/spec/acceptance_spec.rb +32 -0
  37. data/spec/chinese_poker_hand_categorizer_spec.rb +117 -0
  38. data/spec/chinese_poker_hand_evaluator_spec.rb +69 -0
  39. data/spec/chinese_poker_hand_organizer_spec.rb +19 -0
  40. data/spec/chinese_poker_hand_spec.rb +23 -0
  41. data/spec/chinese_poker_scoring_engine_spec.rb +23 -0
  42. data/spec/hand_factory_spec.rb +22 -0
  43. data/spec/organized_hand_spec.rb +4 -0
  44. data/spec/ranked_hand_spec.rb +159 -0
  45. data/spec/royalties_calculator_spec.rb +103 -0
  46. data/spec/spec_helper.rb +28 -0
  47. metadata +143 -0
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe "Hand Categorization" do
5
+ FakeHandOrganizer = Struct.new(:to_s) do
6
+ def organize(hand)
7
+ return ""
8
+ end
9
+ end
10
+
11
+ FakeOrganizedHand = Struct.new(
12
+ :two_cards_match?,
13
+ :two_different_cards_match?,
14
+ :three_cards_match?,
15
+ :four_cards_match?,
16
+ :all_suits_match?,
17
+ :ranks_in_order?,
18
+ :high_card_ace?,
19
+ :three_card_hand?
20
+ )
21
+
22
+ before(:each) do
23
+ @organizer = FakeHandOrganizer.new
24
+ @sut = OfcpScoring::HandCategorizer.new(@organizer)
25
+ end
26
+
27
+ context "Five Card Hands" do
28
+ it "should return an empty string if no hand is present" do
29
+ expect(@sut.categorize(nil)).to eq("")
30
+ end
31
+ it "should return a Pair when two cards match" do
32
+ hand = FakeOrganizedHand.new(:two_cards_match)
33
+ @organizer.stub(:organize).and_return(hand)
34
+ OfcpScoring::Pair.should_receive(:new).with(hand)
35
+ @sut.categorize(hand)
36
+ end
37
+ it "should return two Pair when two sets of two cards match" do
38
+ hand = FakeOrganizedHand.new(:two_cards_match, :two_different_cards_match)
39
+ @organizer.stub(:organize).and_return(hand)
40
+ OfcpScoring::TwoPair.should_receive(:new).with(hand)
41
+ @sut.categorize(hand)
42
+ end
43
+ it "should return Three Of a Kind when three cards match" do
44
+ hand = FakeOrganizedHand.new(false, false, :three_cards_match)
45
+ @organizer.stub(:organize).and_return(hand)
46
+ OfcpScoring::ThreeOfAKind.should_receive(:new).with(hand)
47
+ @sut.categorize(hand)
48
+ end
49
+ it "should return Four of a kind when four cards match" do
50
+ hand = FakeOrganizedHand.new(false, false, false, :four_cards_match)
51
+ @organizer.stub(:organize).and_return(hand)
52
+ OfcpScoring::FourOfAKind.should_receive(:new).with(hand)
53
+ @sut.categorize(hand)
54
+ end
55
+ it "should return Full House when three cards match and two cards match" do
56
+ hand = FakeOrganizedHand.new(:two_cards_match, false, :three_cards_match)
57
+ @organizer.stub(:organize).and_return(hand)
58
+ OfcpScoring::FullHouse.should_receive(:new).with(hand)
59
+ @sut.categorize(hand)
60
+ end
61
+ it "should return High Card when no cards match" do
62
+ hand = FakeOrganizedHand.new(false, false, false, false)
63
+ @organizer.stub(:organize).and_return(hand)
64
+ OfcpScoring::HighCard.should_receive(:new).with(hand)
65
+ @sut.categorize(hand)
66
+ end
67
+ it "should return OfcpScoring::Flush when suits all same" do
68
+ hand = FakeOrganizedHand.new(false, false, false, false, :all_suits_match)
69
+ @organizer.stub(:organize).and_return(hand)
70
+ OfcpScoring::Flush.should_receive(:new).with(hand)
71
+ @sut.categorize(hand)
72
+ end
73
+ it "should return Straight when all five cards are in sequential order" do
74
+ hand = FakeOrganizedHand.new(false, false, false, false, false, :ranks_in_order)
75
+ @organizer.stub(:organize).and_return(hand)
76
+ OfcpScoring::Straight.should_receive(:new).with(hand)
77
+ @sut.categorize(hand)
78
+ end
79
+ it "should return a StraightFlush when all five cards are in sequential order and all suits match" do
80
+ hand = FakeOrganizedHand.new(false, false, false, false, :all_suits_match, :ranks_in_order)
81
+ @organizer.stub(:organize).and_return(hand)
82
+ OfcpScoring::StraightFlush.should_receive(:new).with(hand)
83
+ @sut.categorize(hand)
84
+ end
85
+ it "should return a RoyalFlush when all five cards are in sequential order, all suits match and highest rank is an Ace" do
86
+ hand = FakeOrganizedHand.new(false, false, false, false, :all_suits_match, :ranks_in_order, :high_card_ace)
87
+ @organizer.stub(:organize).and_return(hand)
88
+ OfcpScoring::RoyalFlush.should_receive(:new).with(hand)
89
+ @sut.categorize(hand)
90
+ end
91
+ end
92
+ context "Three Card Hands" do
93
+ it "should never return a flush" do
94
+ hand = FakeOrganizedHand.new(false, false, false, false, :all_suits_match, :ranks_in_order, :high_card_ace, :three_card_hand)
95
+ @organizer.stub(:organize).and_return(hand)
96
+ OfcpScoring::HighCard.should_receive(:new).with(hand)
97
+ @sut.categorize(hand)
98
+ end
99
+ it "should never return a straight" do
100
+ hand = FakeOrganizedHand.new(false, false, false, false, false, :ranks_in_order, :high_card_ace, :three_card_hand)
101
+ @organizer.stub(:organize).and_return(hand)
102
+ OfcpScoring::HighCard.should_receive(:new).with(hand)
103
+ @sut.categorize(hand)
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+
110
+ describe "Integration" do
111
+ it "should categorized unorganized hands correctly" do
112
+ sut = OfcpScoring::HandCategorizer.new
113
+ # expect(sut.categorize(%w(Ah 4s Qs))).to be_a(OfcpScoring::HighCard)
114
+ # expect(sut.categorize(%w(2h 3h 4h 5h 7h))).to be_a(OfcpScoring::Flush)
115
+ expect(sut.categorize(%w(Kh Kd Ks 9c 9s))).to be_a(OfcpScoring::FullHouse)
116
+ end
117
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ ScorableHand = Struct.new(:front,:middle, :back, :misset?)
4
+
5
+
6
+ describe "Evaluator" do
7
+ before(:each) do
8
+ @hand_one = %w(Ah Ks Qs 10s 10d 7d 6c 8h Qc Qd Ad 2c 4d)
9
+ @hand_two = %w(9h 9c Qs 10s 10d 7d 6c 8h Qc Qd Ad 2c 4d)
10
+ @sut = OfcpScoring::HandEvaluator.new(FakeFactory.new, FakeRoyaltyCalculator.new)
11
+ end
12
+ it "should evaluate the front hands" do
13
+ expect(@sut.evaluate(ScorableHand.new(1,0,0), ScorableHand.new(0,1,1))).to eq([1,2])
14
+ end
15
+ it "should evaluate the middle hands" do
16
+ expect(@sut.evaluate(ScorableHand.new(1,0,0), ScorableHand.new(0,1,0))).to eq([1,1])
17
+ end
18
+ it "should evaluate the back hands" do
19
+ expect(@sut.evaluate(ScorableHand.new(1,1,0), ScorableHand.new(0,0,1))).to eq([2,1])
20
+ end
21
+ it "should add a scoop bonus" do
22
+ expect(@sut.evaluate(ScorableHand.new(1,1,1), ScorableHand.new(0,0,0))).to eq([6,0])
23
+ end
24
+ it "should give no points for misset hands" do
25
+ expect(@sut.evaluate(ScorableHand.new(1,1,1, true), ScorableHand.new(0,0,0))).to eq([0,6])
26
+ expect(@sut.evaluate(ScorableHand.new(1,1,1), ScorableHand.new(0,0,0, true))).to eq([6,0])
27
+ end
28
+ end
29
+
30
+ describe "Royalties Calculation" do
31
+ it "should add royalties for a hand when it wins" do
32
+ royalty_calc = double(OfcpScoring::RoyaltiesCalculator, :calculate_bonus => 0)
33
+ sut = OfcpScoring::HandEvaluator.new(FakeFactory.new, royalty_calc)
34
+ royalty_calc.should_receive(:calculate_bonus).once.with(1, :front)
35
+ royalty_calc.should_receive(:calculate_bonus).once.with(1, :middle)
36
+ royalty_calc.should_receive(:calculate_bonus).once.with(1, :back)
37
+ sut.evaluate(ScorableHand.new(1,0,1), ScorableHand.new(0,1,0))
38
+ end
39
+
40
+ it "should add the royalties for the first hand to its score" do
41
+ royalty_calc = OfcpScoring::RoyaltiesCalculator.new
42
+ royalty_calc.stub(:calculate_bonus).and_return(10)
43
+ sut = OfcpScoring::HandEvaluator.new(FakeFactory.new, royalty_calc)
44
+ expect(sut.evaluate(ScorableHand.new(1,0,1), ScorableHand.new(0,1,0))).to eq([22,11])
45
+ end
46
+
47
+ end
48
+
49
+ describe "Integration" do
50
+ it "should score front, middle and back hands" do
51
+ @hand_one = %w(Ah Ks Qs 8s 8d 7d 6c 4h Jc Jd Ad 2c 4d)
52
+ @hand_two = %w(9h 6c Qs 10s 10d 7d 6c 8h Qc Qd Ad 2c 4d)
53
+
54
+ sut = OfcpScoring::HandEvaluator.new
55
+ expect(sut.evaluate(@hand_one, @hand_two)).to eq([1,2])
56
+ end
57
+ end
58
+
59
+ class FakeFactory
60
+ def build(hand)
61
+ hand
62
+ end
63
+ end
64
+
65
+ class FakeRoyaltyCalculator
66
+ def calculate_bonus(hand, position)
67
+ 0
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Hand Organizer" do
4
+ it "should return am empty string if no hand is present" do
5
+ sut = OfcpScoring::HandOrganizer.new
6
+ expect(sut.organize(nil)).to eq("")
7
+ end
8
+ end
9
+
10
+ describe "Integration" do
11
+ it "should organize hands" do
12
+ hand = %w(Qc Qd Ad 2c 4d)
13
+ sut = OfcpScoring::HandOrganizer.new
14
+ organized = sut.organize(hand)
15
+ expect(organized.two_cards_match?).to be
16
+ expect(organized.two_different_cards_match?).to_not be
17
+ expect(organized.ranks).to eq([1,2,4,12,12])
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Chinese Poker Hands" do
4
+ it "should know when it is misset" do
5
+ sut = OfcpScoring::ChinesePokerHand.new({
6
+ :front => OfcpScoring::ThreeOfAKind.new({:ranks => [9,9,9]}),
7
+ :middle => OfcpScoring::Pair.new({:ranks => [2,3,5,8,8]}),
8
+ :back => OfcpScoring::HighCard.new({:ranks => [2,3,4,5,7]})
9
+ })
10
+
11
+ expect(sut.misset?).to be
12
+ end
13
+
14
+ it "should know when it is not misset" do
15
+ sut = OfcpScoring::ChinesePokerHand.new({
16
+ :back => OfcpScoring::ThreeOfAKind.new({:ranks => [9,9,9,5,7]}),
17
+ :middle => OfcpScoring::Pair.new({:ranks => [2,3,5,8,8]}),
18
+ :front => OfcpScoring::HighCard.new({:ranks => [2,3,4]})
19
+ })
20
+
21
+ expect(sut.misset?).to_not be
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Chinese Poker Scoring Engine" do
4
+ before(:each) do
5
+ @sut = OfcpScoring::ScoringEngine.new
6
+ @hand_one = %w(Ah Ks Qs 10s 10d 7d 6c 8h Qc Qd Ad 2c 4d)
7
+ @hand_two = %w(9h 9c Qs 10s 10d 7d 6c 8h Qc Qd Ad 2c 4d)
8
+ end
9
+ it "should return no score for nil hands" do
10
+ expect(@sut.score(nil, nil)).to eq([0,0])
11
+ end
12
+ it "should return no score for one nil hand" do
13
+ expect(@sut.score(nil, 0)).to eq([0,0])
14
+ end
15
+ it "should use a hand evaluator to compare and score the hands" do
16
+ evaluator = double(OfcpScoring::HandEvaluator, :evaluate => [2,1])
17
+ evaluator.should_receive(:evaluate).with(@hand_one, @hand_two)
18
+
19
+ sut = OfcpScoring::ScoringEngine.new(evaluator)
20
+ sut.score(@hand_one, @hand_two)
21
+ end
22
+ end
23
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Building Hands" do
4
+ it "should build Chinese Poker Hands" do
5
+ sut = OfcpScoring::HandFactory.new(FakeCategorizer.new)
6
+ OfcpScoring::ChinesePokerHand.should_receive(:new)
7
+ sut.build(%w())
8
+ end
9
+ it "should use an categorizer to categorize the hand" do
10
+ categorizer = double(OfcpScoring::HandCategorizer, :categorize => {})
11
+ categorizer.should_receive(:categorize).with(%w())
12
+ sut = OfcpScoring::HandFactory.new(categorizer)
13
+ sut.build(%w())
14
+ end
15
+ end
16
+
17
+
18
+ class FakeCategorizer
19
+ def categorize(hand)
20
+ hand
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Organized Hands" do
4
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ class HandWithRankings
4
+ def initialize(ranks)
5
+ @ranks = ranks
6
+ end
7
+ def ranks
8
+ @ranks
9
+ end
10
+ def grouped_ranks
11
+ @ranks.group_by{|c| c}
12
+ end
13
+ end
14
+
15
+ describe "Ranked Hands" do
16
+
17
+ it "should rank RoyalFlushes above Straight Flushes" do
18
+ royal_flush = OfcpScoring::RoyalFlush.new
19
+ straight_flush = OfcpScoring::StraightFlush.new
20
+
21
+ expect(royal_flush > straight_flush).to be
22
+ end
23
+
24
+ it "should rank Straight Flushes above Four of a Kind" do
25
+ straight_flush = OfcpScoring::StraightFlush.new
26
+ four_of_a_kind = OfcpScoring::FourOfAKind.new
27
+
28
+ expect(straight_flush > four_of_a_kind).to be
29
+ end
30
+
31
+ it "should rank a Full House over a Pair" do
32
+ full_house = OfcpScoring::FullHouse.new
33
+ pair = OfcpScoring::Pair.new
34
+
35
+ expect(full_house > pair).to be
36
+ end
37
+
38
+ it "should rank a Flush over a Pair" do
39
+ flush = OfcpScoring::Flush.new
40
+ pair = OfcpScoring::Pair.new
41
+
42
+ expect(pair < flush).to be
43
+ end
44
+
45
+ it "should rank TwoPair over a Pair" do
46
+ two_pair = OfcpScoring::TwoPair.new
47
+ pair = OfcpScoring::Pair.new
48
+
49
+ expect(pair < two_pair).to be
50
+ end
51
+
52
+ context "Breaking Ties" do
53
+ context "When comparing High Card Hands" do
54
+ it "the higest card should be greater" do
55
+ ace_high = OfcpScoring::HighCard.new(HandWithRankings.new([6,7,8,9,14]))
56
+ king_high = OfcpScoring::HighCard.new(HandWithRankings.new([6,7,8,9,13]))
57
+ expect(ace_high > king_high).to be
58
+ expect(king_high < ace_high).to be
59
+ end
60
+ end
61
+ context "When comparing Pairs" do
62
+ it "should compare the value of the paired card" do
63
+ eights = OfcpScoring::Pair.new(HandWithRankings.new([6,7,8,8,13]))
64
+ sixes = OfcpScoring::Pair.new(HandWithRankings.new([6,6,8,9,14]))
65
+ expect(eights > sixes).to be
66
+ expect(sixes < eights).to be
67
+ end
68
+ it "should break ties of pairs by comparing the rest of the cards" do
69
+ with_six = OfcpScoring::Pair.new(HandWithRankings.new([6,8,8,13,14]))
70
+ with_five = OfcpScoring::Pair.new(HandWithRankings.new([5,8,8,13,14]))
71
+ expect(with_six > with_five).to be
72
+ expect(with_five < with_six).to be
73
+ end
74
+ end
75
+ context "When comparing TwoPair Hands" do
76
+ it "should compare the value of the highest paired card of the highest pair" do
77
+ eights_and_sixes = OfcpScoring::TwoPair.new(HandWithRankings.new([6,6,8,8,14]))
78
+ fives_and_fours = OfcpScoring::TwoPair.new(HandWithRankings.new([4,4,5,5,14]))
79
+ expect(eights_and_sixes > fives_and_fours).to be
80
+ expect(fives_and_fours < eights_and_sixes).to be
81
+ end
82
+ it "should first break ties of pairs by comparing the lower pair" do
83
+ eights_and_sixes = OfcpScoring::TwoPair.new(HandWithRankings.new([6,6,8,8,14]))
84
+ eights_and_fours = OfcpScoring::TwoPair.new(HandWithRankings.new([4,4,8,8,14]))
85
+ expect(eights_and_sixes > eights_and_fours).to be
86
+ expect(eights_and_fours < eights_and_sixes).to be
87
+ end
88
+ it "should lastly break ties of pairs by comparing the other cards" do
89
+ with_ace = OfcpScoring::TwoPair.new(HandWithRankings.new([6,6,8,8,14]))
90
+ with_jack = OfcpScoring::TwoPair.new(HandWithRankings.new([6,6,8,8,11]))
91
+ expect(with_ace > with_jack).to be
92
+ expect(with_jack < with_ace).to be
93
+ end
94
+ end
95
+ context "When comparing Three of a Kind Hands" do
96
+ it "should compare the value of the three cards" do
97
+ eights = OfcpScoring::ThreeOfAKind.new(HandWithRankings.new([6,8,8,8,13]))
98
+ sixes = OfcpScoring::ThreeOfAKind.new(HandWithRankings.new([6,6,6,9,14]))
99
+ expect(eights > sixes).to be
100
+ expect(sixes < eights).to be
101
+ end
102
+ end
103
+ context "When comparing Full Houses" do
104
+ it "should use the value of the trip cards" do
105
+ eights = OfcpScoring::ThreeOfAKind.new(HandWithRankings.new([5,8,8,8,5]))
106
+ sixes = OfcpScoring::ThreeOfAKind.new(HandWithRankings.new([6,6,6,9,9]))
107
+ expect(eights > sixes).to be
108
+ expect(sixes < eights).to be
109
+ end
110
+ end
111
+ context "When comparing Four of a Kind Hands" do
112
+ it "should compare the value of the four cards" do
113
+ eights = OfcpScoring::FourOfAKind.new(HandWithRankings.new([8,8,8,8,13]))
114
+ sixes = OfcpScoring::FourOfAKind.new(HandWithRankings.new([6,6,6,6,14]))
115
+ expect(eights > sixes).to be
116
+ expect(sixes < eights).to be
117
+ end
118
+ end
119
+ context "When comparing OfcpScoring::Flushes" do
120
+ it "should compare the highest card" do
121
+ ten_high = OfcpScoring::Flush.new(HandWithRankings.new([2,3,4,5,10]))
122
+ eight_high = OfcpScoring::Flush.new(HandWithRankings.new([2,3,4,5,8]))
123
+ expect(ten_high > eight_high).to be
124
+ expect(eight_high < ten_high).to be
125
+ end
126
+ end
127
+ context "When comparing straights" do
128
+ it "should use the highest card when an ace is not involved" do
129
+ ten_high = OfcpScoring::Straight.new(HandWithRankings.new([2,3,4,5,10]))
130
+ eight_high = OfcpScoring::Straight.new(HandWithRankings.new([2,3,4,5,8]))
131
+ expect(ten_high > eight_high).to be
132
+ expect(eight_high < ten_high).to be
133
+ end
134
+ context "When there is an ace" do
135
+ it "should rank broadway straights above king high straights" do
136
+ broadway = OfcpScoring::Straight.new(HandWithRankings.new([10,11,12,13,14]))
137
+ king_high = OfcpScoring::Straight.new(HandWithRankings.new([9,10,11,12,13]))
138
+ expect(broadway > king_high).to be
139
+ expect(king_high < broadway).to be
140
+ end
141
+ it "should rank six high straights above wheel straights" do
142
+ six_high = OfcpScoring::Straight.new(HandWithRankings.new([2,3,4,5,6]))
143
+ wheel = OfcpScoring::Straight.new(HandWithRankings.new([14,2,3,4,5]))
144
+ expect(six_high > wheel).to be
145
+ expect(wheel < six_high).to be
146
+ end
147
+ end
148
+ end
149
+ context "When comparing straight flushes" do
150
+ it "should use the highest card" do
151
+ ten_high = OfcpScoring::StraightFlush.new(HandWithRankings.new([2,3,4,5,10]))
152
+ eight_high = OfcpScoring::StraightFlush.new(HandWithRankings.new([2,3,4,5,8]))
153
+ expect(ten_high > eight_high).to be
154
+ expect(eight_high < ten_high).to be
155
+ end
156
+ end
157
+ end
158
+
159
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ FakeHand = Struct.new(:class, :ranks) do
4
+ def rank_name
5
+ self.class
6
+ end
7
+ end
8
+
9
+ describe "Royalties Calculations" do
10
+ before(:each) do
11
+ @sut = OfcpScoring::RoyaltiesCalculator.new
12
+ end
13
+ describe "For Front Hands" do
14
+ it "should give an extra point for a pair of sixes" do
15
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [6]), :front)).to eq(1)
16
+ end
17
+ it "should give two extra points for a pair of sevens" do
18
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [7]), :front)).to eq(2)
19
+ end
20
+ it "should give three extra points for a pair of eights" do
21
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [8]), :front)).to eq(3)
22
+ end
23
+ it "should give 9 extra points for a pair of Aces" do
24
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [14]), :front)).to eq(9)
25
+ end
26
+ it "should give no extra points for high card hands" do
27
+ expect(@sut.calculate_bonus(FakeHand.new("HighCard", [14]), :front)).to eq(0)
28
+ end
29
+ end
30
+
31
+ describe "For Middle Hands" do
32
+ it "should not give any bonus for a pair" do
33
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [14]), :middle)).to eq(0)
34
+ end
35
+ it "should give 20 extra points for a straight flush in the middle" do
36
+ expect(@sut.calculate_bonus(FakeHand.new("StraightFlush"), :middle)).to eq(20)
37
+ end
38
+ it "should give 16 extra points for Quads in the middle" do
39
+ expect(@sut.calculate_bonus(FakeHand.new("FourOfAKind"), :middle)).to eq(16)
40
+ end
41
+ it "should give 12 extra points for a full house in the middle" do
42
+ expect(@sut.calculate_bonus(FakeHand.new("FullHouse"), :middle)).to eq(12)
43
+ end
44
+ it "should give 8 extra points for a flush in the middle" do
45
+ expect(@sut.calculate_bonus(FakeHand.new("Flush"), :middle)).to eq(8)
46
+ end
47
+ it "should give 12 extra points for a straight in the middle" do
48
+ expect(@sut.calculate_bonus(FakeHand.new("Straight"), :middle)).to eq(4)
49
+ end
50
+ end
51
+ describe "For Back Hands" do
52
+ it "should not give any bonus for a pair" do
53
+ expect(@sut.calculate_bonus(FakeHand.new("Pair", [14]), :back)).to eq(0)
54
+ end
55
+ it "should give 20 extra points for a royal flush in the back" do
56
+ expect(@sut.calculate_bonus(FakeHand.new("RoyalFlush"), :back)).to eq(20)
57
+ end
58
+ it "should give 10 extra points for a straight flush in the back" do
59
+ expect(@sut.calculate_bonus(FakeHand.new("StraightFlush"), :back)).to eq(10)
60
+ end
61
+ it "should give 8 extra points for Quads in the back" do
62
+ expect(@sut.calculate_bonus(FakeHand.new("FourOfAKind"), :back)).to eq(8)
63
+ end
64
+ it "should give 6 extra points for a full house in the back" do
65
+ expect(@sut.calculate_bonus(FakeHand.new("FullHouse"), :back)).to eq(6)
66
+ end
67
+ it "should give 4 extra points for a flush in the back" do
68
+ expect(@sut.calculate_bonus(FakeHand.new("Flush"), :back)).to eq(4)
69
+ end
70
+ it "should give 2 extra points for a straight in the back" do
71
+ expect(@sut.calculate_bonus(FakeHand.new("Straight"), :back)).to eq(2)
72
+ end
73
+ end
74
+ end
75
+
76
+ # With Royalties you receive the following points for Back hands:
77
+
78
+ # 20 for a Royal
79
+ # 10 for StraightFlush
80
+ # 8 for Quads
81
+ # 6 for a Full House
82
+ # 4 for a OfcpScoring::Flush
83
+ # 2 for a Straight
84
+ # (Some players might play 10 for Quads, 15 for a StraightFlush, and 25 for a Royal, so it is wise to agree the Royalites system beforehand just in case)
85
+
86
+ # You receive the following points for Middle hands:
87
+
88
+ # 20 for StraightFlush
89
+ # 16 for Quads
90
+ # 2 for a Full House
91
+ # 8 for a OfcpScoring::Flush
92
+ # 4 for a Straight
93
+ # You receive the following points for Front hands (the 3 card hand):
94
+
95
+ # Pair of Aces: 9 points
96
+ # Pair of Kings: 8 points
97
+ # Pair of Queens: 7 points
98
+ # Pair of Jacks: 6 points
99
+ # Pair of Tens: 5 points
100
+ # Pair of Nines: 4 points
101
+ # Pair of Eights: 3 points
102
+ # Pair of Sevens: 2 points
103
+ # Paid of Sixes: 1 point
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ rescue LoadError => e
7
+
8
+ end
9
+
10
+ # This file was generated by the `rspec --init` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # Require this file using `require "spec_helper"` to ensure that it is only
13
+ # loaded once.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ config.filter_run :focus
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, you can fix the order by providing
23
+ # the seed, which is printed after each run.
24
+ # --seed 1234
25
+ config.order = 'random'
26
+ end
27
+
28
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ofcp_scoring.rb')