-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathYourPlayer.java
More file actions
40 lines (35 loc) · 1.08 KB
/
YourPlayer.java
File metadata and controls
40 lines (35 loc) · 1.08 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
package com.hangman.players;
import com.hangman.Player;
import java.util.LinkedList;
import java.util.List;
public class YourPlayer implements Player
{
int firstChar = (int) 'a';
List<Integer> pickedList = new LinkedList<Integer>();
@Override
public char GetGuess(List<Character> currentClue) {
for (Character clue:currentClue){
if( ! clue.equals('_')){
pickedList.add(Integer.valueOf(clue));
}
}
int guess = firstChar;
if(isPicked(guess)){
guess = guessFromPickedList(guess);
}
System.out.println("guess=" + (char) guess);
return (char) (guess);
}
private int guessFromPickedList(int guess) {
int charCount=0;
while (isPicked(guess) && charCount<26) {
charCount++;
guess++;
}
return guess;
}
boolean isPicked(int guess){
System.out.println("checking " + (char) guess + " at " + pickedList.indexOf(Integer.valueOf(guess)));
return pickedList.indexOf(Integer.valueOf(guess))>-1;
}
}