Tic-Tac-toe C++ programe
  • Tic-Tac-toe C++ programe

About the Product

Tic-Tac-toe C++ program

Summary:

This C++ program is a Tic-Tac-Toe game that provides an interactive gaming experience for two players. Upon running the program, the players are prompted to enter their names, making the game more personalized. The game utilizes a 3×3 grid as the playing board, where each cell represents a box number that players can choose to place their respective symbols, ‘x’ or ‘o’.

A blank grid is displayed to start the game, and the players take turns entering their moves. The program ensures that each move is valid by checking if the selected box number is available and not already occupied by a symbol. If a player attempts to select an occupied box, the program prompts them to enter another number until a valid move is made.

The game continues until one player wins or all the boxes are filled, resulting in a draw. The program checks the rows, columns, and diagonals for three identical symbols in a row to determine the winner. If a winning condition is met, the program declares the respective player as the winner and displays a congratulatory message.

In the event of a draw, where all the boxes are filled without any winning combination, the program announces the game as a draw. It ensures that the game ends with a clear outcome, either a winner or a draw, and allows the players to replay the game if they wish to continue the fun.

The program includes various functions to handle different aspects of the game, such as displaying the initial blank grid, updating the grid with each move, and validating player inputs. These functions improve the efficiency and maintainability of the code, making it easier to manage and enhance in the future.

Excerpt:

Tic-Tac-toe C++ program

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
const int ROWS = 3;
const int COL = 3;

//Function prototypes
void pattern();
void pattern(int);
void pattern(char [][COL]);
void isValid1(char [][COL], int);
void isValid2(char [][COL], int);
int ifWon(char[][COL]);