Handles prison (kåk)
This commit is contained in:
@@ -15,14 +15,18 @@ public class PokerGame {
|
|||||||
public int getScore(String hand) {
|
public int getScore(String hand) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
if (findPair(hand) == true)
|
if (findPrison(hand) == true)
|
||||||
score = 2;
|
score = 9;
|
||||||
if (findThreeOfAKind(hand) == true)
|
else if (findFourOfAKind(hand) == true)
|
||||||
score = 3;
|
|
||||||
if (findTwoPairs(hand) == true)
|
|
||||||
score = 6;
|
|
||||||
if (findFourOfAKind(hand) == true)
|
|
||||||
score = 7;
|
score = 7;
|
||||||
|
else if (findTwoPairs(hand) == true)
|
||||||
|
score = 6;
|
||||||
|
else if (findThreeOfAKind(hand) == true)
|
||||||
|
score = 3;
|
||||||
|
else if (findPair(hand) == true)
|
||||||
|
score = 2;
|
||||||
|
else
|
||||||
|
score = 0;
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +84,17 @@ public class PokerGame {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean findPrison(String hand) {
|
||||||
|
char[] values = getValues(hand);
|
||||||
|
|
||||||
|
// We have a prison if the first and last two cards are a pair, and the
|
||||||
|
// middle card has same value as either of them (is three of a kind)
|
||||||
|
if (values[0] == values[1] && values[3] == values[4]
|
||||||
|
&& (values[0] == values[2] || values[2] == values[3]))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private char[] getValues(String hand) {
|
private char[] getValues(String hand) {
|
||||||
char[] values = "".toCharArray();
|
char[] values = "".toCharArray();
|
||||||
String temp = "";
|
String temp = "";
|
||||||
|
|||||||
@@ -60,4 +60,13 @@ public class PokerGameTest {
|
|||||||
|
|
||||||
assertEquals(7, result);
|
assertEquals(7, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void prison_gives_9() throws Exception {
|
||||||
|
String hand = "S2K2R2H7S7";
|
||||||
|
|
||||||
|
int result = myGame.getScore(hand);
|
||||||
|
|
||||||
|
assertEquals(9, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user