-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequencyAI.java
More file actions
40 lines (35 loc) · 1.12 KB
/
frequencyAI.java
File metadata and controls
40 lines (35 loc) · 1.12 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// ai player that guesses letters based on english letter frequency
public class frequencyAI implements WOFPlayer {
private String playerId;
private List<Character> frequencyOrder;
private int currentIndex;
// constructor initializing player ID
public frequencyAI() {
this.playerId = "frequencyAI";
reset();
}
// returns the next letter in frequency order
@Override
public char nextGuess() {
if (currentIndex < frequencyOrder.size()) {
return frequencyOrder.get(currentIndex++);
}
return '?'; // fallback if all letters guessed
}
// returns the player's ID
@Override
public String playerId() {
return playerId;
}
// resets index and sets letter frequency order
@Override
public void reset() {
frequencyOrder = new ArrayList<>(Arrays.asList(
'e', 't', 'a', 'o', 'i', 'n', 's', 'h', 'r', 'd', 'l', 'c', 'u', 'm', 'w', 'f', 'g', 'y', 'p', 'b', 'v', 'k', 'j', 'x', 'q', 'z'
));
currentIndex = 0;
}
}