Tic Tac Toe
Tic Tac Toe
Tic Tac Toe
We would also like to thank our parents for their undivided support and
interest and also providing the necessary facilities regarding financial
matters. At last we would like to thank our friends for motivating us.
1|TIC-TAC-TOE
CERTIFICATE OF APPROVAL
(4) SamratSaha
(5) SubhasishBhowmik
2|TIC-TAC-TOE
CANDIDATES DECLARATION
3|TIC-TAC-TOE
CONTENTS
Page
SL.NO. TITLE No.
1. OVERVIEW OF C++ 5
2. PROGRAMMING METHODOLOGY 6
3. SOFTWARE REQUIREMENTS 7
5. INTRODUCTION TO TIC-TAC-TOE 9
10-15
6. SOURCE CODE
16-20
7. OUTPUT
8. CONCLUSION 21
9. BIBLIOGRAPHY 22
4|TIC-TAC-TOE
OVERVIEW OF C++
5|TIC-TAC-TOE
PROGRAMMING METHODOLOGY
In order to clearly understand the object orientation, let’s take your ‘hands’ as
example, the ‘hand’ is a class. Your body has two objects of type hand, named
left hand and right hand. Their functions are controlled/managed by the set of
electrical signals sent through your shoulders(through an interface). So, the
shoulder is an interface which your body uses to interact with your hand. The
hand is being copied to create the left hand and the right hand by slightly
changing the properties of it.
6|TIC-TAC-TOE
SOFTWARE REQUIREMENTS
REQUIREMENTS:
Minimum Recommended
7|TIC-TAC-TOE
PURPOSE OF HEADER FILES USED
#include<iostream.h>
#include<conio.h>
#include<string.h>
8|TIC-TAC-TOE
INTRODUCTION TO
TIC-TAC-TOE
Tic-Tac-Toe(Noughts & Crosses or X & O)is a pencil & paper game for
two players, ‘X’&‘O’, who take turns making the spaces in a 3X3 grid.
The player who succeeds in placing 3 respective marks in a horizontal,
vertical, or diagonal row wins the game.
This game uses board to control players. In each turn players enter a
number and choose a move. Simply programming assumes that player
one always moves first and uses ‘X’ & Player two moves at 2nd position
and uses ‘O’.
9|TIC-TAC-TOE
SOURCE CODE
#include<iostream.h>
#include<string.h>
#include<conio.h>
char
square[10]={'0','1','2','3','4','5','6','7','8','9'};
intcheckwin();
void board();
intmain()
{
int player=1,i,choice;
char mark;
clrscr();
do
{
board();
player=(player%2)?1:2;
cout<<"Player "<<player<<", Enter a Number:";
cin>>choice;
10 | T I C - T A C - T O E
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
{
cout<<"Invalid move";
player--;
getch();
}
11 | T I C - T A C - T O E
i=checkwin();
player++;
}while(i==-1);
board();
if(i==1)
cout<<"==>\aPlayer "<<--player<<" Win!";
else
cout<<"==>\aGame Draw";
getch();
return 0;
}
/****************************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
0 GAME IS OVER AND NO RESULT
****************************************************/
intcheckwin()
{
if(square[1]==square[2] && square[2]==square[3])
return 1;
else if(square[4]==square[5] &&
square[5]==square[6])
return 1;
12 | T I C - T A C - T O E
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;
}
13 | T I C - T A C - T O E
/****************************************************
****************************************************/
void board()
{
clrscr();
cout<<"\n\n\t TIC TAC TOE\n\n";
cout<<"\npresented by:\n\n 1.Prantik Chakraborty\t
2.Bishal Paul\t 3.Debajit Ghosh\n 4.Samrat Saha\t
5.Subhasish Bhowmik\n\n";
14 | T I C - T A C - T O E
cout<<"___|___|___"<<endl;
cout<<" | | "<<endl;
cout<<" "<<square[7]<<" | "<<square[8]<<" |
"<<square[9]<<endl;
cout<<" | | "<<endl<<endl;
}
15 | T I C - T A C - T O E
OUTPUT
(i)
(ii)
16 | T I C - T A C - T O E
(iii)
(iv)
17 | T I C - T A C - T O E
(v)
(vi)
18 | T I C - T A C - T O E
(vii)
(viii)
19 | T I C - T A C - T O E
(ix)
20 | T I C - T A C - T O E
CONCLUSION
21 | T I C - T A C - T O E
BIBLIOGRAPHY
To make this project we have taken help with the source from
Github.com & Stackoverflow.com.
22 | T I C - T A C - T O E