Question
Tic Tac Toe In C Programining. I don't know how to make the players moves register on the board. I want to make it so
Tic Tac Toe In C Programining. I don't know how to make the players moves register on the board. I want to make it so the choices the player makes shows up on the board as an X, but I do not know where to start.
Here is my code so far:
#include
char ttt [3][3];
int win;
char player;
int countmove;
int move;
int i, j;
void PrintBoard(void)
{
printf("\t\t\t\tT i c t a c t o e");
printf(" Players Symbol: X");
printf(" Computer Symbol: O");
printf(" Enter a number between 1-9 to mark your X.");
printf(" Here is your board key! Use it as a spot reference for the Game Board.");
printf(" | | ");
printf(" %i | %i | %i ",1,2,3);
printf(" -------|-------|-------");
printf(" %i | %i | %i ",4,5,6);
printf(" -------|-------|-------");
printf(" %i | %i | %i ",7,8,9);
printf(" | | ");
printf("\tG A M E B O A R D");
printf(" \t\t\t\t | | ");
printf(" \t\t\t\t *%c | *%c | *%c ", ttt[0][0],ttt[0][1],ttt[0][2]);
printf(" \t\t\t\t-------|-------|-------");
printf(" \t\t\t\t *%c | *%c | *%c ", ttt[1][0],ttt[1][1],ttt[1][2]);
printf(" \t\t\t\t-------|-------|-------");
printf(" \t\t\t\t *%c | *%c | *%c ",ttt[2][0],ttt[2][1],ttt[2][2]);
printf(" \t\t\t\t | | ");
}
void DisplayMoves(void)
{
}
int CheckWin(void)
{
win = 0;
if (ttt[0][0] == player && ttt[0][1] == player && ttt[0][2] == player || /* Horizontal wins */
ttt[1][0] == player && ttt[1][1] == player && ttt[1][2] == player ||
ttt[2][0] == player && ttt[2][1] == player && ttt[2][2] == player ||
ttt[0][0] == player && ttt[1][0] == player && ttt[2][0] == player || /* Vertical wins */
ttt[0][1] == player && ttt[1][1] == player && ttt[2][1] == player ||
ttt[0][2] == player && ttt[1][2] == player && ttt[2][2] == player ||
ttt[0][0] == player && ttt[1][1] == player && ttt[2][2] == player || /* Cross wins */
ttt[2][0] == player && ttt[1][1] == player && ttt[0][2] == player)
{
win = 1;
}
}
void GetValidMove(void)
{
do{
do{
printf("Enter your move 1-9: ");
scanf("%i", &move);
}while (move < 1 || move > 9);
do{
switch(move)
{
case 1:
i = 0; j = 0;
break;
case 2:
i = 0; j = 1;
break;
case 3:
i = 0; j = 2;
break;
case 4:
i = 1; j = 0;
break;
case 5:
i = 1; j = 1;
break;
case 6:
i = 1; j = 2;
break;
case 7:
break;
i = 2; j = 0;
break;
case 8:
i = 2; j = 1;
break;
case 9:
i = 2; j = 2;
break;
}
}while (ttt[i][j]!= ' ');
}while (ttt[i][j]!= ' ');
}
void main(void)
{
do{
for (i=0; i <3; i++)
for (j=0; j<3; j++)
ttt[i][j] = ' ';
PrintBoard();
GetValidMove();
ttt[i][j] = player;
countmove ++;
CheckWin();
} while (win == 0);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started