Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please refer to the following instructions and the following template to write a C program that displays the same results as shown in the sample.

Please refer to the following instructions and the following template to write a C program that displays the same results as shown in the sample. Please be sure to use the macros, arrays, and functions in the template. Instructions:

image text in transcribed

Template:

#include //Standard Library #include //Board Size Constant #define BOARD_SIZE 8 //Board Space Constants #define EMPTY_SPACE 0 #define P1_SPACE 1 #define P2_SPACE 2 //Player Constants #define PLAYER1 1 #define PLAYER2 2 // function prototypes: // All these three printBoard function prototypes are equivalent void printBoard(int board[BOARD_SIZE][BOARD_SIZE]); // OK // void printBoard(int board[][BOARD_SIZE]); // Good // void printBoard(int (* board)[BOARD_SIZE]); // Good int validateInput(); // All these three printMove function prototypes are equivalent int playMove(int x, int y, int PLAYER, int board[BOARD_SIZE][BOARD_SIZE]); // OK // int playMove(int x, int y, int PLAYER, int board[][BOARD_SIZE]); // Good //int playMove(int x, int y, int PLAYER, int (* board)[BOARD_SIZE]); // Good int main(void){ // ..... int board[BOARD_SIZE][BOARD_SIZE]; //Game Board Variable // use a do-while or while loop here // do{ // ... //Getting Player Input int x, y; printf(" "); printf("Enter X coordinate: "); x = validateInput(); printf("Enter Y coordinate: "); y = validateInput(); playMove(x, y, playersTurn, board); // Place Move on Board printBoard(board); // function call // }while(scanf("%d", &status)); return 0; } void printBoard(int board[BOARD_SIZE][BOARD_SIZE]) // OK // void printBoard(int board[][BOARD_SIZE]) // Good //void printBoard(int (* board)[BOARD_SIZE]) // Good { //Display the game board here } //To be changed in XGame Week 5 Assignment int playMove(int x, int y, int PLAYER, int board[][BOARD_SIZE]) // OK // int playMove(int x, int y, int PLAYER, int board[][BOARD_SIZE]) // Good // int playMove(int x, int y, int PLAYER, int (* board)[BOARD_SIZE]) // Good { //Set board to either P1_SPACE or P2_SPACE here return 1; } int validateInput(){ int num; // validate input here return num; } 

Sample:

image text in transcribed

Thank you.

This week you will create a game board array that will save player moves. Start by declaring this array as a 2D-array of integers with size BOARD SIZE (at this time make sure BOARD-SIZE is equal to 8). Create a set of macros that will define whether a space on the game board is an EMPTY SPACE, P1-SPACE, or P2 SPACE. An example of the #define directives is as follows: Board Size Constant #define BOARD SIZE Board Space Constants #define EMPTY SPACE 0 #define P1 SPACE #define P2 SPACE //Player Constants #define PLAYER1 #define PLAYER2 You will use these macros as values in your game board array. Set every cell in the game board array to EMPTY SPACE. Then set indices [3][3] and [4][4] to P1-SPACE and indices 13][4] and [4][3] to P2 SPACE. Now modify your printBoard function to take the game board array as the only parameter. Modify the function to print out 'B' (for P1-SPACED, 'W' (for P2-SPACED, and (for EMPTY SPACE) using your macros defined earlier. Finally, modify the code in your program where you call the printBoard function to now take the 2D game board array as a parameter Next, you may delete the code in your game loop that asks for a second coordinate, as well as the print statements that print the alignment of the coordinates. You will only be asking for one coordinate from now on (See sample output for example) Finally create a function called playMove, which takes the x and y coordinates the current player's turn variable, and the 2D game board array as parameters and returns an integer. The function should set the board space at index [x]ly to the appropriate space macro defined from earlier (P1-SPACE or P2-SPACE) depending on the player variable passed in. This function should return 1 for now. We will modify this function more in the coming weeks (as of right now, players will be able to overwrite previous moves We will change this later) The prototypes of the functions are as follows int getAlignment (int, int int int); //Returns Alignment Constant void print Board (int [B0ARD SIZEJ [B0ARD SIZE]) //Prints Game Board int validate Input int play Move (int, int int int [B0ARD SIZE] [BOARD SIZE]) (Continued on next page)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

e. What difficulties did they encounter?

Answered: 1 week ago