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

Joe #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Joe #42

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
42 changes: 41 additions & 1 deletion src/main/java/com/hangman/players/YourPlayer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
package com.hangman.players;
import com.hangman.HangmanGame;
import com.hangman.Player;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class YourPlayer implements Player {

private LinkedList<Character> guesses;
private List<Character> latestClue;

public static final List<Character> mostCommon2LeastLetters;

static {
mostCommon2LeastLetters = Arrays.asList(
'e', 'a', 'r', 'i', 'o', 't', 'n', 's', 'l', 'c', 'u', 'd', 'p', 'm', 'h', 'g',
'b', 'f', 'y', 'w', 'k', 'v', 'x', 'z', 'j', 'q');
}

public YourPlayer() {
guesses = new LinkedList<Character>();
this.SetGuesses(mostCommon2LeastLetters);
}

private void SetGuesses(List<Character> chars) {
this.guesses = new LinkedList<Character>();
for(char guess : chars) {
this.guesses.add(guess);
}
}

@Override
public char GetGuess(List<Character> clue) {
return 'a';
if (clue == null) {
return 0;
}

latestClue = clue;
if (guesses.size() > 0) {
char c = guesses.pop();
if (!latestClue.contains(c))
return c;
}

return 0;
}

public List<Character> GetLatestClue() {
return latestClue;
}
}
55 changes: 50 additions & 5 deletions src/test/java/com/hangman/players/YourPlayerTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
package com.hangman.players;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import java.util.List;

import static org.junit.Assert.*;

public class YourPlayerTest {

private YourPlayer player;

@Before
public void setUp() {
player = new YourPlayer();
}

@Test
public void AlwaysGuessA() {
YourPlayer player = new YourPlayer();
public void GetLatestClueShouldReturnNothing() {
assertNull(player.GetLatestClue());
}

char guess = player.GetGuess(Arrays.asList('a', 'b', 'c'));
@Test
public void GetGuessShouldReturnFirstElementInMostCommonLetterList() {
char guess = player.GetGuess(Arrays.asList('_', '_', '_'));
assertEquals(guess, YourPlayer.mostCommon2LeastLetters.get(0).charValue());
}

assertEquals('a', guess);
@Test
public void GetGuessShouldReturnZeroWhenClueIsNull() {
char c = player.GetGuess(null);
assertTrue(c == 0);
}

@Test
public void GetGuessShouldAlwaysReturnElementInMostCommonLetterList() {
for(int i = 0; i < YourPlayer.mostCommon2LeastLetters.size(); i++) {
char guess = player.GetGuess(Arrays.asList('_', '_', '_'));
assertTrue(Character.isAlphabetic(guess));
}
}

@Test
public void GetGuessShouldNotReturnLetterMorN() {
for(int i = 0; i < YourPlayer.mostCommon2LeastLetters.size(); i++) {
char c = player.GetGuess(Arrays.asList('m', '_', 'n'));
assertNotEquals(c, 'm');
assertNotEquals(c, 'n');
}
}

@Test
public void GetLatestClueShouldMatchInitialClueList() {
List <Character> clue = Arrays.asList('_', '_', '_');
player.GetGuess(Arrays.asList('_', '_', '_'));
assertEquals(clue, player.GetLatestClue());
}
}