Question: This program should be done in C language. Use the program below to modify it to include multiple game modes; the two-player mode youve written

This program should be done in C language. Use the program below to modify it to include multiple game modes; the two-player mode youve written so far and a single-player mode. The user should select which game mode they want to play from a menu at the start of the program. The single-player mode should create a struct for the computer player that assigns it the name Computer and the letter O. The computer should make moves by picking the most top left place among all the available places in the board.

Use the following function prototypes:

void playSinglePlayer();

void playTwoPlayer();

void makeComputerMove(char board[][3]);

The output should look like this:

This program should be done in C language. Use the program below

to modify it to include multiple game modes; the two-player mode youve

written so far and a single-player mode. The user should select which

This is the program to modify:

#include

void initializeBoard(char board[][3]);

void displayBoard(char board[][3]);

void makeMove(char board[][3], char player);

int validMove(char board[][3], int row, int column);

int checkWinner(char board[][3]);

int main()

{

int moves = 1;

char board[3][3];

char player = 'o';

initializeBoard(board);

while(moves

{

displayBoard(board);

makeMove(board, player);

if(checkWinner(board))

{

displayBoard(board);

if(player=='o')

{

printf("O wins!");

}

else

{

printf("X wins!");

}

break;

}

if(player == 'o')

{

player = 'x';

}

else

{

player = 'o';

}

moves++;

}

}

void initializeBoard(char board[][3])

{

int i , j;

for(i = 0 ;i

for( j = 0; j

board[i][j] = ' ';

}

void displayBoard(char board[][3])

{

printf(" 1 2 3 ");

int i;

int j;

for(i = 0; i

{

printf("%d ", (i+1));

for(j = 0; j

{

printf("[%c] ", board[i][j]);

}

printf(" ");

}

}

void makeMove(char board[][3], char player)

{

/**

* Here we call the function validMove() in do while loop.

*/

int row;

int col;

do

{

printf("Enter the row and column you'd like to fill: ");

scanf("%d %d", &row, &col);

if(validMove(board,row,col)==1)

{

board[row-1][col-1] = player;

break;

}

else if(validMove(board,row,col)==2)

{

printf("That move has already been entered! ");

}

else

{

printf("That move is not on the board! ");

}

}

while(1);

}

int validMove(char board[][3], int row, int column)

{

if(row3)

{

return 0;

}

if(column3)

{

return 0;

}

if(board[row-1][column-1]=='o' ||board[row-1][column-1]=='x')

{

return 2;

}

return 1;

}

int checkWinner(char board[][3])

{

if(board[0][0]!=' ' && board[0][0]==board[0][1] && board[0][1]==board[0][2])

{

return 1;

}

else if(board[1][0]!=' ' && board[1][0]==board[1][1] && board[1][1]==board[1][2])

{

return 1;

}

else if(board[2][0]!=' ' && board[2][0]==board[2][1] && board[2][1]==board[2][2])

{

return 1;

}

else if(board[0][0]!=' ' && board[0][0]==board[1][0] && board[1][0]==board[2][0])

{

return 1;

}

else if(board[0][1]!=' ' && board[0][1]==board[1][1] && board[1][1]==board[2][1])

{

return 1;

}

else if(board[0][2]!=' ' && board[0][2]==board[1][2] && board[1][2]==board[2][2])

{

return 1;

}

else if(board[0][0]!=' ' && board[0][0]==board[1][1] && board[1][1]==board[2][2])

{

return 1;

}

else if(board[0][2]!=' ' && board[0][2]==board[1][1] && board[1][1]==board[2][0])

{

return 1;

}

return 0;

}

Let's play Tic-Tac-Toe! -please select one by typing in the number- 1.Single Player 2.Two Players 3.Exit 2 I1 3 1 I 1 Enter the row and column you' d like to fill:l 1 1 [o I 1 2 I1 3 1 I 1 That move has already been entered! The computer place the X at row 1 column 2 2 I1 3 1 I 1 Enter the row and column you' d like to fill:2 2 2 o] 3 1 I 1 That move has already been entered! That move has already been entered! The computer place the X at row 1 column 3 1 o] [x] [X 2 o] 3 1 I 1 Enter the row and column you' d like to fill:3 3 1 o] [x] [X 2 o] 3 [o O wins

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 Databases Questions!