From 69e5b77c70ab35f03d614e29382d8b3834bb399d Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 11 Jun 2015 18:25:32 -0500 Subject: [PATCH 1/4] Add a readme. --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..31f30f3 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# Hangman in Java - for code sparring. + +This program tries to solve a game of hangman. It doesn't do a very good job - it's your job to fork it and create a new solution for it. + +## How To + +Fork this repo then clone it. To run the tests: + +```bash +mvn test +``` + +Tough stuff. To run the program: + +```bash +mvn package +java -jar target/Hangman-1.jar +``` + +When you run the program you'll see something like this: + +```bash +Erics-MacBook-Pro:HangmanJava paytonrules$ java -jar target/Hangman-1.jar +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +Current Clue Is _ _ _ _ _ +com.hangman.Game Over +``` + +What this means is is that the clue length was five characters, and your player successfully guessed....nothing. To see why let's take a look at YourPlayer.java. + +```java +public class YourPlayer implements Player { + @Override + public char GetGuess(List clue) { + return 'a'; + } +} +``` + +That's right `YourPlayer` - regardless of the clue - will guess the letter `a`. If it got `a` right, it guessed `a`. Wrong? `a`. It's a pretty stupid player. + +So to complete this exercise you will need to delete return 'a' - and instead return better guesses. How? Well look the parameter: + +`List clue`. The clue is exactly what you're seeing on screen. It is an array of characters where the '_' character means that you haven't gotten that location correct yet. + +This stumps people so let's go through an example. Let's assume the secret word is "aaron". The first time GetGuess is called it will get: + +`['_', '_', '_', '_', '_']` + +`YourPlayer` will guess 'a'. The next time GuetGuess is called it will look like: + +`['a', 'a', '_', '_', '_']` + +Naturally `YourPlayer` will guess 'a' again, because it is stupid. To complete this exercise you need to make `YourPlayer` good at hangman. + +## Tips + +* Maybe keep track of what you've guessed. +* Vowels are good. +* Your testing WILL BE GRADED! From a4fdb7b7172150548a10ebcb73e78670d81fce9a Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 11 Jun 2015 18:25:58 -0500 Subject: [PATCH 2/4] Add a test that clarifies that '_' is valid This stumps people. --- src/test/java/com/hangman/players/YourPlayerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/hangman/players/YourPlayerTest.java b/src/test/java/com/hangman/players/YourPlayerTest.java index bc92a3b..6324245 100644 --- a/src/test/java/com/hangman/players/YourPlayerTest.java +++ b/src/test/java/com/hangman/players/YourPlayerTest.java @@ -9,7 +9,7 @@ public class YourPlayerTest { public void AlwaysGuessA() { YourPlayer player = new YourPlayer(); - char guess = player.GetGuess(Arrays.asList('a', 'b', 'c')); + char guess = player.GetGuess(Arrays.asList('_', 'b', 'c')); assertEquals('a', guess); } From 0a01697bf96ab420679858db1737c5e245b7d84a Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Fri, 12 Jun 2015 13:01:05 -0500 Subject: [PATCH 3/4] Dont timestmap reports --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 117652a..25d43c1 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ com.hangman.players.* + false From 40d42721fb1d68fffdc5fc79fe73b29eb2cfea12 Mon Sep 17 00:00:00 2001 From: Robert Mulholand Date: Fri, 12 Jun 2015 14:38:59 -0500 Subject: [PATCH 4/4] guess by letter frequency --- .../java/com/hangman/players/YourPlayer.java | 41 +++++++++- .../com/hangman/players/YourPlayerTest.java | 79 ++++++++++++++++++- 2 files changed, 114 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hangman/players/YourPlayer.java b/src/main/java/com/hangman/players/YourPlayer.java index f537169..2dda4b2 100644 --- a/src/main/java/com/hangman/players/YourPlayer.java +++ b/src/main/java/com/hangman/players/YourPlayer.java @@ -6,8 +6,41 @@ import java.util.List; public class YourPlayer implements Player { - @Override - public char GetGuess(List clue) { - return 'a'; - } + int counter = 0; + + @Override + public char GetGuess(List clue) { + return letters(counter++); + } + + public char letters(int index) { + Character[] letters = new Character[26]; + letters[0] = 'e'; + letters[1] = 't'; + letters[2] = 'a'; + letters[3] = 'o'; + letters[4] = 'i'; + letters[5] = 'n'; + letters[6] = 's'; + letters[7] = 'h'; + letters[8] = 'r'; + letters[9] = 'd'; + letters[10] = 'l'; + letters[11] = 'c'; + letters[12] = 'u'; + letters[13] = 'm'; + letters[14] = 'w'; + letters[15] = 'f'; + letters[16] = 'g'; + letters[17] = 'y'; + letters[18] = 'p'; + letters[19] = 'b'; + letters[20] = 'v'; + letters[21] = 'k'; + letters[22] = 'j'; + letters[23] = 'x'; + letters[24] = 'q'; + letters[25] = 'z'; + return letters[index]; + } } diff --git a/src/test/java/com/hangman/players/YourPlayerTest.java b/src/test/java/com/hangman/players/YourPlayerTest.java index 6324245..059c62c 100644 --- a/src/test/java/com/hangman/players/YourPlayerTest.java +++ b/src/test/java/com/hangman/players/YourPlayerTest.java @@ -6,11 +6,86 @@ public class YourPlayerTest { @Test - public void AlwaysGuessA() { + public void hasCounterInitializedToZeroThatIncrementsWithGuesses() { + YourPlayer player = new YourPlayer(); + assertEquals(0, player.counter); + + player.GetGuess(Arrays.asList('_', '_', '_')); + assertEquals(1, player.counter); + + player.GetGuess(Arrays.asList('_', '_', '_')); + assertEquals(2, player.counter); + + player.GetGuess(Arrays.asList('_', '_', '_')); + assertEquals(3, player.counter); + + player.GetGuess(Arrays.asList('_', '_', '_')); + assertEquals(4, player.counter); + } + + @Test + public void guessLettersInOrderOfFrequency() { YourPlayer player = new YourPlayer(); char guess = player.GetGuess(Arrays.asList('_', 'b', 'c')); - assertEquals('a', guess); + assertEquals('e', guess); + assertEquals('t', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('a', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('o', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('i', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('n', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('s', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('h', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('r', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('d', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('l', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('c', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('u', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('m', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('w', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('f', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('g', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('y', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('p', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('b', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('v', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('k', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('j', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('x', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('q', player.GetGuess(Arrays.asList('_', '_', '_'))); + assertEquals('z', player.GetGuess(Arrays.asList('_', '_', '_'))); + } + + @Test + public void storeAllLetters() { + YourPlayer player = new YourPlayer(); + + assertEquals(player.letters(0), 'e'); + assertEquals(player.letters(1), 't'); + assertEquals(player.letters(2), 'a'); + assertEquals(player.letters(3), 'o'); + assertEquals(player.letters(4), 'i'); + assertEquals(player.letters(5), 'n'); + assertEquals(player.letters(6), 's'); + assertEquals(player.letters(7), 'h'); + assertEquals(player.letters(8), 'r'); + assertEquals(player.letters(9), 'd'); + assertEquals(player.letters(10), 'l'); + assertEquals(player.letters(11), 'c'); + assertEquals(player.letters(12), 'u'); + assertEquals(player.letters(13), 'm'); + assertEquals(player.letters(14), 'w'); + assertEquals(player.letters(15), 'f'); + assertEquals(player.letters(16), 'g'); + assertEquals(player.letters(17), 'y'); + assertEquals(player.letters(18), 'p'); + assertEquals(player.letters(19), 'b'); + assertEquals(player.letters(20), 'v'); + assertEquals(player.letters(21), 'k'); + assertEquals(player.letters(22), 'j'); + assertEquals(player.letters(23), 'x'); + assertEquals(player.letters(24), 'q'); + assertEquals(player.letters(25), 'z'); } }