I'm writing an int openCorner() method that returns the position of the board. I have it working I believe, but I need help simplifying it. Thanks. The position is the same as row * 3 + col.
private int openCorner()
{
boolean topLeft = false;
boolean topRight = false;
boolean bottomLeft = false;
boolean bottomRight = false;
if(board[0][0].isAvailable()){
topLeft=true;
}
if(board[0][2].isAvailable()){
topRight=true;
}
if(board[2][0].isAvailable()){
bottomLeft=true;
}
if(board[2][2].isAvailable()){
bottomRight=true;
}
ArrayList<Integer> pos = new ArrayList<Integer>();
if(topLeft==true){
pos.add(0);
}
if(topRight==true){
pos.add(2);
}
if(bottomLeft==true){
pos.add(6);
}
if(bottomRight==true){
pos.add(8);
}
Random gen = new Random();
if(pos.size()==0){
return -1;
}else{
return pos.get(gen.nextInt(pos.size()));
}
}
