From d372113c66acc6ec04d14a37e86620e116e298c8 Mon Sep 17 00:00:00 2001 From: tfoster-ssi Date: Mon, 13 Apr 2015 11:56:19 -0400 Subject: [PATCH] Todd Foster --- .../java/com/hangman/players/YourPlayer.java | 39 ++++++++++++++++--- .../com/hangman/players/YourPlayerTest.java | 3 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hangman/players/YourPlayer.java b/src/main/java/com/hangman/players/YourPlayer.java index ddcfbd3..177fe19 100644 --- a/src/main/java/com/hangman/players/YourPlayer.java +++ b/src/main/java/com/hangman/players/YourPlayer.java @@ -1,13 +1,40 @@ package com.hangman.players; + import com.hangman.Player; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; -public class YourPlayer implements Player { - @Override - public char GetGuess(List currentClue) { - return 'a'; - } +public class YourPlayer implements Player +{ + int firstChar = (int) 'a'; + + List pickedList = new LinkedList(); + @Override + public char GetGuess(List currentClue) { + for (Character clue:currentClue){ + if( ! clue.equals('_')){ + pickedList.add(Integer.valueOf(clue)); + } + } + int guess = firstChar; + if(isPicked(guess)){ + guess = guessFromPickedList(guess); + } + System.out.println("guess=" + (char) guess); + return (char) (guess); + } + + private int guessFromPickedList(int guess) { + int charCount=0; + while (isPicked(guess) && charCount<26) { + charCount++; + guess++; + } + return guess; + } + boolean isPicked(int guess){ + System.out.println("checking " + (char) guess + " at " + pickedList.indexOf(Integer.valueOf(guess))); + return pickedList.indexOf(Integer.valueOf(guess))>-1; + } } diff --git a/src/test/java/com/hangman/players/YourPlayerTest.java b/src/test/java/com/hangman/players/YourPlayerTest.java index d613f6b..67ad05c 100644 --- a/src/test/java/com/hangman/players/YourPlayerTest.java +++ b/src/test/java/com/hangman/players/YourPlayerTest.java @@ -3,6 +3,7 @@ import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; public class YourPlayerTest { @Test @@ -29,6 +30,6 @@ public void GuessesAWhenAIsThereAreAsInTheClueAsWell() { char guess = player.GetGuess(Arrays.asList('_', 'a', '_')); - assertEquals('a', guess); + assertNotEquals('a', guess); } }