IO good enough

This commit is contained in:
Malte Tammena 2017-10-20 23:05:15 +02:00 committed by Maurizio Bruetsch
parent b6214bd9e1
commit 1cb455100d

View file

@ -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