Professional Documents
Culture Documents
The successful completion of this project mark the beginning of an ever - going
learning experience of converting ideas and concepts into real life, practical
system. This project was a quite a learning experience for me at each and every
step. At the same time it has given me confidence to work in professional setup. I
feel the experience gained during the project will lead me to gain the bright
prospect in the future.
DECLARATION
I, ABHISHEK KUMAR, Student of B.tech (CSE) declare that the project titled “TIC
TAC TOE ” which is submitted by me to Department of computer science and
engineering, B.N. College of engineering & Technology , Lucknow affiliated to
Abdul kalam Technical University.
• RAM:512 MB
• Display board
• Get players move
• Check for gameend
CODING
# include <iostream.h>
#include <conio.h>
int main()
{
int player =1,i,choice;
char mark;
clrscr();
do
{
board();
player=(player%2)?1:2;
cout << "Player " << player << ", enter a number: ";
cin >> 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
{
cout<<"Invalid move ";
player--;
getch();
}
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
1FOR GAME IS OVER WITH RESULT
-1FOR GAME IS IN PROGRESS
O GAME IS OVERAND NORESULT
**********************************************/
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()
{
clrscr();
cout << "\n\n\tTic TacToe\n\n";
cout << "Player 1(X) - Player 2 (O)" << endl << endl;
cout <<endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;
cout << " | | " << endl;
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;
cout << " | | " << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;
cout << " | | " << endl<< endl;
}
/*******************************************************************
END OF PROJECT
********************************************************************/
OUTPUT
Initialization Of Variables&
explanatory statements
Program comments are explanatory statements that we can include in the C++ code
that we write and helps anyone reading its source code. All programming languages
allow for some form of comments.
C++ supports single line and multi-line comments. All characters available inside any
comment are ignored by C++compiler.
C++ comments start with /* and end with */. For example:
// This is acomment
!!
the next portion of code
Each branch of the if statement makes two check, the first input
check that the input is valid digit from 1to 9 and second check is for
make sure of the input is digit not an character, second check also
make sure that the number which is entered not entered
Previously
Game Loops
( player's moves)
Note there are the nine ways to end the game, 8 conditions
to win the game and 1condition for draw the game.
The third if statement handles the 2 cases from the 9th square
In each of these cases we check that the squares not equals to its number
character.
This check ensures that we have an extra O and the other two checks make
sure that the other two squares have the same O in the series like this one
Those cases cover the win condition however game will be ended and draw like
this.
Game Loops
( player's moves)
After that we print the ending board of the game and tells
whose win and ask the user to play another game or quit
If the user want play again the looping is continue and the
board will be reset and the player turn also set back to 1
The final check takes cover of the case that game will be draw
and all the squares will be marked.
When we determine that the game is over we run through over
final condition
If the game is over we check for the game that someone is win
the game Boolean which we set at the last part, if some has
won then it will be last one or last player which is moved.
BIBLIOGRAPHY