Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have soe error in this program could you please help me N.B: The use of global variables (variables declared outside the body of a

i have soe error in this program could you please help me

N.B: The use of global variables (variables declared outside the body of a function) is not needed

#include

#include

void condition_check(void);

void player_turn(int);

void computer_turn(void);

void print_board(void);

int main(void)

{ int count = 0, stop = 0;

int choice;

printf("Welcome to 5x5 Tic-Tac-Toe Game ");

printf("1)Human player vs Human player ");

printf("2)Human player vs Computer ");

do

{

printf("Enter 1 or 2 to select gameplay mode ");

scanf("%d",&choice);

} while(choice!=1 && choice!=2);

if(choice==1)

{

print_board();

while(1)

{

player_turn(1);

condition_check();

if(stop == 1)

{

break;

}

player_turn(2);

condition_check();

if(stop == 1)

{

break;

}

}

}

if(choice==2)

{

print_board();

while(1)

{

player_turn(1);

condition_check();

if(stop == 1)

{

break;

}

computer_turn();

condition_check();

if(stop == 1)

{

break;

}

}

}

return 0;

}

void condition_check(void)

{ int count = 0, stop = 0;

count += 1; char board[5][5]={{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '}};

int i,j,count1,count2;

for(i=0;i<5;i++)

{

count1=0;

count2=0;

for(j=0;j<5;j++)

{

if(board[i][j]=='X')

count1++;

if(board[i][j]=='O')

count2++;

}

if(count1==5)

{

printf("Game Over! Player-1 won ");

stop=1;

return;

}

if(count2==5)

{

printf("Game Over! Player-2 won ");

stop=1;

return;

}

}

for(j=0;j<5;j++)

{

count1=0;

count2=0;

for(i=0;i<5;i++)

{

if(board[i][j]=='X')

count1++;

if(board[i][j]=='O')

count2++;

}

if(count1==5)

{

printf("Game Over! Player-1 won ");

stop=1;

return;

}

if(count2==5)

{

printf("Game Over! Player-2 won ");

stop=1;

return;

}

}

count1=0;

count2=0;

for(i=0;i<5;i++)

{

if(board[i][i]=='X')

count1++;

if(board[i][i]=='O')

count2++;

}

if(count1==5)

{

printf("Game Over! Player-1 won ");

stop=1;

return;

}

if(count2==5)

{

printf("Game Over! Player-2 won ");

stop=1;

return;

}

count1=0;

count2=0;

for(i=0;i<5;i++)

{

for(j=4;j>=0;j--)

{

if(board[i][j]=='X')

count1++;

if(board[i][j]=='O')

count2++;

}

}

if(count1==5)

{

printf("Game Over! Player-1 won ");

stop=1;

return;

}

if(count2==5)

{

printf("Game Over! Player-2 won ");

stop=1;

return;

}

if(count==25)

{

printf("Game Over! It's a Tie! ");

stop=1;

return;

}

return;

}

void computer_turn(void)

{

//code not designed time is not sufficient

}

void player_turn(int player_no)

{ int row_idx,col_idx;

do

{

printf("user-%d enter position to place your symbol ",player_no);

printf("Enter row index ");

scanf("%d",&row_idx);

printf("Enter column index ");

scanf("%d",&col_idx);

} while(board[row_idx-1][col_idx-1]!=' ');

if(player_no==1)

{

board[row_idx-1][col_idx-1]='X';

}

if(player_no==2)

{

board[row_idx-1][col_idx-1]='O';

}

print_board();

return;

}

void print_board(void) { char board[5][5]={{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '},{' ',' ',' ',' ',' '}}; printf(" 1 2 3 4 5 ");

printf(" +---+---+---+---+---+ ");

printf("1 | %c | %c | %c | %c | %c | ",board[0][0],board[0][1],board[0][2],board[0][3],board[0][4]);

printf(" +---+---+---+---+---+ ");

printf("2 | %c | %c | %c | %c | %c | ",board[1][0],board[1][1],board[1][2],board[1][3],board[1][4]);

printf(" +---+---+---+---+---+ ");

printf("3 | %c | %c | %c | %c | %c | ",board[2][0],board[2][1],board[2][2],board[2][3],board[2][4]);

printf(" +---+---+---+---+---+ ");

printf("4 | %c | %c | %c | %c | %c | ",board[3][0],board[3][1],board[3][2],board[3][3],board[3][4]);

printf(" +---+---+---+---+---+ ");

printf("5 | %c | %c | %c | %c | %c | ",board[4][0],board[4][1],board[4][2],board[4][3],board[4][4]);

printf(" +---+---+---+---+---+ ");

return;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago