Changing move.
Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
parent
e09cffbabe
commit
d8d4680eca
|
@ -1,6 +1,8 @@
|
||||||
package player;
|
package player;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class Player2 implements Player{
|
public class Player2 implements Player{
|
||||||
|
|
||||||
|
@ -13,11 +15,14 @@ public class Player2 implements Player{
|
||||||
}
|
}
|
||||||
|
|
||||||
public int move(int[][] board){
|
public int move(int[][] board){
|
||||||
int choice = ran.nextInt(7);
|
Set<Integer> options = new HashSet<>([0, 1, 2, 3, 4, 5, 6]);
|
||||||
while (board[choice][0] != 0) {
|
for (Integer i: options) {
|
||||||
choice = ran.nextInt(7);
|
if (board[i][0] != 0) {
|
||||||
|
options.remove(i);
|
||||||
}
|
}
|
||||||
return choice;
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
|
|
Loading…
Reference in a new issue