c code connect 4 game please note that i do not have access to the header file and t 5150029

C code – Connect 4 game:

*Please note that I do NOT have access to the header file and therefore cannot provide this, access to this is not necessary in completing this question, as the completion of this question is expected to be done without this file.

I assume that the content of the array is an integer:

int board[COLS][ROWS] : the current state of the board. Each element in the array represents one square, 0 for empty, 1 for player 1, 2 for player 2. The first dimension (COLS) is the horizontal position on the board, starting at 0 on the left, COLS-1 on the right. The second dimension is the vertical position, starting at 0 at the TOP of the board, to ROWS-1 at the BOTTOM.

Write a function for the following:

winner(): Takes a board as input, and scans the board to see if anybody has won the game (has 4 tokens in a row either vertically, horizontally, or diagonally). If so, that player number (1 or 2) is returned, otherwise 0 is returned if nobody has won. This function will require many different checks to see if there are 4 non-empty squares of the same value in a row in multiple directions.

An example of what the game looks like is shown below:

UUTUUD UUUUUUU II|||0||| =============== 1 2 3 4 5 6 7 Player 2s (x) turn Enter column:

This is the main function of the template file:

#include
#include
#include
#include
#include
#include “connect4.h”

int main ( void ){

int option ;
   Game g ;

   // intitialise random seed
   srand(time(NULL));

while (( option = main_menu()) != -1 ){
if ( option == 1 ){
// setup a new game
setup_game ( &g ) ;
// now play this game
play_game ( &g ) ;
} else if ( option == 2 ){
// attempt to load the game from the save file
if ( load_game ( &g, “game.txt” ) == 0 ){
// if the load went well, resume this game
play_game ( &g ) ;
} else {
printf ( “Loading game failed.n”) ;
}
} else if ( option == -1 ){
printf ( “Exiting game, goodbye!n”) ;
}
}
}

UUTUUD UUUUUUU II|||0||| =============== 1 2 3 4 5 6 7 Player 2's (x) turn Enter column:

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now