Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todd Foster #30

Open
wants to merge 1 commit into
base: gradle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/main/java/com/hangman/players/YourPlayer.java
Original file line number Diff line number Diff line change
@@ -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<Character> currentClue) {
return 'a';
}
public class YourPlayer implements Player
{
int firstChar = (int) 'a';

List<Integer> pickedList = new LinkedList<Integer>();
@Override
public char GetGuess(List<Character> 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;
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/hangman/players/YourPlayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +30,6 @@ public void GuessesAWhenAIsThereAreAsInTheClueAsWell() {

char guess = player.GetGuess(Arrays.asList('_', 'a', '_'));

assertEquals('a', guess);
assertNotEquals('a', guess);
}
}