Oop Microproject Group 1
Oop Microproject Group 1
● Rules of Tic-Tac-Toe
Following are the rules that define how to play
the tic tac toe game:
● A player can put only a single letter X or O
in the 3 x 3 grid in each chance.
● Both players will get chances alternatively
one after another till someone wins or
draws.
● To win this game, the player must create a
horizontal, vertical, or diagonal line
consisting of three same letters.
● The game is drawn, if all grids are filled with
X or O letters but no line is made.
Feature of Tic-Tac-Toe in C++
This game provides the following features:
● This game is developed on a 3×3 grid.
● This game is designed for two players.
● Every player may choose a letter between X
and O.
● Both players will get their chances to turn
by turn.
● Components of the Game
The game is made of the following
components that include the functions and
data structures to provide the basic
operations of the game.
1. Game Board
To create a tic-tac-toe board, a 3 x 3 array
initialized with space is used.
char board[3][3] = {{' ', ' ', ' '},
{' ', ' ', ' '}, {' ', ' ', ' '}};
In this array, we will fill the X and O
characters based on the moves of the players.
2. Movement Of Player
Now we will create a
function drawBoard() to display the Board. It
will initialize the array and display the board
after each move.
The logic for user input and valid input
checking is defined inside the main() function
itself.
How to check if the input is valid or not?
● Valid input: If the cell is empty and is within
the boundary
● Invalid input: If the cell has already been
#include <iostream>
return true;
return true;
return true;
return false;
int main()
{
// Initialize the board and players
// Game loop
drawBoard(board);
// Prompt for valid input
while (true) {
else {
board[row][col] = player;
if (checkWin(board, player)) {
drawBoard(board);
drawBoard(board);
return 0;
Output
Welcome to Tic-Tac-Toe!
-------------
| | | |
-------------
| | | |
-------------
| | | |
-------------
Player X, enter row (0-2) and column
(0-2): 1 1
-------------
| | | |
-------------
| | X | |
-------------
| | | |
-------------
Player O, enter row (0-2) and column
(0-2): 0 0
-------------
| O | | |
-------------
| | X | |
-------------
| | | |
-------------
Player X, enter row (0-2) and column
(0-2): 1 0
-------------
| O | | |
-------------
| X | X | |
-------------
| | | |
-------------
Player O, enter row (0-2) and column
(0-2): 2 2
-------------
| O | | |
-------------
| X | X | |
-------------
| | | O |
-------------
Player X, enter row (0-2) and column
(0-2): 1 2
-------------
| O | | |
-------------
| X | X | X |
-------------
| | | O |
-------------
Player X wins!
-------------
| O | | |
-------------
| X | X | X |
-------------
| | | O |
------------