-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomAI.java
More file actions
41 lines (36 loc) · 1.09 KB
/
randomAI.java
File metadata and controls
41 lines (36 loc) · 1.09 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
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
// ai player that guesses letters randomly
public class randomAI implements WOFPlayer {
private String playerId;
private List<Character> remainingLetters;
private Random random;
// constructor initializing player ID and random generator
public randomAI() {
this.playerId = "randomAI";
this.random = new Random();
reset();
}
// returns a random letter that hasn't been guessed yet
@Override
public char nextGuess() {
int index = random.nextInt(remainingLetters.size());
char guess = remainingLetters.get(index);
remainingLetters.remove(index);
return guess;
}
// returns the player's ID
@Override
public String playerId() {
return playerId;
}
// resets the remaining letters list to include all letters
@Override
public void reset() {
remainingLetters = new ArrayList<>();
for (char letter = 'a'; letter <= 'z'; letter++) {
remainingLetters.add(letter);
}
}
}