Question: Need help coding. Needs to print tic tac toe example. Where it tells you too insert code that's where it needs to be inputed. //

Need help coding. Needs to print tic tac toe example. Where it tells you too insert code that's where it needs to be inputed.  Need help coding. Needs to print tic tac toe example. Where
it tells you too insert code that's where it needs to be
// ticTacShell.c
//
// Shell of the game 'TicTacToe' for CpSc 1010/1011
//
#include
#include // rand(), srand()
#include // time()
// Size of the board (square)
const int BOARD_SIZE = 3;
// Symbols used for the board
const char BLANK_SYMBOL = ' ';
const char COMP_SYMBOL = 'O';
const char HUMAN_SYMBOL = 'X';
// Human goes first
const int HUMANS_TURN = 0;
const int COMPUTERS_TURN = 1;
// Function prototypes
void initializeBoard(char board[BOARD_SIZE][BOARD_SIZE]);
int hasWon(char board[BOARD_SIZE][BOARD_SIZE], char mark);
int hasWonHorizontal(char board[BOARD_SIZE][BOARD_SIZE], char mark);
int hasWonVertical(char board[BOARD_SIZE][BOARD_SIZE], char mark);
int hasWonDiagonal(char board[BOARD_SIZE][BOARD_SIZE], char mark);
void getComputerMove(char board[BOARD_SIZE][BOARD_SIZE]);
void getHumanMove(char board[BOARD_SIZE][BOARD_SIZE]);
void printBoard(char board[BOARD_SIZE][BOARD_SIZE]);
void clearScreen(void);
//
// The main function should not be changed
//
int main(void) {
char board[BOARD_SIZE][BOARD_SIZE];
int humanWon = 0; // boolean (0/1)
int computerWon = 0; // boolean (0/1)
int move = 0;
// Seed the random number generator
srand(time(0));
initializeBoard(board);
while ((move
clearScreen();
if ((move % 2) == COMPUTERS_TURN) {
getComputerMove(board);
} else {
printBoard(board);
getHumanMove(board);
}
computerWon = hasWon(board, COMP_SYMBOL);
humanWon = hasWon(board, HUMAN_SYMBOL);
move++;
}
clearScreen();
printBoard(board);
if (humanWon) {
printf(">>>> You won! ");
} else if (computerWon) {
printf("
} else { // move >= BOARD_SIZE * BOARD_SIZE
printf("==== A Draw ");
}
return 0;
}
//
// Initialized the board to all BLANK_SYMBOL
//
void initializeBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
int row;
for (row = 0; row
int col;
for (col = 0; col
board[row][col] = BLANK_SYMBOL;
}
}
}
//
// Determines if the 'mark' completely fills a row, column, or diagonal
// returns 1 if yes, 0 if no
//
int hasWon(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
return hasWonHorizontal(board, mark)
|| hasWonVertical(board, mark)
|| hasWonDiagonal(board, mark);
}
//
// Determines if the 'mark' completely fills a row
// returns 1 if yes, 0 if no
//
int hasWonHorizontal(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
int won = 0; // boolean (0/1). Assume lost until proven true
int row;
for (row = 0; row
int match = 1; // boolean (0/1)
int col;
for (col = 0; col
if (board[row][col] != mark) {
match = 0;
}
}
won = match;
}
return won;
}
//
// Determines if the 'mark' completely fills a column
// returns 1 if yes, 0 if no
//
int hasWonVertical(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}
//
// Determines if the 'mark' completely fills a diagonal
// returns 1 if yes, 0 if no
//
int hasWonDiagonal(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}
//
// Gets computer move by randomly picking an unoccupied cell
//
void getComputerMove(char board[BOARD_SIZE][BOARD_SIZE]) {
int row;
int col;
do {
row = rand() % BOARD_SIZE;
col = rand() % BOARD_SIZE;
} while (board[row][col] != BLANK_SYMBOL);
board[row][col] = COMP_SYMBOL;
}
//
// Gets human move by prompting user for row and column numbers
//
void getHumanMove(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}
//
// Prints the board to the screen. Example:
//
// 0 1 2
// +---+---+---+
// 0 | X | | |
// +---+---+---+
// 1 | | O | O |
// +---+---+---+
// 2 | | | X |
// +---+---+---+
//
void printBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}
//
// Clears the screen -- uses ANSI terminal control codes
//
void clearScreen(void) {
const char ESC = 27;
printf("%c[2J%c[H", ESC, ESC);
}
K Lab 09 lab9.pdf CPSC 1010/1011 Lab 9 2-D Arrays & Tic Tac Toe this week's lab, we will take a look at simple 2-dimensional arrays. These are used for tables ofdata They also b can ed to store the board in some game. ownload the shell of a game that plays TicTacToecalled tic TacShelle from this lab assignment in Canvas. fter downloading the game, save it (or rename it as ticTacProg.c. should compile and run. The computer just akes moves at ra ndom, while the human player does nothing. And yet the game sometimes ends in draw. Why? or th lab, you must finish the tic TacProgeprogram. It is recommended that you write it in stages. Add the code to display the board. Run it and check it's working. Add the code to get the aser's move: read two ints with rows nambered top lo bottom and columns left to right. Run and check that i's working. Add the code that tests for a vertical three-in-a-row. (Hint: look at the code for horizontal three-in-a-row. Runit an check that its working. Add the code that tests for a diagonal three-in-a-row. Run it and check that it's working. urn In Your Work 1. Before tuming in your assignment, make sure you have followed all of the instructions stated in this assignment and any additional instructions by your lab instructort s. Always test, test, and retest that your program given compiles and runs successfully on our Unix machines before submitting 2. Show your TA that you completed the assignment. Then submit and upload your ticTacProg source code to the CPSC 10 Labs website on Canvass under the comectlab assignment. After you submit filets on Canvas this program and other programs that you write this semester, always doublecheck that you submitted the correct file(so to do this download your submission from Canvas, view it, and make surethe submitted file(s) compiles and runs on our Unix machines. tyle Formatting and Commenting Reguirements 120 points) 5 points) Commenting your source code The top of your file should have a header comment, which should contain: our name (first and last Lab Section A brief description about what the program does Any other helpful information that you think would be good to have. All functions should be commented about what they do, and significant blocks of source codesheuld all describe its functional ity in plain English (which means someone who has no programming experience should be able to read your comments understand its functionality). 5 points] Variables should be declared at the top of the main function (when appropriatel, and variables should have meal ningful names. 5 points) Always indent your source code in a proper, consistent, and readable way (if you have questions abou how to indent your code conrectly, then ask your lab instructor before you submit your assignment) points) Your code should compile without any warnings on our Unix machines. Don't forget to use the flag when compiling to check for all compiler wannings. Correct any compiler warmings before submittin Wall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!