TIC TAC TOE Game
TIC TAC TOE Game
void drawBoard(){
cout<<"\n";
for(int i = 0; i < 3; i++){
for(int j = 0; j <3; j++){
cout<<board[i][j]<<" ";
if(j<2) cout <<"|";
}
cout<<"\n";
if(i<2) cout<<"--|---|--\n";
}
cout<<"\n";
}
int checkWinner(){
//Check rows and columns
for(int i = 0; i < 3 ; i++){
if(board[i][0] == board[i][1] && board[i][1] == board[i][2]) return
currentPlayer;
if(board[0][i] == board[1][i] && board[1][i] == board[2][i]) return
currentPlayer;
}//check diagonals
if(board[0][0] == board[1][1] && board[1][1] == board[2][2]) return
currentPlayer;
if(board[0][2] == board[1][1] && board[1][1] == board[2][0]) return
currentPlayer;
void swapPlayerAndMarker(){
currentPlayer = (currentPlayer == 1)? 2 :1;
currentMarker = (currentMarker == 'X')? 'O' : 'X';
}
void game(){
int winner = 0;
int slot;
cout << "Player 1, Choose your marker ( X or O ): ";
cin >> currentMarker;
currentPlayer = 1;
drawBoard();
if(winner == 0){
swapPlayerAndMarker();
}
}
if(winner = 0){
cout<<"It's a tie!\n";
} else{
cout<<"Player " << winner << " wins!\n";
}
}
int main(){
cout<<"Wecome to the TIC TAC TOE game!\n";
game();
return 0;
}