IO good enough
This commit is contained in:
parent
b6214bd9e1
commit
1cb455100d
|
@ -1,6 +1,9 @@
|
|||
package player;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Human implements Player {
|
||||
|
||||
|
@ -17,8 +20,18 @@ public class Human implements Player {
|
|||
|
||||
@Override
|
||||
public int move(int[][] board) {
|
||||
System.out.print("Choose a move: ");
|
||||
return sc.nextInt();
|
||||
Set<Integer> options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6));
|
||||
for (Integer i: new HashSet<Integer>(options)) {
|
||||
if (board[i][0] != 0) {
|
||||
options.remove(i);
|
||||
}
|
||||
}
|
||||
int choice = -1;
|
||||
while (!options.contains(new Integer(choice))) {
|
||||
System.out.print("Choose a move from " + options + ": ");
|
||||
choice = sc.nextInt();
|
||||
}
|
||||
return choice;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue