Added Straight Flush
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 (findStraight(values) == true)
|
if (findStraightFlush(values, colors) == true)
|
||||||
|
score = 14;
|
||||||
|
else if (findStraight(values) == true)
|
||||||
score = 12;
|
score = 12;
|
||||||
else if (findFlush(colors) == true)
|
else if (findFlush(colors) == true)
|
||||||
score = 10;
|
score = 10;
|
||||||
@@ -156,7 +158,7 @@ public class PokerGame {
|
|||||||
* throughout all the cards
|
* throughout all the cards
|
||||||
*
|
*
|
||||||
* @param values
|
* @param values
|
||||||
* @return
|
* @return true if there is a straight, otherwise false
|
||||||
*/
|
*/
|
||||||
private boolean findStraight(char[] values) {
|
private boolean findStraight(char[] values) {
|
||||||
for (int i = 0; i < values.length - 1; i++)
|
for (int i = 0; i < values.length - 1; i++)
|
||||||
@@ -165,6 +167,23 @@ public class PokerGame {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a Straight Flush by first looking for a Straight and then the Flush
|
||||||
|
*
|
||||||
|
* @param values
|
||||||
|
* @param colors
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean findStraightFlush(char[] values, char[] colors) {
|
||||||
|
for (int i = 0; i < values.length - 1; i++)
|
||||||
|
if (values[i + 1] != values[i] + 1)
|
||||||
|
return false;
|
||||||
|
if (colors[0] == colors[4])
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts all the values from the given String (hand)
|
* Extracts all the values from the given String (hand)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package session3;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PokerGameTest {
|
public class PokerGameTest {
|
||||||
@@ -87,4 +88,23 @@ public class PokerGameTest {
|
|||||||
|
|
||||||
assertEquals(12, result);
|
assertEquals(12, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void straight_flush_gives_14() throws Exception {
|
||||||
|
String hand = "K2K3K4K5K6";
|
||||||
|
|
||||||
|
int result = myGame.getScore(hand);
|
||||||
|
|
||||||
|
assertEquals(14, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void royal_straight_flush_gives_16() throws Exception {
|
||||||
|
String hand = "R10RKRDRKRE";
|
||||||
|
|
||||||
|
int result = myGame.getScore(hand);
|
||||||
|
|
||||||
|
assertEquals(16, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user