Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m writing a code for tic tac toe and am having problems writingthe code to in

ID: 3609020 • Letter: I

Question

I'm writing a code for tic tac toe and am having problems writingthe code to initialize game board and check if there is a winner(highlighted in red). Any help in theright direction would greatly be appreciated. This is how its setup...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define XPLAYER 0
#define OPLAYER 1
#define OPEN    -99

#define TIEGAME 2
#define LIVEGAME 3

int gameboard[9];

// Prototypes of subroutines involved
void initialize_board();
int check_winner();
int check_valid_move();
void display_board();

// Tic-Tac-Toe
//
//     |   |
// ------------
//     |   |
// ------------
//     |   |
//
// The array "gameboard" is tracking the following:
//   0 | 1 | 2
// ------------
//   3 | 4 | 5
// ------------
//   6 | 7 | 8
//
// The array "gameboard" is tracking the following:


void initialize_board()
{
//write code to initialize all board spotsto OPEN
}

int check_winner()
{
//write code to see if player has wongame
// Return 0 if game is won by XPLAYER
// Return 1 if game is won by OPLAYER
// Return 2 if game is a tie
// Return 3 if game is still going on

}

int check_valid_move(int spot)
{
// write code to see if player has wongame
// Return 0 if spot is not valid
// Return 1 if spot is valid
}

Explanation / Answer

please rate - thanks You said any help would be appreciated, so I've given you a workingtic tac toe in C, should get you started #include #include #include int matrix[3][3]; /* the tic tac toe matrix */ int check(void); void init_matrix(void); void get_player_move(void); void get_computer_move(void); void disp_matrix(void); int main(void) { int done; printf("This is the game of Tic Tac Toe. "); printf("You will be playing against the computer. "); done = -1; init_matrix(); do {     disp_matrix();     get_player_move();     done = check(); /* see if winner */     if(done!= -1) break; /* winner!*/     get_computer_move();     done = check(); /* see if winner */ } while(done== -1); if(done==1) printf("You won! "); else printf("I won!!!! "); disp_matrix(); /* show final positions */ getch(); return 0; } /* Initialize the matrix. */ void init_matrix(void) { int i, j; for(i=0; i