Question: below is starter code for a program thats ment to play tic tac toe. ive been tinkering with the 4 functons to make the program

below is starter code for a program thats ment to play tic tac toe. ive been tinkering with the 4 functons to make the program work with no sucess. please keep it as simple and clean as possible and have it be able to run a tic tat toe game. please repond if any more info is needed.
// constants
const char SIGIL[3]={'.','X','O'};
// prototypes
int winner(int board[3][3]);
bool isGameOver(int board[3][3]);
void drawBoard(int board[3][3]);
bool isMoveLegal(int board[3][3], int, int);
// return 1 if player 1'X' has won
// return 2 if player 2'O' has won
// return 0 if neither player has won
int winner(int board[3][3]){
return 0;
}
// using this board as a guide
// draw the board using "." for empty squares
// or 'X' or 'O' for player 1 or player 2
void drawBoard(int board[3][3]){
cout <<"012"<< endl;
cout <<"0..."<< endl;
cout <<"1..."<< endl;
cout <<"2..."<< endl;
}
// return false if row or column are out of bounds
// or if that spot on the board is already taken
// otherwise return true
bool isMoveLegal(int board[3][3], int row, int column){
return true;
}
// if any player has three in a row or if the board is full
// return true otherwise return false
bool isGameOver(int board[3][3]){
if (winner(board)==1|| winner(board)==2) return true;
for(int r=0; r<=2; r++)
for (int c=0; c<=2; c++)
if (board[r][c]==0)
return false;
return true;
}
int main(){
int board[3][3]={{0}}; //0 for empty square, 1 or 2 for taken squares
int player =1;
int row, column, result;
bool legalMove;
// starting board
drawBoard(board);
while(!isGameOver(board)){
cout << "Player "<< player <<"("<< SIGIL[player]<<"), your move?";
cin >> row >> column;
legalMove = isMoveLegal(board, row, column);
while(!legalMove){
cout << "Player "<< player <<"("<< SIGIL[player]<<"), your move?";
cin >> row >> column;
legalMove = isMoveLegal(board, row, column);
}
board[row][column]= player;
drawBoard(board);
player =3- player;
}
// game over
result = winner(board);
if (result ==0){
cout << "Tie Game" << endl;
} else {
cout << "Player "<< result <<"("<< SIGIL[result]<<") wins!" << endl;
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!