From da5a1648b89046d1719a43df2326415fb528245c Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:13:12 +0200 Subject: [PATCH 1/8] Some refactoring --- PokerKata/src/session3/PokerGame.java | 61 +++++++++++++-------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/PokerKata/src/session3/PokerGame.java b/PokerKata/src/session3/PokerGame.java index afdf76e..c4ff621 100644 --- a/PokerKata/src/session3/PokerGame.java +++ b/PokerKata/src/session3/PokerGame.java @@ -20,18 +20,20 @@ import java.util.Arrays; public class PokerGame { public int getScore(String hand) { int score = 0; + char[] values = getValues(hand); + char[] colors = getColors(hand); - if (findFlush(hand) == true) + if (findFlush(colors) == true) score = 10; - else if (findFullHouse(hand) == true) + else if (findFullHouse(values) == true) score = 9; - else if (findFourOfAKind(hand) == true) + else if (findFourOfAKind(values) == true) score = 7; - else if (findTwoPairs(hand) == true) + else if (findTwoPairs(values) == true) score = 6; - else if (findThreeOfAKind(hand) == true) + else if (findThreeOfAKind(values) == true) score = 3; - else if (findPair(hand) == true) + else if (findPair(values) == true) score = 2; else score = 0; @@ -45,8 +47,7 @@ public class PokerGame { * @param hand * @return true if there is a pair, otherwise false */ - private boolean findPair(String hand) { - char[] values = getValues(hand); + private boolean findPair(char[] values) { // Loop again, find pair for (int i = 0; i < values.length - 1; i++) { @@ -63,8 +64,7 @@ public class PokerGame { * @param hand * @return true if there is a Three of a kind, otherwise false */ - private boolean findThreeOfAKind(String hand) { - char[] values = getValues(hand); + private boolean findThreeOfAKind(char[] values) { // Loop again, find three of a kind for (int i = 0; i < values.length - 2; i++) { @@ -81,8 +81,7 @@ public class PokerGame { * @param hand * @return true if there is two pairs, otherwise false */ - private boolean findTwoPairs(String hand) { - char[] values = getValues(hand); + private boolean findTwoPairs(char[] values) { try { // Loop again, find pair @@ -94,7 +93,8 @@ public class PokerGame { } } } - } catch (ArrayIndexOutOfBoundsException e) { + } + catch (ArrayIndexOutOfBoundsException e) { return false; } return false; @@ -107,8 +107,7 @@ public class PokerGame { * @param hand * @return true if there is a Four of a kind, otherwise false */ - private boolean findFourOfAKind(String hand) { - char[] values = getValues(hand); + private boolean findFourOfAKind(char[] values) { // Loop again, find three of a kind for (int i = 0; i < values.length - 2; i++) { @@ -127,8 +126,7 @@ public class PokerGame { * @param hand * @return true if there is a Full House, otherwise false */ - private boolean findFullHouse(String hand) { - char[] values = getValues(hand); + private boolean findFullHouse(char[] values) { if (values[0] == values[1] && values[3] == values[4] && (values[0] == values[2] || values[2] == values[3])) @@ -136,6 +134,21 @@ public class PokerGame { return false; } + /** + * Finds a Flush by looking if all cards has the same colors + * + * @param hand + * @return true if there is a flush, otherwise false + */ + private boolean findFlush(char[] colors) { + + // Loop again, find pair + if (colors[0] == colors[1] && colors[1] == colors[2] + && colors[2] == colors[3] && colors[3] == colors[4]) + return true; + return false; + } + /** * Extracts all the values from the given String (hand) * @@ -174,18 +187,4 @@ public class PokerGame { return colors; } - /** - * Finds a Flush by looking if all cards has the same colors - * - * @param hand - * @return true if there is a flush, otherwise false - */ - private boolean findFlush(String hand) { - char[] colors = getColors(hand); - - // Loop again, find pair - if (colors[0] == colors[1] && colors[1] == colors[2] && colors[2] == colors[3] && colors[3] == colors[4]) - return true; - return false; - } } From 610a48657b04a607e268a14369792bab8ca52272 Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:20:07 +0200 Subject: [PATCH 2/8] Updated gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..efec373 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin/ +.classpath +.project +.settings \ No newline at end of file From 05ba0ebb03f59169e12de8f0926439b4f7587ee8 Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:47:02 +0200 Subject: [PATCH 3/8] Finds a Straight --- PokerKata/src/session3/PokerGame.java | 18 +++++++++++++++++- PokerKata/test/session3/PokerGameTest.java | 11 ++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/PokerKata/src/session3/PokerGame.java b/PokerKata/src/session3/PokerGame.java index c4ff621..9db3676 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 (findFlush(colors) == true) + if (findStraight(values) == true) + score = 12; + else if (findFlush(colors) == true) score = 10; else if (findFullHouse(values) == true) score = 9; @@ -149,6 +151,20 @@ public class PokerGame { 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) * diff --git a/PokerKata/test/session3/PokerGameTest.java b/PokerKata/test/session3/PokerGameTest.java index 28b420e..d0b7ed8 100644 --- a/PokerKata/test/session3/PokerGameTest.java +++ b/PokerKata/test/session3/PokerGameTest.java @@ -78,4 +78,13 @@ public class PokerGameTest { assertEquals(10, result); } -} + + @Test + public void straight_gives_12() throws Exception { + String hand = "K2S3H4R5R6"; + + int result = myGame.getScore(hand); + + assertEquals(12, result); + } +} \ No newline at end of file From 514e478b35e912ae5c0db1af4b49afa07462c7db Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:50:30 +0200 Subject: [PATCH 4/8] Cleaning --- PokerKata/.classpath | 8 -------- PokerKata/.gitignore | 4 ---- PokerKata/.project | 17 ----------------- PokerKata/.settings/org.eclipse.jdt.core.prefs | 11 ----------- 4 files changed, 40 deletions(-) delete mode 100644 PokerKata/.classpath delete mode 100644 PokerKata/.gitignore delete mode 100644 PokerKata/.project delete mode 100644 PokerKata/.settings/org.eclipse.jdt.core.prefs diff --git a/PokerKata/.classpath b/PokerKata/.classpath deleted file mode 100644 index 1b83178..0000000 --- a/PokerKata/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/PokerKata/.gitignore b/PokerKata/.gitignore deleted file mode 100644 index efec373..0000000 --- a/PokerKata/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin/ -.classpath -.project -.settings \ No newline at end of file diff --git a/PokerKata/.project b/PokerKata/.project deleted file mode 100644 index c950868..0000000 --- a/PokerKata/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - PokerKata - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/PokerKata/.settings/org.eclipse.jdt.core.prefs b/PokerKata/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 3a21537..0000000 --- a/PokerKata/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 From d28597351b8d3d5645bf45c5d49b2ba2c26b19ec Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:52:09 +0200 Subject: [PATCH 5/8] Cleaning --- BowlingKata/.classpath | 8 -------- BowlingKata/.project | 17 ----------------- .../.settings/org.eclipse.jdt.core.prefs | 11 ----------- 3 files changed, 36 deletions(-) delete mode 100644 BowlingKata/.classpath delete mode 100644 BowlingKata/.project delete mode 100644 BowlingKata/.settings/org.eclipse.jdt.core.prefs diff --git a/BowlingKata/.classpath b/BowlingKata/.classpath deleted file mode 100644 index 1b83178..0000000 --- a/BowlingKata/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/BowlingKata/.project b/BowlingKata/.project deleted file mode 100644 index 9fccbe4..0000000 --- a/BowlingKata/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - BowlingKata - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/BowlingKata/.settings/org.eclipse.jdt.core.prefs b/BowlingKata/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 3a21537..0000000 --- a/BowlingKata/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 From f0af7c90d15262837f48560660ac8751381692f4 Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 09:54:48 +0200 Subject: [PATCH 6/8] Cleaning --- PokerKata/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 PokerKata/.gitignore diff --git a/PokerKata/.gitignore b/PokerKata/.gitignore new file mode 100644 index 0000000..efec373 --- /dev/null +++ b/PokerKata/.gitignore @@ -0,0 +1,4 @@ +/bin/ +.classpath +.project +.settings \ No newline at end of file From 94f11c39f356b3e3ded2dc5b535850198aab12fd Mon Sep 17 00:00:00 2001 From: di7chro Date: Tue, 28 Apr 2015 10:02:19 +0200 Subject: [PATCH 7/8] 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 From a39c85388d4b3542f8e5e4a0dd94c717652481f2 Mon Sep 17 00:00:00 2001 From: Christian Ohlsson Date: Tue, 28 Apr 2015 13:27:34 +0200 Subject: [PATCH 8/8] Update README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 926eacb..1248f82 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,26 @@ Inom WhiteBox-test har man möjligheten att kunna titta in i lådan för att se ## 3. Test Double Inför detta pas gjorde vi som hemarbete den tredje katan, Poker Kata +Nu skall den göras på riktigt. + +### Klassdiagram + +#### Kort +- Färg +- Värde + +#### Kortlek +- Kort +- Blanda + +#### Spelare +- 5 Kort + +#### Spel +- Kortlek +- Regler +- Spelare +- Jämför händer ## 4. Clean Code + ATDD