Skip to content

Commit 1d25891

Browse files
committed
Changed to more closely match the rules people know. I thought it was an unnecessary distraction that they were changed.
1 parent f165d3f commit 1d25891

File tree

11 files changed

+122
-108
lines changed

11 files changed

+122
-108
lines changed

README.md

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
This Refactoring Kata was designed by Jon Jagger and is available in his Cyber-Dojo. See [his blog post](http://jonjagger.blogspot.co.uk/2012/05/yahtzee-cyber-dojo-refactoring-in-java.html)
44

5-
The other language translations have been contributed by:
5+
I have changed it a little, so that the rules more closely match the original game.
66

7-
Python: Emily Bache
7+
The other language translations have been contributed by:
88

9-
Ruby: Kim Persson and Lennart Fridén
9+
- Python: Emily Bache
10+
- Ruby: Kim Persson and Lennart Fridén
1011

1112
## Kata: Yahtzee rules
1213

@@ -43,74 +44,85 @@ highest scoring category for a given roll.
4344

4445
## Kata: Yahzee Categories and Scoring Rules
4546

46-
_Note these rules differ from the original (copyrighted) rules_
47-
48-
Chance:
49-
The player scores the sum of all dice,
50-
no matter what they read.
51-
For example,
52-
1,1,3,3,6 placed on "chance" scores 14 (1+1+3+3+6)
53-
4,5,5,6,1 placed on "chance" scores 21 (4+5+5+6+1)
54-
55-
Yahtzee:
56-
If all dice have the same number,
57-
the player scores 50 points.
58-
For example,
59-
1,1,1,1,1 placed on "yahtzee" scores 50
60-
1,1,1,2,1 placed on "yahtzee" scores 0
61-
62-
Ones, Twos, Threes, Fours, Fives, Sixes:
63-
The player scores the sum of the dice that reads one,
64-
two, three, four, five or six, respectively.
65-
For example,
66-
1,1,2,4,4 placed on "fours" scores 8 (4+4)
67-
2,3,2,5,1 placed on "twos" scores 4 (2+2)
68-
3,3,3,4,5 placed on "ones" scores 0
69-
70-
Pair:
71-
The player scores the sum of the two highest matching dice.
72-
For example, when placed on "pair"
73-
3,3,3,4,4 scores 8 (4+4)
74-
1,1,6,2,6 scores 12 (6+6)
75-
3,3,3,4,1 scores 0
76-
3,3,3,3,1 scores 0
77-
78-
Two pairs:
79-
If there are two pairs of dice with the same number, the
80-
player scores the sum of these dice.
81-
For example, when placed on "two pairs"
82-
1,1,2,3,3 scores 8 (1+1+3+3)
83-
1,1,2,3,4 scores 0
84-
1,1,2,2,2 scores 0
85-
86-
Three of a kind:
87-
If there are three dice with the same number, the player
88-
scores the sum of these dice.
89-
For example, when placed on "three of a kind"
90-
3,3,3,4,5 scores 9 (3+3+3)
91-
3,3,4,5,6 scores 0
92-
3,3,3,3,1 scores 0
93-
94-
Four of a kind:
95-
If there are four dice with the same number, the player
96-
scores the sum of these dice.
97-
For example, when placed on "four of a kind"
98-
2,2,2,2,5 scores 8 (2+2+2+2)
99-
2,2,2,5,5 scores 0
100-
2,2,2,2,2 scores 0
101-
102-
Small straight:
103-
When placed on "small straight", if the dice read
104-
1,2,3,4,5, the player scores 15 (the sum of all the dice.
105-
106-
Large straight:
107-
When placed on "large straight", if the dice read
108-
2,3,4,5,6, the player scores 20 (the sum of all the dice).
109-
110-
Full house:
111-
If the dice are two of a kind and three of a kind, the
112-
player scores the sum of all the dice.
113-
For example, when placed on "full house"
114-
1,1,2,2,2 scores 8 (1+1+2+2+2)
115-
2,2,3,3,4 scores 0
116-
4,4,4,4,4 scores 0
47+
### Chance:
48+
The player scores the sum of all dice, no matter what they read.
49+
For example:
50+
51+
- 1,1,3,3,6 placed on "chance" scores 14 (1+1+3+3+6)
52+
- 4,5,5,6,1 placed on "chance" scores 21 (4+5+5+6+1)
53+
54+
### Yahtzee:
55+
If all dice have the same number,
56+
the player scores 50 points.
57+
For example:
58+
59+
- 1,1,1,1,1 placed on "yahtzee" scores 50
60+
- 1,1,1,2,1 placed on "yahtzee" scores 0
61+
62+
### Ones, Twos, Threes, Fours, Fives, Sixes:
63+
The player scores the sum of the dice that reads one,
64+
two, three, four, five or six, respectively.
65+
For example:
66+
67+
- 1,1,2,4,4 placed on "fours" scores 8 (4+4)
68+
- 2,3,2,5,1 placed on "twos" scores 4 (2+2)
69+
- 3,3,3,4,5 placed on "ones" scores 0
70+
71+
### Pair:
72+
The player scores the sum of the two highest matching dice.
73+
For example, when placed on "pair":
74+
75+
- 3,3,3,4,4 scores 8 (4+4)
76+
- 1,1,6,2,6 scores 12 (6+6)
77+
- 3,3,3,4,1 scores 6 (3+3)
78+
- 3,3,3,3,1 scores 6 (3+3)
79+
80+
### Two pairs:
81+
If there are two pairs of dice with the same number, the
82+
player scores the sum of these dice.
83+
For example, when placed on "two pairs":
84+
85+
- 1,1,2,3,3 scores 8 (1+1+3+3)
86+
- 1,1,2,3,4 scores 0
87+
- 1,1,2,2,2 scores 6 (1+1+2+2)
88+
89+
### Three of a kind:
90+
If there are three dice with the same number, the player
91+
scores the sum of these dice.
92+
For example, when placed on "three of a kind":
93+
94+
- 3,3,3,4,5 scores 9 (3+3+3)
95+
- 3,3,4,5,6 scores 0
96+
- 3,3,3,3,1 scores 9 (3+3+3)
97+
98+
### Four of a kind:
99+
If there are four dice with the same number, the player
100+
scores the sum of these dice.
101+
For example, when placed on "four of a kind":
102+
103+
- 2,2,2,2,5 scores 8 (2+2+2+2)
104+
- 2,2,2,5,5 scores 0
105+
- 2,2,2,2,2 scores 8 (2+2+2+2)
106+
107+
### Small straight:
108+
When placed on "small straight", if the dice read
109+
110+
1,2,3,4,5,
111+
112+
the player scores 15 (the sum of all the dice.
113+
114+
### Large straight:
115+
When placed on "large straight", if the dice read
116+
117+
2,3,4,5,6,
118+
119+
the player scores 20 (the sum of all the dice).
120+
121+
### Full house:
122+
If the dice are two of a kind and three of a kind, the
123+
player scores the sum of all the dice.
124+
For example, when placed on "full house":
125+
126+
- 1,1,2,2,2 scores 8 (1+1+2+2+2)
127+
- 2,2,3,3,4 scores 0
128+
- 4,4,4,4,4 scores 0

cpp/yahtzee.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int Yahtzee::TwoPair(int d1, int d2, int d3, int d4, int d5)
130130
int n = 0;
131131
int score = 0;
132132
for (int i = 0; i < 6; i += 1)
133-
if (counts[6-i-1] == 2) {
133+
if (counts[6-i-1] >= 2) {
134134
n++;
135135
score += (6-i);
136136
}
@@ -152,7 +152,7 @@ int Yahtzee::FourOfAKind(int _1, int _2, int d3, int d4, int d5)
152152
tallies[d4-1]++;
153153
tallies[d5-1]++;
154154
for (int i = 0; i < 6; i++)
155-
if (tallies[i] == 4)
155+
if (tallies[i] >= 4)
156156
return (i+1) * 4;
157157
return 0;
158158
}
@@ -169,7 +169,7 @@ int Yahtzee::ThreeOfAKind(int d1, int d2, int d3, int d4, int d5)
169169
t[d4-1]++;
170170
t[d5-1]++;
171171
for (int i = 0; i < 6; i++)
172-
if (t[i] == 3)
172+
if (t[i] >= 3)
173173
return (i+1) * 3;
174174
return 0;
175175
}

cpp/yahtzee.tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ static void one_pair()
8080
static void two_Pair()
8181
{
8282
assert(16 == Yahtzee().TwoPair(3,3,5,4,5));
83-
assert(0 == Yahtzee().TwoPair(3,3,5,5,5));
83+
assert(16 == Yahtzee().TwoPair(3,3,5,5,5));
8484
}
8585

8686
static void three_of_a_kind()
8787
{
8888
assert(9 == Yahtzee().ThreeOfAKind(3,3,3,4,5));
8989
assert(15 == Yahtzee().ThreeOfAKind(5,3,5,4,5));
90-
assert(0 == Yahtzee::ThreeOfAKind(3,3,3,3,5));
90+
assert(9 == Yahtzee::ThreeOfAKind(3,3,3,3,5));
9191
}
9292

9393
static void four_of_a_knd()
9494
{
9595
assert(12 == Yahtzee::FourOfAKind(3,3,3,3,5));
9696
assert(20 == Yahtzee::FourOfAKind(5,5,5,4,5));
97-
assert(0 == Yahtzee::FourOfAKind(3,3,3,3,3));
97+
assert(12 == Yahtzee::FourOfAKind(3,3,3,3,3));
9898
}
9999

100100
static void smallStraight()

csharp/Yahtzee.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static int ScorePair(int d1, int d2, int d3, int d4, int d5)
107107
counts[d5-1]++;
108108
int at;
109109
for (at = 0; at != 6; at++)
110-
if (counts[6-at-1] == 2)
110+
if (counts[6-at-1] >= 2)
111111
return (6-at)*2;
112112
return 0;
113113
}
@@ -123,7 +123,7 @@ public static int TwoPair(int d1, int d2, int d3, int d4, int d5)
123123
int n = 0;
124124
int score = 0;
125125
for (int i = 0; i < 6; i += 1)
126-
if (counts[6-i-1] == 2) {
126+
if (counts[6-i-1] >= 2) {
127127
n++;
128128
score += (6-i);
129129
}
@@ -143,7 +143,7 @@ public static int FourOfAKind(int _1, int _2, int d3, int d4, int d5)
143143
tallies[d4-1]++;
144144
tallies[d5-1]++;
145145
for (int i = 0; i < 6; i++)
146-
if (tallies[i] == 4)
146+
if (tallies[i] >= 4)
147147
return (i+1) * 4;
148148
return 0;
149149
}
@@ -158,7 +158,7 @@ public static int ThreeOfAKind(int d1, int d2, int d3, int d4, int d5)
158158
t[d4-1]++;
159159
t[d5-1]++;
160160
for (int i = 0; i < 6; i++)
161-
if (t[i] == 3)
161+
if (t[i] >= 3)
162162
return (i+1) * 3;
163163
return 0;
164164
}

csharp/YahtzeeTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,23 @@ public void one_pair()
7979
public void two_Pair()
8080
{
8181
Assert.AreEqual(16, Yahtzee.TwoPair(3,3,5,4,5));
82-
Assert.AreEqual(0, Yahtzee.TwoPair(3,3,5,5,5));
82+
Assert.AreEqual(16, Yahtzee.TwoPair(3,3,5,5,5));
8383
}
8484

8585
[Test]
8686
public void three_of_a_kind()
8787
{
8888
Assert.AreEqual(9, Yahtzee.ThreeOfAKind(3,3,3,4,5));
8989
Assert.AreEqual(15, Yahtzee.ThreeOfAKind(5,3,5,4,5));
90-
Assert.AreEqual(0, Yahtzee.ThreeOfAKind(3,3,3,3,5));
90+
Assert.AreEqual(9, Yahtzee.ThreeOfAKind(3,3,3,3,5));
9191
}
9292

9393
[Test]
9494
public void four_of_a_knd()
9595
{
9696
Assert.AreEqual(12, Yahtzee.FourOfAKind(3,3,3,3,5));
9797
Assert.AreEqual(20, Yahtzee.FourOfAKind(5,5,5,4,5));
98-
Assert.AreEqual(0, Yahtzee.FourOfAKind(3,3,3,3,3));
98+
Assert.AreEqual(12, Yahtzee.FourOfAKind(3,3,3,3,3));
9999
}
100100

101101
[Test]
@@ -121,4 +121,3 @@ public void fullHouse()
121121
Assert.AreEqual(0, Yahtzee.FullHouse(2,3,4,5,6));
122122
}
123123
}
124-

java/Yahtzee.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static int score_pair(int d1, int d2, int d3, int d4, int d5)
107107
counts[d5-1]++;
108108
int at;
109109
for (at = 0; at != 6; at++)
110-
if (counts[6-at-1] == 2)
110+
if (counts[6-at-1] >= 2)
111111
return (6-at)*2;
112112
return 0;
113113
}
@@ -123,7 +123,7 @@ public static int two_pair(int d1, int d2, int d3, int d4, int d5)
123123
int n = 0;
124124
int score = 0;
125125
for (int i = 0; i < 6; i += 1)
126-
if (counts[6-i-1] == 2) {
126+
if (counts[6-i-1] >= 2) {
127127
n++;
128128
score += (6-i);
129129
}
@@ -143,7 +143,7 @@ public static int four_of_a_kind(int _1, int _2, int d3, int d4, int d5)
143143
tallies[d4-1]++;
144144
tallies[d5-1]++;
145145
for (int i = 0; i < 6; i++)
146-
if (tallies[i] == 4)
146+
if (tallies[i] >= 4)
147147
return (i+1) * 4;
148148
return 0;
149149
}
@@ -158,7 +158,7 @@ public static int three_of_a_kind(int d1, int d2, int d3, int d4, int d5)
158158
t[d4-1]++;
159159
t[d5-1]++;
160160
for (int i = 0; i < 6; i++)
161-
if (t[i] == 3)
161+
if (t[i] >= 3)
162162
return (i+1) * 3;
163163
return 0;
164164
}

java/YahtzeeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ public void one_pair() {
7070
@Test
7171
public void two_Pair() {
7272
assertEquals(16, Yahtzee.two_pair(3,3,5,4,5));
73-
assertEquals(0, Yahtzee.two_pair(3,3,5,5,5));
73+
assertEquals(16, Yahtzee.two_pair(3,3,5,5,5));
7474
}
7575

7676
@Test
7777
public void three_of_a_kind()
7878
{
7979
assertEquals(9, Yahtzee.three_of_a_kind(3,3,3,4,5));
8080
assertEquals(15, Yahtzee.three_of_a_kind(5,3,5,4,5));
81-
assertEquals(0, Yahtzee.three_of_a_kind(3,3,3,3,5));
81+
assertEquals(9, Yahtzee.three_of_a_kind(3,3,3,3,5));
8282
}
8383

8484
@Test
8585
public void four_of_a_knd() {
8686
assertEquals(12, Yahtzee.four_of_a_kind(3,3,3,3,5));
8787
assertEquals(20, Yahtzee.four_of_a_kind(5,5,5,4,5));
88-
assertEquals(0, Yahtzee.three_of_a_kind(3,3,3,3,3));
88+
assertEquals(9, Yahtzee.three_of_a_kind(3,3,3,3,3));
8989
}
9090

9191
@Test

python/test_yahtzee.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ def test_one_pair():
6161

6262
def test_two_Pair():
6363
assert 16 == Yahtzee.two_pair(3,3,5,4,5)
64-
assert 0 == Yahtzee.two_pair(3,3,5,5,5)
64+
assert 18 == Yahtzee.two_pair(3,3,6,6,6)
65+
assert 0 == Yahtzee.two_pair(3,3,6,5,4)
6566

6667

6768
def test_three_of_a_kind():
6869
assert 9 == Yahtzee.three_of_a_kind(3,3,3,4,5)
6970
assert 15 == Yahtzee.three_of_a_kind(5,3,5,4,5)
70-
assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,5)
71+
assert 9 == Yahtzee.three_of_a_kind(3,3,3,3,5)
7172

7273

7374
def test_four_of_a_knd():
7475
assert 12 == Yahtzee.four_of_a_kind(3,3,3,3,5)
7576
assert 20 == Yahtzee.four_of_a_kind(5,5,5,4,5)
76-
assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,3)
77+
assert 12 == Yahtzee.four_of_a_kind(3,3,3,3,3)
78+
assert 0 == Yahtzee.four_of_a_kind(3,3,3,2,1)
7779

7880

7981
def test_smallStraight():

0 commit comments

Comments
 (0)