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

Erik Paulsen #34

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
42 changes: 37 additions & 5 deletions src/main/java/com/hangman/players/YourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,44 @@
import com.hangman.Player;

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

public class YourPlayer implements Player {
@Override
public char GetGuess(List<Character> currentClue) {
return 'a';
}
List<Character> vowels = Arrays.asList('a','e','i','o','u');
List<Character> cons = Arrays.asList('s','m');
List<Character> guessed = new ArrayList<Character>();

@Override
public char GetGuess(List<Character> currentClue) {
if (countMatches(currentClue) >= 2) {
for (Character ch : cons) {
if (!guessed.contains(ch)) {
return remember(ch);
}
}
}
else {
for (Character ch : vowels) {
if (!guessed.contains(ch)) {
return remember(ch);
}
}
}
return remember('z');
}

private int countMatches(List<Character> currentClue) {
int matches = 0;
for (Character ch : currentClue) {
if (!ch.equals('_')) {
matches++;
}
}
return matches;
}
private char remember(char ch) {
guessed.add(ch);
return ch;
}
}
40 changes: 27 additions & 13 deletions src/test/java/com/hangman/players/YourPlayerTest.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
package com.hangman.players;

import org.junit.Test;
import org.junit.*;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import com.hangman.Player;

public class YourPlayerTest {
Player player;

@Before
public void setup() {
player = new YourPlayer();
}
@Test
public void GuessesAWhenThereAreNoSuccessfulCharactersGuessedYet() {
YourPlayer player = new YourPlayer();

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

assertEquals('a', guess);
}

@Test
public void GuessesAWhenThereAreSuccessfulCharactersGuessedThatAreNotA() {
YourPlayer player = new YourPlayer();
// @Test
// public void GuessesAWhenThereAreSuccessfulCharactersGuessedThatAreNotA() {
//
// char guess = player.GetGuess(Arrays.asList('m', '_', 'n'));
//
// assertEquals('a', guess);
// }

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

assertEquals('a', guess);
@Test
public void ShouldTryAllVowelsWhenNoMatch() {
List<Character> noMatch = Arrays.asList('_', '_', '_');
assertEquals('a', player.GetGuess(noMatch));
assertEquals('e', player.GetGuess(noMatch));
assertEquals('i', player.GetGuess(noMatch));
assertEquals('o', player.GetGuess(noMatch));
assertEquals('u', player.GetGuess(noMatch));
}

@Test
public void GuessesAWhenAIsThereAreAsInTheClueAsWell() {
YourPlayer player = new YourPlayer();

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

assertEquals('a', guess);
public void ShouldTryConsonentsWhenTwoMatches() {
List<Character> noMatch = Arrays.asList('_', 'a', '_', 'o', '_');
assertEquals('s', player.GetGuess(noMatch));
}
}