Connect4.c
2. Include the string.h header file
3. Declare the following macros (i.e., use #define NOT const) to use
as global constants for the application
a. ROW with a value of 6
b. COL with a value of 7
c. ONE with a value of 1
d. TWO with a value of 2
e. SPACE with a value of ' ' (NOTE: there is an explicit
space between the open and close single quote)
f. TRUE with a value of 1
g. FALSE with a value of 0
4. Write the function declaration or prototype for functions
a. initializeBoard
b. displayBoard
c. makeMove
5. Update function playGame to do the following
a. Add local variable named board, data type character,
two-dimensional array, size 6 rows and 7 columns (i.e.,
use macros ROW and COL)
b. Before the while loop
i. Call function initializeBoard; pass as an argument
array board
c. Inside the while loop
i. Comment out or delete call to function
displayExplicitBoard
ii. Call function displayBoard; pass as an argument
array board
iii. Inside the if/else if statements
1. Replace the printf statement notifying the
player it is their turn with call to function
makeMove; pass as arguments
a. Character array of players name
(i.e., yellow or red)
b. 2-d array board
6. Write function initializeBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Set the element at the current row and column in
the 2-d array board to an explicit space (i.e., use
macro SPACE)
7. Write function displayBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write printf statements to display the top row of the
Connect Four board
d. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Write a printf statement to display the value
stored in the current element of the array board
8. Write function makeMove to do the following
d. Return type void
e. Parameter list includes
i. Character array for the players name (i.e.,
playerName, size is 20, use macro NAME)
ii. 2-d character array (i.e., board), size 6 rows and 7
columns (i.e., use macros ROW and COL)
f. Declare variable to store the user input for their move,
data type character array, size 2 (i.e., move, use macro
TWO)
g. Declare variable to store if player move is valid, data type
integer, initialize to 0 (i.e., valid, use macro FALSE)
h. Loop while the players move input is not valid (i.e.,
FALSE)
i. Write a printf statement to prompt the player to
enter their move
ii. Write a scanf statement to store the players move
in local variable move
iii. Write a printf statement to display to the player
the move they entered
iv. Declare variable to store the length of the players
move input, data type integer (i.e., length) set
equal to explicit type ca.
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
1. Connect4.c
2. Include the string.h header file
3. Declare the following macros (i.e., use #define NOT const) to use
as global constants for the application
a. ROW with a value of 6
b. COL with a value of 7
c. ONE with a value of 1
d. TWO with a value of 2
e. SPACE with a value of ' ' (NOTE: there is an explicit
space between the open and close single quote)
f. TRUE with a value of 1
g. FALSE with a value of 0
4. Write the function declaration or prototype for functions
a. initializeBoard
b. displayBoard
c. makeMove
5. Update function playGame to do the following
a. Add local variable named board, data type character,
two-dimensional array, size 6 rows and 7 columns (i.e.,
use macros ROW and COL)
b. Before the while loop
i. Call function initializeBoard; pass as an argument
array board
c. Inside the while loop
i. Comment out or delete call to function
displayExplicitBoard
ii. Call function displayBoard; pass as an argument
array board
iii. Inside the if/else if statements
1. Replace the printf statement notifying the
player it is their turn with call to function
makeMove; pass as arguments
a. Character array of players name
(i.e., yellow or red)
2. b. 2-d array board
6. Write function initializeBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Set the element at the current row and column in
the 2-d array board to an explicit space (i.e., use
macro SPACE)
7. Write function displayBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write printf statements to display the top row of the
Connect Four board
d. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Write a printf statement to display the value
stored in the current element of the array board
8. Write function makeMove to do the following
d. Return type void
e. Parameter list includes
i. Character array for the players name (i.e.,
playerName, size is 20, use macro NAME)
ii. 2-d character array (i.e., board), size 6 rows and 7
columns (i.e., use macros ROW and COL)
f. Declare variable to store the user input for their move,
data type character array, size 2 (i.e., move, use macro
TWO)
g. Declare variable to store if player move is valid, data type
integer, initialize to 0 (i.e., valid, use macro FALSE)
h. Loop while the players move input is not valid (i.e.,
FALSE)
3. i. Write a printf statement to prompt the player to
enter their move
ii. Write a scanf statement to store the players move
in local variable move
iii. Write a printf statement to display to the player
the move they entered
iv. Declare variable to store the length of the players
move input, data type integer (i.e., length) set
equal to explicit type cast to integer of return value
from function call strlen(), pass as an argument
variable move
v. Evaluate variable length
1. If it is equal to 1, set variable valid equal to
true (i.e., use macros ONE and TRUE)
2. If it is not equal to 1, set variable valid
equal to false (i.e., use macros ONE and
FALSE)
vi. Evaluate variable valid, if it is false, write a printf
statement to notify the player their move input was
not valid (i.e., use macro FALSE)
Above are the instructions I need and below is what I currently have.
#include
#include
// global constants a.k.a. macros
#define NAME 20
#define YELLOW 1
#define RED 2
#define ZERO 0
#define FOUR 4
// function prototypes
void welcomeScreen ();
void displayEmptyBoard();
void playGame();
// main function
int main()
4. {
// call function welcomeScreen
welcomeScreen();
// call function displayEmptyBoard
// displayEmptyBoard();
// call function playGame
playGame();
// program executed successfully
return 0;
}
// welcomeScreen function displays the Connect Four logo and rules of the game
void welcomeScreen ()
{
printf (" CCCC OOOO N N N N EEEEE CCCC TTTTT FFFFF OOOO U
U RRRR n");
printf ("C O O N N N N N N EE C T F O O U
U R R n");
printf ("C O O N N N N N N EEEE C T FFF O O U
U R R n");
printf ("C O O N NN N NN EE C T F O O U
U R R n");
printf (" CCCC OOOO N N N N EEEEE CCCC T F OOOO UUUU
R R n");
printf ("n");
printf ("CONNECT FOUR GAME RULESnn");
printf("t 1. The board is 6 rows and 7 columns.n");
printf("t 2. The player with the yellow discs goes first.n");
printf("t 3. Players drop 1 disc in the grid at a time.n");
printf("t 4. Players alternate turns.n");
printf("t 5. Once a player has four discs in a row vertically, horizontally or
diagonally, they have won the game!n");
}
// function displayEmptyBoard displays a hardcoded version of an Connect Four board
void displayEmptyBoard()
{
printf("|------------------------------------------n");
5. printf("| A | B | C | D | E | F | G |n");
printf("|------------------------------------------n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
}
void playGame()
{
// store player names
char yellow[NAME]; // Karin
char red[NAME]; // Lia
// yellow (Y) always goes first
int currentPlayer = YELLOW;
int loop = ZERO;
printf("Player Yellow, please enter your namen");
scanf("%s", yellow);
printf("Player Red, please enter your namen");
scanf("%s", red);
printf("%s and %s, let's play Connect Four!n", yellow, red);
while(loop < FOUR)
{
// call function displayEmptyBoard
displayEmptyBoard();
// switch players for each move
if(currentPlayer == YELLOW)
{
6. printf("%s, it is your turnn", yellow);
// switch players
currentPlayer = RED;
}
else if(currentPlayer == RED)
{
printf("%s, it is your turnn", red);
currentPlayer = YELLOW;
}
loop++;
}
}
Please provide code screenshots in C language. Thank you