Last step
Sat May 20 2023 15:16:47 GMT+0000 (Coordinated Universal Time)
Saved by
@gokulz
public class TicTacToe{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
// create a 2d character array full of dashes
char[][] board = {{'-','-','-'},
{'-','-','-'},
{'-','-','-'}
};
for(int i=0; i<9; i++){
if(i%2==0){
System.out.println("Turn: X");
int[] spot = askUser(board);
board[spot[0]][spot[1]] = 'X';
printBoard(board);
}
else{
System.out.println("Turn: O");
int[] spot = askUser(board);
board[spot[0]][spot[1]] = 'O';
printBoard(board);
}
int count = checkWin(board);
if(count==3){
System.out.println("X Wins ");
break;
}
else if(count==-3){
System.out.println("O Wins");
break;
}
else if(i==8){
System.out.println("Tie");
}
}
}
content_copyCOPY
Comments