From 94f11c39f356b3e3ded2dc5b535850198aab12fd Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 10:02:19 +0200 Subject: [PATCH] Added Straight Flush --- PokerKata/src/session3/PokerGame.java | 23 ++++++++++++++++++++-- PokerKata/test/session3/PokerGameTest.java | 20 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/PokerKata/src/session3/PokerGame.java b/PokerKata/src/session3/PokerGame.java index 9db3676..fec4ec6 100644 --- a/PokerKata/src/session3/PokerGame.java +++ b/PokerKata/src/session3/PokerGame.java @@ -23,7 +23,9 @@ public class PokerGame { char[] values = getValues(hand); char[] colors = getColors(hand); - if (findStraight(values) == true) + if (findStraightFlush(values, colors) == true) + score = 14; + else if (findStraight(values) == true) score = 12; else if (findFlush(colors) == true) score = 10; @@ -156,7 +158,7 @@ public class PokerGame { * throughout all the cards * * @param values - * @return + * @return true if there is a straight, otherwise false */ private boolean findStraight(char[] values) { for (int i = 0; i < values.length - 1; i++) @@ -165,6 +167,23 @@ public class PokerGame { 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) * diff --git a/PokerKata/test/session3/PokerGameTest.java b/PokerKata/test/session3/PokerGameTest.java index d0b7ed8..a9cee8f 100644 --- a/PokerKata/test/session3/PokerGameTest.java +++ b/PokerKata/test/session3/PokerGameTest.java @@ -11,6 +11,7 @@ package session3; import static org.junit.Assert.assertEquals; +import org.junit.Ignore; import org.junit.Test; public class PokerGameTest { @@ -87,4 +88,23 @@ public class PokerGameTest { 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); + } } \ No newline at end of file