-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathYourPlayer.java
More file actions
53 lines (42 loc) · 1.17 KB
/
YourPlayer.java
File metadata and controls
53 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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) {
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;
}
}