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