Lab 10.1 - TicTacToe Write a C++ program that allows two players to play a game of Tic-Tac-Toe. You MUST use functions for this lab and use the three file structure (main.cpp, tictactoe.cpp, and tictactoe.h). Below are constant variables and functions that you MUST USE to complete this lab. If you want to create an additional set of functions, it is ok to do. const int NUM_PLAYERS = 2 local constant integer used to determined number of players const char PLAYER_TOKEN[NUM_PLAYERS] = {'X', 'O'} local constant array of characters to identify the player's token const int NUM_ROWS = 3 global constant integer used to determine number of rows in the TicTacToe board const int NUM_COLS = 3 global constant integer used to determine number of columns in the TicTacToe board void initializeBoard(char board[][NUM_COLS]) called to initialize all elements in the 2d array with '*' void displayBoard(const char board[][NUM_COLS]) display the board on the screen as shown in the example board display below void updateBoard(char board[][NUM_COLS], int row, int col, char playerToken) update the board's row and column element with the playerToken bool isValidMove(const char board[][NUM_COLS], int row, int col) return true if the row and col is a valid move, otherwise, return false bool isWin(const char board[][NUM_COLS],char playerToken) return true if the current player has won, otherwise, return false bool isFull(const char board[][NUM_COLS]) return true if the board is full, otherwise, return false Game Loops Almost every game has a game loop. A game loop runs continuously during gameplay. Each turn of the loop, it processes user input, updates the game state, and renders the game It also tracks the passage of time to control the rate of gameplay. However, since we will not be doing any game animation, this doesn't really matter in this case. // game setup / initialization // game Loop bool isDone = false; // game over??? while (!isDone) { // process input // update // render } Game Pseudocode 1. Create a two-dimensional char array with three rows and three columns as the game board. 2. Each element of the array should be initialized with a value such as an asterisk '*'. 3. The program should display the initial board configuration and then 4. Start of the game loop that does the following: a. Have player 1 select a board location by entering a row and column number. b. Then redisplay the board with an 'X' replacing the '*' in the chosen location. c. If there is no winner yet and the board is not yet full, continue below, otherwise game ends d. Have player 2 select a board location by entering a row and column number. e. Then redisplay the board with an 'O' replacing the '*' in the chosen location. f. If there is no winner yet and the board is not yet full, repeat the loop, otherwise game ends Game Ends The loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or report a tie. Player 1 wins when there are three 'X' characters in a row, a column, or a diagonal on the game board. Player 2 wins when there are three 'O' characters in a row, a column, or a diagonal on the game board. A tie occurs when all of the locations on the board are full, but there is no winner. Other Requirements Input validation: Only allow legal moves to be entered. The row and column MUST be 1, 2, or 3. The selected board location must currently be empty (still have an '*' character). Commit your code throughout the development process.
Lab 10.1 - TicTacToe Write a C++ program that allows two players to play a game of Tic-Tac-Toe. You MUST use functions for this lab and use the three file structure (main.cpp, tictactoe.cpp, and tictactoe.h). Below are constant variables and functions that you MUST USE to complete this lab. If you want to create an additional set of functions, it is ok to do. const int NUM_PLAYERS = 2 local constant integer used to determined number of players const char PLAYER_TOKEN[NUM_PLAYERS] = {'X', 'O'} local constant array of characters to identify the player's token const int NUM_ROWS = 3 global constant integer used to determine number of rows in the TicTacToe board const int NUM_COLS = 3 global constant integer used to determine number of columns in the TicTacToe board void initializeBoard(char board[][NUM_COLS]) called to initialize all elements in the 2d array with '*' void displayBoard(const char board[][NUM_COLS]) display the board on the screen as shown in the example board display below void updateBoard(char board[][NUM_COLS], int row, int col, char playerToken) update the board's row and column element with the playerToken bool isValidMove(const char board[][NUM_COLS], int row, int col) return true if the row and col is a valid move, otherwise, return false bool isWin(const char board[][NUM_COLS],char playerToken) return true if the current player has won, otherwise, return false bool isFull(const char board[][NUM_COLS]) return true if the board is full, otherwise, return false Game Loops Almost every game has a game loop. A game loop runs continuously during gameplay. Each turn of the loop, it processes user input, updates the game state, and renders the game It also tracks the passage of time to control the rate of gameplay. However, since we will not be doing any game animation, this doesn't really matter in this case. // game setup / initialization // game Loop bool isDone = false; // game over??? while (!isDone) { // process input // update // render } Game Pseudocode 1. Create a two-dimensional char array with three rows and three columns as the game board. 2. Each element of the array should be initialized with a value such as an asterisk '*'. 3. The program should display the initial board configuration and then 4. Start of the game loop that does the following: a. Have player 1 select a board location by entering a row and column number. b. Then redisplay the board with an 'X' replacing the '*' in the chosen location. c. If there is no winner yet and the board is not yet full, continue below, otherwise game ends d. Have player 2 select a board location by entering a row and column number. e. Then redisplay the board with an 'O' replacing the '*' in the chosen location. f. If there is no winner yet and the board is not yet full, repeat the loop, otherwise game ends Game Ends The loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or report a tie. Player 1 wins when there are three 'X' characters in a row, a column, or a diagonal on the game board. Player 2 wins when there are three 'O' characters in a row, a column, or a diagonal on the game board. A tie occurs when all of the locations on the board are full, but there is no winner. Other Requirements Input validation: Only allow legal moves to be entered. The row and column MUST be 1, 2, or 3. The selected board location must currently be empty (still have an '*' character). Commit your code throughout the development process.
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
Related questions
Question
Lab 10.1 - TicTacToe
Write a C++ program that allows two players to play a game of Tic-Tac-Toe.
-
You MUST use functions for this lab and use the three file structure (main.cpp, tictactoe.cpp, and tictactoe.h). Below are constant variables and functions that you MUST USE to complete this lab. If you want to create an additional set of functions, it is ok to do.
- const int NUM_PLAYERS = 2
- local constant integer used to determined number of players
- const char PLAYER_TOKEN[NUM_PLAYERS] = {'X', 'O'}
- local constant array of characters to identify the player's token
- const int NUM_ROWS = 3
- global constant integer used to determine number of rows in the TicTacToe board
- const int NUM_COLS = 3
- global constant integer used to determine number of columns in the TicTacToe board
- void initializeBoard(char board[][NUM_COLS])
- called to initialize all elements in the 2d array with '*'
- void displayBoard(const char board[][NUM_COLS])
- display the board on the screen as shown in the example board display below
- void updateBoard(char board[][NUM_COLS], int row, int col, char playerToken)
- update the board's row and column element with the playerToken
- bool isValidMove(const char board[][NUM_COLS], int row, int col)
- return true if the row and col is a valid move, otherwise, return false
- bool isWin(const char board[][NUM_COLS],char playerToken)
- return true if the current player has won, otherwise, return false
- bool isFull(const char board[][NUM_COLS])
- return true if the board is full, otherwise, return false
- const int NUM_PLAYERS = 2
Game Loops
Almost every game has a game loop. A game loop runs continuously during gameplay. Each turn of the loop,
- it processes user input,
- updates the game state, and
- renders the game
It also tracks the passage of time to control the rate of gameplay. However, since we will not be doing any game animation, this doesn't really matter in this case.
// game setup / initialization // game Loop bool isDone = false; // game over??? while (!isDone) { // process input // update // render }
Game Pseudocode
1. Create a two-dimensional char array with three rows and three columns as the game board. 2. Each element of the array should be initialized with a value such as an asterisk '*'. 3. The program should display the initial board configuration and then 4. Start of the game loop that does the following: a. Have player 1 select a board location by entering a row and column number. b. Then redisplay the board with an 'X' replacing the '*' in the chosen location. c. If there is no winner yet and the board is not yet full, continue below, otherwise game ends d. Have player 2 select a board location by entering a row and column number. e. Then redisplay the board with an 'O' replacing the '*' in the chosen location. f. If there is no winner yet and the board is not yet full, repeat the loop, otherwise game ends
Game Ends
- The loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or report a tie.
- Player 1 wins when there are three 'X' characters in a row, a column, or a diagonal on the game board.
- Player 2 wins when there are three 'O' characters in a row, a column, or a diagonal on the game board.
- A tie occurs when all of the locations on the board are full, but there is no winner.
Other Requirements
- Input validation: Only allow legal moves to be entered. The row and column MUST be 1, 2, or 3. The selected board location must currently be empty (still have an '*' character).
- Commit your code throughout the development process.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education