Handles prison (kåk)
This commit is contained in:
@@ -15,14 +15,18 @@ public class PokerGame {
|
||||
public int getScore(String hand) {
|
||||
int score = 0;
|
||||
|
||||
if (findPair(hand) == true)
|
||||
score = 2;
|
||||
if (findThreeOfAKind(hand) == true)
|
||||
score = 3;
|
||||
if (findTwoPairs(hand) == true)
|
||||
score = 6;
|
||||
if (findFourOfAKind(hand) == true)
|
||||
if (findPrison(hand) == true)
|
||||
score = 9;
|
||||
else if (findFourOfAKind(hand) == true)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -80,6 +84,17 @@ public class PokerGame {
|
||||
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) {
|
||||
char[] values = "".toCharArray();
|
||||
String temp = "";
|
||||
|
||||
@@ -60,4 +60,13 @@ public class PokerGameTest {
|
||||
|
||||
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