C Programming Question: Will you fix and update function playGame & makeMove using the instructions I provided. There are errors in my code. You do not have to provide an example. The erros in my code needs to be fixed. Please send a picture of the fixed code. Thank you! void playGame() { struct Player playerX; struct Player playerO; printf("Player X, please enter your name\n"); scanf("%s", playerX.playerName); playerX.playerNum = PLAYER_X; playerX.discCount = TWO; printf("Player O, please enter your name\n"); scanf("%s", playerO.playerName); playerO.playerNum = PLAYER_O; playerO.discCount = TWO; printf("%s and %s, let's play Othello!\n", playerX.playerName, playerO.playerName); // Othello board char board[ROW][COL]; // this is really a memory location of board[0][0] // black (X) always goes first int currentPlayer = PLAYER_X; int loop = ZERO; // call function initializeBoard initializeBoard(board); while(loop < FOUR) { // call function displayBoard displayBoard(board); // request the player's move if(currentPlayer == PLAYER_X) { makeMove(&playerX, board); currentPlayer = PLAYER_O; } else if(currentPlayer == PLAYER_O) { makeMove(&playerO, board); currentPlayer = PLAYER_X; } displayStats(playerX); displayStats(playerO); loop++; } } void makeMove(struct Player* player, char playerName, int playerNum, char board[ROW][COL]); { char move[THREE]; int valid = FALSE; // loop until the player enters a valid move while(valid == FALSE) { printf("%s, enter your move location (e.g. B6)\n", player->playerName); scanf("%s", move); printf("%s, you entered %s\n", player->playerName, move); // clears the buffer of extra characters getchar(); // fflush(stdin); int length = (int)strlen(move); if(length == TWO) valid = isValid(move, board); else valid = FALSE; if(valid == FALSE) printf("Invalid move, try again\n\n"); else printf("Valid move\n\n"); } } // good int isValid (char move[THREE], char board[ROW][COL]) { int valid = FALSE; // good valid = isOpen(move, board); // not sure return valid; //good }
C
Will you fix and update function playGame & makeMove using the instructions I provided.
There are errors in my code. You do not have to provide an example. The erros in my code needs to be fixed.
Please send a picture of the fixed code. Thank you!
void playGame()
{
struct Player playerX;
struct Player playerO;
printf("Player X, please enter your name\n");
scanf("%s", playerX.playerName);
playerX.playerNum = PLAYER_X;
playerX.discCount = TWO;
printf("Player O, please enter your name\n");
scanf("%s", playerO.playerName);
playerO.playerNum = PLAYER_O;
playerO.discCount = TWO;
printf("%s and %s, let's play Othello!\n", playerX.playerName, playerO.playerName);
// Othello board
char board[ROW][COL]; // this is really a memory location of board[0][0]
// black (X) always goes first
int currentPlayer = PLAYER_X;
int loop = ZERO;
// call function initializeBoard
initializeBoard(board);
while(loop < FOUR)
{
// call function displayBoard
displayBoard(board);
// request the player's move
if(currentPlayer == PLAYER_X)
{
makeMove(&playerX, board);
currentPlayer = PLAYER_O;
}
else if(currentPlayer == PLAYER_O)
{
makeMove(&playerO, board);
currentPlayer = PLAYER_X;
}
displayStats(playerX);
displayStats(playerO);
loop++;
}
}
void makeMove(struct Player* player, char playerName, int playerNum, char board[ROW][COL]);
{
char move[THREE];
int valid = FALSE;
// loop until the player enters a valid move
while(valid == FALSE)
{
printf("%s, enter your move location (e.g. B6)\n", player->playerName);
scanf("%s", move);
printf("%s, you entered %s\n", player->playerName, move);
// clears the buffer of extra characters
getchar();
// fflush(stdin);
int length = (int)strlen(move);
if(length == TWO)
valid = isValid(move, board);
else
valid = FALSE;
if(valid == FALSE)
printf("Invalid move, try again\n\n");
else
printf("Valid move\n\n");
}
}
// good
int isValid (char move[THREE], char board[ROW][COL])
{
int valid = FALSE; // good
valid = isOpen(move, board); // not sure
return valid; //good
}
![Update function playGame to do the following
a. Change the data type of variable playerX from a character array
to struct Player
b. Change the data type of variable player from a character array
to struct Player
c.
When prompting the players for their name
i.
Change storing the entered player name in the previous
character array (i.e. playerX and playerO) to struct field
playerName field (i.e. playerX.playerName and
playerO.playerName)
ii.
Set the value for struct field playerNum to the associated
macros for each player
iii. Set the value for struct field discCount to the value 2 for
5
each player
d. Update the printf statement to use the struct field playerName
e. Move function call display Board inside the while loop at the
beginning
f. Update calls to function makeMove so the argument list is
i. Address of the player's struct (i.e. &playerX or
&playerO)
ii.
Two-dimensional array board
g. Before incrementing the loop control variable (i.e. loop) call
function displayStats for each player, passing the player's struct
as an argument (i.e. playerX or playerO, NOT as a pointer, just
the struct)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7d4fd4d4-77c7-4e93-950b-25099f54e660%2F6550cd21-0e16-474a-818b-2afd8824254f%2F9kztuwf_processed.png&w=3840&q=75)
![Update function makeMove to do the following
a. Return type void
b. Parameter list includes
i. Pointer to struct Player (i.e. player)
ii. 2-d character array (i.e. board), size 8 rows and 8 cols
(i.e. use macros ROW and COL)
d.
c. Update the printf statements to use the struct field playerName
If data validation of length of user input is true (i.e. correct
length) set local variable valid equal to function call is Valid, pass
as arguments
i. Array move
ii. Array board
e. Evaluate the value of valid
i. if false, display to the user their move is invalid
ii. if true, display to the user their move is valid](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7d4fd4d4-77c7-4e93-950b-25099f54e660%2F6550cd21-0e16-474a-818b-2afd8824254f%2Fnk8tfkr_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)