you don’t necessarily win in 9 turns
nobody claimed that
Good eye!
Well 9 squares = 9 moves doesn’t it? Unless I’m mistaken.
~Shazer2
That all the cells are filled, doesn’t mean there is a winner, it can be a tie. In the same way, you can win when there are less than 9 cells filled, so you have to call you checkWin( ) method after every turn, not after 9 turns.
OOX … take that!
That’s true, Riven. I’m having a problem, I dropped in my win check after each turn and now when I do check the win (place the final mark in a row of 3) it checks the win, before it’s placed (redraw of board).
So I am checking the win correctly but it is checking the win before the final piece is drawn to the board. The board is drawn BEFORE the last move.
EDIT: I fixed the drawing issue. Now, when checking for a tie or win I have the following check.
public void actualCheckWin() {
if (checkWin().equals("X")) {
System.out.println("X wins!");
System.exit(0);
} else if (checkWin().equals("O")) {
System.out.println("O wins!");
System.exit(0);
} else {
System.out.println("It's a tie!");
System.exit(0);
}
}
The else gets called straight away on the first move. I’m not sure why.
~Shazer2
Try
else if(turns == 9) {
// tie!
}
Ah good point, because I just assumed I didn’t need that variable anymore and removed it conpletely. However I shall re-add it when I get home.
What variable? you meant “turns”? although if it’s not matter on logic, I think it’s good to show it for player