0% found this document useful (0 votes)
47 views8 pages

Tic Tac Toe Report

Uploaded by

dipanshugaur676
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Tic Tac Toe Report

Uploaded by

dipanshugaur676
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DEPARTMENT OF INFORMATION COMMUNICATION &

TECHNOLOGY

Project Title: TIC TAC TOE GAME


SUBJECT : C LANGUAGE
Session: 2021-22
Submitted to: Mr. Ajay Dureja
Program & Semester BCA 1st Semester
Group
Members :Ayush Arya, Abhishek rana, Akib Javed, Aman, Aman
Sharma
Software Used: Turbo C++

ABSTRACT:

Our project name is Tic-Tac-Toe game. This game is very popular and is
fairly simple by itself. It is actually a two player game. In this game, there
is a board with n x n squares. In our game, it is 3 x 3 squares.
The goal of Tic-Tac-Toe is to be one of the players to get three same
symbols in a row - horizontally, vertically or diagonally - on a 3 x 3 grid.

Overview:

This game can be played in a 3x3 grid (shown in the figure 2.1) .The game
can be played by two players. There are two options for players:

(a) Human (b) Computer


Players:

For the option human, both the players are human and for the option
computer, the first player is human and the second player is
computer.

Theory of Game:

A player can choose between two symbols with his opponent, usual games
use “X”and “O”. If first player choose “X” then the second player have to
play with “O” and vice versa.

A player marks any of the 3x3 squares with his symbol (may be “X” or “O”)
and his aim is to create a straight line horizontally or vertically or diagonally
with two intensions:

a) Create a straight line before his opponent to win the game.

b) Restrict his opponent from creating a straight line first.

In case logically no one can create a straight line with his own symbol, the
game results a tie.

Hence there are only three possible results – a player wins, his
opponent (human or computer) wins or it’s a tie.

Proposed gaming system

The Tic Tac Toe game is a game for two players, called "X" and "O", who take
turns marking the spaces in a 3×3 grid. The player who succeeded in placing three
respective marks in a horizontal, vertical, or diagonal row wins the game. The Tic
Tac Toe is a great way to pass your free time whether you're standing in a line or
spending time with your kids. Stop wasting paper and save trees. Because of the
simplicity of Tic Tac Toe, it is often used as a pedagogical tool for teaching the
concepts of good sportsmanship and the branch of artificial intelligence
OUTPUT
CODE:

#include <stdio.h>
#include <conio.h>

char square[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

int checkwin();
void board();

int main()
{
int player = 1, i, choice;

char mark;
do
{
board();
player = (player % 2) ? 1 : 2;

printf("Player %d, enter a number: ", player);


scanf("%d", &choice);

mark = (player == 1) ? 'X' : 'O';


if (choice == 1 && square[1] == '1')
square[1] = mark;

else if (choice == 2 && square[2] == '2')


square[2] = mark;

else if (choice == 3 && square[3] == '3')


square[3] = mark;

else if (choice == 4 && square[4] == '4')


square[4] = mark;

else if (choice == 5 && square[5] == '5')


square[5] = mark;

else if (choice == 6 && square[6] == '6')


square[6] = mark;

else if (choice == 7 && square[7] == '7')


square[7] = mark;

else if (choice == 8 && square[8] == '8')


square[8] = mark;

else if (choice == 9 && square[9] == '9')


square[9] = mark;

else
{
printf("Invalid move ");

player--;
getch();
}
i = checkwin();

player++;
}while (i == - 1);

board();

if (i == 1)
printf("==>\aPlayer %d win ", --player);
else
printf("==>\aGame draw");
getch();

return 0;
}

/*********************************************

FUNCTION TO RETURN GAME STATUS


1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/

int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;

else if (square[4] == square[5] && square[5] == square[6])


return 1;

else if (square[7] == square[8] && square[8] == square[9])


return 1;

else if (square[1] == square[4] && square[4] == square[7])


return 1;

else if (square[2] == square[5] && square[5] == square[8])


return 1;

else if (square[3] == square[6] && square[6] == square[9])


return 1;

else if (square[1] == square[5] && square[5] == square[9])


return 1;

else if (square[3] == square[5] && square[5] == square[7])


return 1;

else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7]
!= '7' && square[8] != '8' && square[9] != '9')

return 0;
else
return - 1;
}

/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK

*******************************************************************
*/

void board()
{
system("cls");
printf("\n\n\tTic Tac Toe\n\n");

printf("Player 1 (X) - Player 2 (O)\n\n\n");

printf(" | | \n");
printf(" %c | %c | %c \n", square[1], square[2], square[3]);

printf("_____|_____|_____\n");
printf(" | | \n");

printf(" %c | %c | %c \n", square[4], square[5], square[6]);

printf("_____|_____|_____\n");
printf(" | | \n");

printf(" %c | %c | %c \n", square[7], square[8], square[9]);

printf(" | | \n\n");
}

/*******************************************************************
END OF PROJECT

*******************************************************************
*/

Learning Outcomes:
After Making this project student will able to :
1) Use the Arrays
2) Concept of functions
References:
1) https://www.academia.edu/28164640/Project_Report_Tic_Tac_Toe
2) https://fdocuments.in/document/report-for-mini-projecttic-tac-toe-using-
c.html
3) https://www.codewithc.com/mini-project-in-c-tic-tac-toe-game/

You might also like