C Programming Could you update my code using the code I provided. I need help with 5.   #include #include #define TRUE 1 #define FALSE 0 #define NAME 20 #define ROW 8 #define COL 8 #define SPACE ' ' #define PLAYER_X 1 #define PLAYER_O 2 #define ZERO 0 #define ONE 1 #define TWO 2 #define FOUR 4 #define INVALID -1 // function prototypes void welcomeScreen (); void displayExplicitBoard(); void clearScreen(); void playGame(); // main function int main() {     // call function welcomeScreen     welcomeScreen();     // call function clearScreen     clearScreen();     // call function displayExplicitBoard //    displayExplicitBoard();     // call function playGame     playGame();     // program executed successfully     return 0; } // welcomeScreen function displays the Othello logo and rules of the game void welcomeScreen () {     printf ("\t\t OOOO  TTTTTT HH  HH EEEEEE LL      LL      OOOO  \n");     printf ("\t\tOO  OO   TT   HH  HH EE     LL      LL     OO  OO \n");     printf ("\t\tOO  OO   TT   HHHHHH EEEE   LL      LL     OO  OO \n");     printf ("\t\tOO  OO   TT   HH  HH EE     LL      LL     OO  OO \n");     printf ("\t\t OOOO    TT   HH  HH EEEEEE LLLLLLL LLLLLL  OOOO  \n");     printf ("\n\n");//     printf ("OTHELLO GAME RULES:\n");     printf("\t1. A square 8 x 8 board\n");     printf("\t2. 64 discs colored black (X) on one side and white (O) on the opposite side.\n");     printf("\t3. The board will start with 2 black discs (X) and 2 white discs (O) at the center of the board.\n");     printf("\t4. They are arranged with black (X) forming a North-East to South-West direction. White (O) is forming a North-West to South-East direction\n");     printf("\t5. The goal is to get the majority of color discs on the board at the end of the game.\n");     printf("\t6. Each player gets 32 discs and black (X) always starts the game.\n");     printf("\t7. The game alternates between white (O) and black (X) until one player can not make a valid move to outflank the opponent or both players have no valid moves.\n");     printf("\t8. When a player has no valid moves, they pass their turn and the opponent continues.\n");     printf("\t9. A player cannot voluntarily forfeit their turn.\n");     printf("\t10. When both players can not make a valid move the game ends.\n"); } // function displayExplicitBoard displays a hardcoded version of an Othello board void displayExplicitBoard() {     printf("|-----------------------------------------------------|\n");     printf("|     |  A  |  B  |  C  |  D  |  E  |  F  |  G  |  H  |\n");     printf("|-----------------------------------------------------|\n");     printf("|  1  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  2  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  3  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  4  |     |     |     |  O  |  X  |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  5  |     |     |     |  X  |  O  |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  6  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  7  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");     printf("|  8  |     |     |     |     |     |     |     |     |\n");     printf("|-----------------------------------------------------|\n");  } // function clearScreen clears the screen for display purposes void clearScreen() {     printf("\n\t\t\t\tHit to continue!\n");     char enter;     scanf("%c", &enter );     // send the clear screen command Windows     system("cls");     // send the clear screen command for UNIX flavor operating systems //    system("clear"); } void playGame() {     // get player names     char playerX[NAME];     char playerO[NAME];     // black (X) always goes first     int currentPlayer = PLAYER_X;     int loop = ZERO;     printf("Player X, please enter your name\n");     scanf("%s", playerX);     printf("Player O, please enter your name\n");     scanf("%s", playerO);     printf("%s and %s, let's play Othello!\n", playerX, playerO);     while(loop < FOUR)     {         // call function displayExplicitBoard         displayExplicitBoard();         // switch players for each move         if(currentPlayer == PLAYER_X)         {             printf("%s, it is your turn\n",  playerX);             // switch players             currentPlayer = PLAYER_O;         }         else if(currentPlayer == PLAYER_O)         {             printf("%s, it is your turn\n",  playerO);             currentPlayer = PLAYER_X;         }         system("pause");         loop++;     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C Programming

Could you update my code using the code I provided. I need help with 5.

 

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

#define TRUE 1
#define FALSE 0
#define NAME 20
#define ROW 8
#define COL 8
#define SPACE ' '
#define PLAYER_X 1
#define PLAYER_O 2
#define ZERO 0
#define ONE 1
#define TWO 2
#define FOUR 4
#define INVALID -1

// function prototypes
void welcomeScreen ();
void displayExplicitBoard();
void clearScreen();
void playGame();

// main function
int main()
{
    // call function welcomeScreen
    welcomeScreen();
    // call function clearScreen
    clearScreen();

    // call function displayExplicitBoard
//    displayExplicitBoard();

    // call function playGame
    playGame();

    // program executed successfully
    return 0;
}

// welcomeScreen function displays the Othello logo and rules of the game
void welcomeScreen ()
{
    printf ("\t\t OOOO  TTTTTT HH  HH EEEEEE LL      LL      OOOO  \n");
    printf ("\t\tOO  OO   TT   HH  HH EE     LL      LL     OO  OO \n");
    printf ("\t\tOO  OO   TT   HHHHHH EEEE   LL      LL     OO  OO \n");
    printf ("\t\tOO  OO   TT   HH  HH EE     LL      LL     OO  OO \n");
    printf ("\t\t OOOO    TT   HH  HH EEEEEE LLLLLLL LLLLLL  OOOO  \n");
    printf ("\n\n");//
    printf ("OTHELLO GAME RULES:\n");
    printf("\t1. A square 8 x 8 board\n");
    printf("\t2. 64 discs colored black (X) on one side and white (O) on the opposite side.\n");
    printf("\t3. The board will start with 2 black discs (X) and 2 white discs (O) at the center of the board.\n");
    printf("\t4. They are arranged with black (X) forming a North-East to South-West direction. White (O) is forming a North-West to South-East direction\n");
    printf("\t5. The goal is to get the majority of color discs on the board at the end of the game.\n");
    printf("\t6. Each player gets 32 discs and black (X) always starts the game.\n");
    printf("\t7. The game alternates between white (O) and black (X) until one player can not make a valid move to outflank the opponent or both players have no valid moves.\n");
    printf("\t8. When a player has no valid moves, they pass their turn and the opponent continues.\n");
    printf("\t9. A player cannot voluntarily forfeit their turn.\n");
    printf("\t10. When both players can not make a valid move the game ends.\n");
}

// function displayExplicitBoard displays a hardcoded version of an Othello board
void displayExplicitBoard()
{
    printf("|-----------------------------------------------------|\n");
    printf("|     |  A  |  B  |  C  |  D  |  E  |  F  |  G  |  H  |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  1  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  2  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  3  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  4  |     |     |     |  O  |  X  |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  5  |     |     |     |  X  |  O  |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  6  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  7  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
    printf("|  8  |     |     |     |     |     |     |     |     |\n");
    printf("|-----------------------------------------------------|\n");
 }

// function clearScreen clears the screen for display purposes
void clearScreen()
{
    printf("\n\t\t\t\tHit <ENTER> to continue!\n");

    char enter;
    scanf("%c", &enter );

    // send the clear screen command Windows
    system("cls");
    // send the clear screen command for UNIX flavor operating systems
//    system("clear");
}

void playGame()
{
    // get player names
    char playerX[NAME];
    char playerO[NAME];

    // black (X) always goes first
    int currentPlayer = PLAYER_X;
    int loop = ZERO;

    printf("Player X, please enter your name\n");
    scanf("%s", playerX);

    printf("Player O, please enter your name\n");
    scanf("%s", playerO);

    printf("%s and %s, let's play Othello!\n", playerX, playerO);

    while(loop < FOUR)
    {
        // call function displayExplicitBoard
        displayExplicitBoard();

        // switch players for each move
        if(currentPlayer == PLAYER_X)
        {
            printf("%s, it is your turn\n",  playerX);

            // switch players
            currentPlayer = PLAYER_O;
        }
        else if(currentPlayer == PLAYER_O)
        {
            printf("%s, it is your turn\n",  playerO);

            currentPlayer = PLAYER_X;
        }

        system("pause");
        loop++;
    }
}

5. Write function initializeBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e. board),
size 8 rows and 8 cols (i.e. use macros ROW and COL)
Write a nested for loop to iterate through the rows and
columns of array board to do the following
c.
i. Based on the initial board setup, set the element in
the 2-d array board equal to an 'O' for the
appropriate row/column indexes
ii. Based on the initial board setup, set the element in
the 2-d array board equal to an 'X' for the
appropriate row/column indexes
iii. All other array elements, set the element in the 2-d
array board to an explicit space (i.e. use macro
SPACE)
Transcribed Image Text:5. Write function initializeBoard to do the following a. Return type void b. Parameter list includes 2-d character array (i.e. board), size 8 rows and 8 cols (i.e. use macros ROW and COL) Write a nested for loop to iterate through the rows and columns of array board to do the following c. i. Based on the initial board setup, set the element in the 2-d array board equal to an 'O' for the appropriate row/column indexes ii. Based on the initial board setup, set the element in the 2-d array board equal to an 'X' for the appropriate row/column indexes iii. All other array elements, set the element in the 2-d array board to an explicit space (i.e. use macro SPACE)
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Variables
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education