I'm coding a Tic Tac Toe game. I have this int method that returns the position of a random open corner. However, it keeps returning the bottom left corner. It's not random.
Can someone point the problem please? Thanks.
private int openCorner() { boolean topLeft = board[0][0].isAvailable(); boolean topRight = board[0][2].isAvailable(); boolean bottomLeft = board[2][0].isAvailable(); boolean bottomRight = board[2][2].isAvailable(); ArrayList<Integer> pos = new ArrayList<Integer>(); if(topLeft) pos.add(0); if(topRight) pos.add(2); if(bottomLeft) pos.add(6); if(bottomRight) pos.add(8); Random gen = new Random(); if(pos.size()==0){ return -1; }else{ return pos.get(gen.nextInt(pos.size())); } }