Coders Packet

Tic-tac-toe Game in C++

By Ayush Agrawal

This project consists of designing and building a computer program in C++ that allows 2 players to play tic-tac-toe against each other.

About the Game:

Tic-tac-toe is a two-player game. The two players take turns putting marks in a 3*3 board. The player who gets the first 3 of his/her symbol in a row (horizontally, diagonally or vertically) wins the game, and hence the other loses the game.

Game Rules:

In the program, the 3*3 board is considered to be a row order matrix having numbers from 1 to 9 in each cell respectively.

A game will consist of a sequence of the following actions:

1. First of all, the program will ask for the input of the field number or cell number in which the player wants to put his/her favourable mark. The player that gets to play with the 'X' symbol will play first (referred to as Player 1) and the player that gets to play with the 'O' symbol will play second (referred to as Player 2).

2. Player 1 and 2 take turns making moves. Before each move, the player is required to enter the position on the board which is empty or not occupied with any of the symbols. And after each move, the position on the matrix will be occupied by a symbol and the player will be switched.

3. The game/program ends when either:

    i. one of the players wins the game. In that case, the program will print "Player 1/2 Won!".

    ii. all the positions on the board are occupied. In this case, the game ends in a draw and it will print "Match draw!".

Download project

Reviews Report

Submitted by Ayush Agrawal (ayushagrawal41)

Download packets of source code on Coders Packet