-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathYourPlayer.java
More file actions
42 lines (34 loc) · 1.17 KB
/
YourPlayer.java
File metadata and controls
42 lines (34 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
package com.hangman.players;
import com.hangman.Player;
import com.sun.org.apache.xerces.internal.impl.xs.util.LSInputListImpl;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class YourPlayer implements Player {
private List<Character> vowels = new LinkedList<Character>(Arrays.asList('e', 'a', 'i', 'o', 'u'));
private List<Character> consonants = new LinkedList<Character>(Arrays.asList('r', 's', 't', 'l', 'n', 'd', 'g', 'b', 'c', 'm', 'p', 'f', 'h', 'v', 'w', 'y', 'j', 'k', 'q', 'x', 'z'));
public char GetGuess(List<Character> clue) {
return MakeEducatedGuess(clue);
}
private int EmptySpaces(List<Character> clue) {
int spaces = 0;
for(char i : clue) {
if (i == '_') {
spaces++;
}
}
return spaces;
}
private char MakeEducatedGuess(List<Character> clue) {
Random randomizer = new Random();
int spaces = EmptySpaces(clue);
if (spaces == clue.size()) {
return vowels.remove(0);
} else if (spaces == clue.size() - 1) {
return vowels.remove(0);
} else {
return consonants.remove(randomizer.nextInt(consonants.size() -1));
}
}
}