Question
Overview In this assignment, the student will write a C program that runs a Tic-Tac-Toe type game. When completing this assignment, the student should demonstrate
Overview
In this assignment, the student will write a C program that runs a Tic-Tac-Toe type game.
When completing this assignment, the student should demonstrate mastery of the following concepts:
Functions
Design by Interface
Looping Clauses
Decision Making Clauses
Output Formatting
Modular Design
2D Arrays Pattern Detecting Algorithm
Assignment In this assignment, you will be programming an interactive simulation of the game Tic-Tac-Toe. However, unlike regular Tic-Tac-Toe, you must write your program in a robust manner so a board of arbitrary size can be played on and a player need an arbitrary number of consecutive pieces in a row to win. When your program is done, you should have a final product that would allow two players sitting at the same computer to give moves to the program so they can play the game against one another.
To provide some structure in this project, the following shell is provided. You do not have to use this exact shell in your project, but the desired structure of the program and the functions involved is best explained by looking at some starting code:
// INCLUDES
#include
// DEFINES
#ifndef __TRUE_FALSE__
#define __TRUE_FALSE__
#define TRUE 1
#define FALSE 0
#endif
// ROWS and COLS must be between 1 and 9
#define ROWS 7
#define COLS 7
// MARKER CODES
#define MARKONE 'X'
#define MARKTWO 'O'
#define BLANK ' '
// VICTORY CODES
#define NOWIN 0
#define MARKONEVICTORY 1
#define MARKTWOVICTORY 2
#define TIE 3
#define ERROR 4
#define EPIC_FAIL 5
// GAME PARAMETER CODES
#define CONSECUTIVE_MARKS_REQUIRED 3
// PROTOTYPES
void InitializeBoard(char[ROWS][COLS]);
void DisplayBoard(char[ROWS][COLS]);
int PlayerMove(int, int, char[ROWS][COLS], char);
int VictoryCheck(int, char[ROWS][COLS]);
void DisplayVictoryMessage(int);
// MAIN
int main() {
// THE CORE LOGIC FOR YOUR GAME GOES HERE
// exit program
return 0;
}
// FUNCTION IMPLEMENTATIONS
void InitializeBoard(char board[ROWS][COLS]) {
// YOUR IMPLEMENTATION GOES HERE
}
void DisplayBoard(char board[ROWS][COLS]) {
// YOUR IMPLEMENTATION GOES HERE
}
int PlayerMove(int row, int col, char board[ROWS][COLS], char symbol) {
// YOUR IMPLEMENTATION GOES HERE
}
int VictoryCheck(int winRequirement, char board[ROWS][COLS]) {
// YOUR IMPLEMENTATION GOES HERE
}
void DisplayVictoryMessage(int victoryCode) {
// AN IMPLEMENTATION FOR THIS FUNCTION WAS PROVIDED IN A WEEKLY ASSIGNMENT
}
Minimally, the following functions should exist in your program. You may add additional functions if you desire, but please make sure the provided functions exist in some form within your program.
void InitializeBoard(char[ROWS][COLS]);
FUNCTION EXPLANATION This function should initialize the board. The board is represented in the game as a two-dimensional array. The dimensions of the board in rows and columns are provided in the provided preprocessor directive statements. When the board is initialized, all spaces within the board array should be set to the blank space. The function returns no value.
void DisplayBoard(char[ROWS][COLS]);
FUNCTION EXPLANATION This function should display the board in an organized, intuitive fashion. Details on the way this function works can be found in the weekly assignments. The function takes a single two-dimensional array as its only argument. That array should contain information about the pieces that are on the board at specific coordinates. Please note that this is the only function that draws things on the screen. Your main() may contain some prompting code to get player moves, but this function should be doing most of the drawing in the program. It return no value.
int PlayerMove(int, int, char[ROWS][COLS], char);
FUNCTION EXPLANATION This function is called when the core logic of your program attempts to put a player marker on the board. The first two arguments represent the row and column on the board where the user wishes to place a piece. Please note that in your interface, the upper-left corner of the board should be coordinate (1, 1). However, within the board array, the upper-left space would be coordinate (0, 0). Make sure the PlayerMove() function performs the appropriate offset calculation to ensure the piece is actually going where it belongs. The third argument is a two-dimensional array representing the board. The fourth argument is a character that represents the symbol that the player wants to place on the board. Ideally, you should use X and O. The ASCII codes used to represent these markers are set in the preprocessor directive within your program. The function should return TRUE is the move was successfully placed on the board. The function should return FALSE if the player attempts to make a move that is off of the board or make a move that collides with a piece that already exists on the board. Optionally, you can print a small error message on the screen if one of these error conditions
occurs. Make sure the printed error message results in an intuitive user interface once the program is complete.
int VictoryCheck(int, char[ROWS][COLS]);
FUNCTION EXPLANATION This functions first argument is an integer representing the number of adjacent symbols the player needs on the board in a horizontal, vertical, or diagonal fashion to win the game. The second argument is a two-dimensional array representing the board. The VictoryCheck() function should systematically scan the board looking for winners and return a value containing one of the predefined victory codes discussed in class. Please consult your weekly assignments for specific details on the victory codes NOWIN, MARKONEVICTORY, MARKTWOVICTORY, TIE, ERROR, EPIC_FAIL.
void DisplayVictoryMessage(int);
FUNCTION EXPLANATION The implementation for this function was provided in your weekly assignments. The function takes a single integer argument and displays a user-friendly message indicating the interpretation of a particular victory code.
After you have written definitions for each of the previously described functions, you must write core logic in the main() function that creates gameplay behavior. The optimal strategy for the core logic is to make extensive use of the functions that were already coded to make the game intuitively playable to the point where individuals with no programming knowledge could enjoy the program. You may assume the users will type in numbers when giving row and column coordinates to the program, but you can make no assumption about what numbers the users will type in. After your program is complete, ensure that all game ending conditions can be achieved and the program responds in a user-friendly manner. Be sure to give invalid numeric inputs for the row and column information to make sure the program handles the erroneous input gracefully. Ideally, if a player makes a mistake, re-prompt him/her for another move until something valid is given to the program. Your program should also be adaptive based on the values given in the ROWS, COLS, and CONSECUTIVE_MARKS_REQUIRED preprocessor directive statements. When the assignment is being graded, these values will be changed and your program must still be fully functional
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started