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 }

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

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

}

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)
Transcribed Image Text: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)
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning