Finds a Straight
This commit is contained in:
@@ -23,7 +23,9 @@ public class PokerGame {
|
|||||||
char[] values = getValues(hand);
|
char[] values = getValues(hand);
|
||||||
char[] colors = getColors(hand);
|
char[] colors = getColors(hand);
|
||||||
|
|
||||||
if (findFlush(colors) == true)
|
if (findStraight(values) == true)
|
||||||
|
score = 12;
|
||||||
|
else if (findFlush(colors) == true)
|
||||||
score = 10;
|
score = 10;
|
||||||
else if (findFullHouse(values) == true)
|
else if (findFullHouse(values) == true)
|
||||||
score = 9;
|
score = 9;
|
||||||
@@ -149,6 +151,20 @@ public class PokerGame {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a Straight by looking if the value of the next card is 1 higher
|
||||||
|
* throughout all the cards
|
||||||
|
*
|
||||||
|
* @param values
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean findStraight(char[] values) {
|
||||||
|
for (int i = 0; i < values.length - 1; i++)
|
||||||
|
if (values[i + 1] != values[i] + 1)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts all the values from the given String (hand)
|
* Extracts all the values from the given String (hand)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -78,4 +78,13 @@ public class PokerGameTest {
|
|||||||
|
|
||||||
assertEquals(10, result);
|
assertEquals(10, result);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void straight_gives_12() throws Exception {
|
||||||
|
String hand = "K2S3H4R5R6";
|
||||||
|
|
||||||
|
int result = myGame.getScore(hand);
|
||||||
|
|
||||||
|
assertEquals(12, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user