From b8512a169325780aeb5c29688c37b0616dad083f Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Fri, 20 Oct 2017 23:05:15 +0200 Subject: [PATCH] IO good enough --- src/player/Human.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/player/Human.java b/src/player/Human.java index 9263c36..84d792e 100644 --- a/src/player/Human.java +++ b/src/player/Human.java @@ -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 options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6)); + for (Integer i: new HashSet(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