0% found this document useful (0 votes)
13 views21 pages

Final Updated Report Format

The document is a project report on a Tic-Tac-Toe game implemented in C++ for the Artificial Intelligence & Data Science program at Savitribai Phule Pune University. It details the game's design, features, and programming logic, highlighting its educational value and potential for enhancements such as AI opponents. The report includes acknowledgments, an abstract, and sections on hardware/software requirements, advantages/disadvantages, and the source code.

Uploaded by

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

Final Updated Report Format

The document is a project report on a Tic-Tac-Toe game implemented in C++ for the Artificial Intelligence & Data Science program at Savitribai Phule Pune University. It details the game's design, features, and programming logic, highlighting its educational value and potential for enhancements such as AI opponents. The report includes acknowledgments, an abstract, and sections on hardware/software requirements, advantages/disadvantages, and the source code.

Uploaded by

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

Savitribai Phule Pune University

A Project Report On

“ TIC TAC TOE GAME ”

SUBMITTED TO THE SAVITRIBAI PHULE PUNE UNIVERSITY


IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE AWARD OF THE DEGREE

SECOND YEAR
(Artificial Intelligence & Data Science)

SUBMITTED BY

Swanand Wakadmane

Vishal Gawade

Yash Jagtap

Under the Guidance


of
Ms. Pachhade R.C.

Department of Artificial Intelligence & Data Science

Vishwabharati Academy’s College of Engineering, Sarola


Baddi,Ahmednagar 414201
2024-25
Department of Artificial Intelligence & Data Science

Vishwabharati Academy’s College of Engineering Sarola


Baddi,Ahmednagar 414201

CERTIFICATE

This is to certify that the report entitled

“ TIC TAC TOE GAME”

Submitted by

Swanand Wakadmane Exam Seat No:

Vishal Gawade Exam Seat No:

Yash Jagtap Exam Seat No:

Is a bonafide work carried out under the supervision of "Ms.Pachhade R.C.” and it
is submitted towards the partial fulfillment of the requirement of Savitribai Phule
Pune University, Pune for the award of the degree of Second year of Engineering
(Artificial Intelligence & Data Science).

(Ms.Pachhade R.C.) (Ms.Pachhade R.C.)


Artificial Intelligence & Data Science

Place: Ahmednagar Date: 21/10/2024


ACKNOWLEDGEMENT

I profoundly grateful to Ms.Pachhade R.C. for her expert guidance and


continuous encouragement throughout to see that this Report rights its target since
its commencement to its completion. I would like to express deepest appreciation
towards Principal, Vishwabharati Academy’s College of Engineering,
Ahmednagar, Ms.Pachhade R.C., Head of Department of Artificial Intelligence &
Data Science whose invaluable guidance supported me in completing this mini
project. At last I must express my sincere heartfelt gratitude to all the staff members
of Artificial Intelligence & Data Science Department who helped me directly or
indirectly during this course of work.
ABSTRACT

This project presents a Tic-Tac-Toe game implemented in C++,


showcasing fundamental programming concepts and graphical user
interface design. The game allows two players to compete in a
classic grid-based format, where they take turns placing their
symbols (X or O) on a 3x3 grid. The program incorporates features
such as user input handling, real-time graphical rendering, and game
logic to determine winning conditions and draws. The application
leverages the graphics.h library to create an interactive experience,
displaying the game board, player indicators, and game outcomes.
The code structure is modular, facilitating easier maintenance and
potential enhancements, such as the introduction of an AI opponent
or network play. This Tic-Tac-Toe game serves as both a
recreational tool and an educational resource, demonstrating key
programming practices, including conditionals, loops, and
functions. Through this implementation, users gain insights into the
process of game development and the application of algorithms in
creating engaging interactive experiences.
CONTENTS

ACKNOWLEDGEMENT
ABSTRACT

1. INTRODUCTION. ......................................................................... 01
2. FUNCTIONS TO BE USED ........................................................... 02
3. HARDWARE & SOFTWARE REQUIREMENTS ...................... 03
4. APPLICATIONS ............................................................................ 04
5. ADVANTAGES & DISADVANTGES ......................................... 05
6. PROGRAMMING MODULE ........................................................ 06
7. SOURCE CODE .............................................................................. 07
8. OUTPUT........................................................................................... 08
9. FUTURE APPLICATION .............................................................. 09
10. CONCLUSION ................................................................................ 10
11. REFERENCES ................................................................................ 11
Chapter : 1
INTRODUCTION

This program implements a graphical version of the classic Tic-Tac


Toe game using C++ with graphics. Tic-Tac-Toe is a simple two-
player game where each player takes turns marking a 3x3 grid with
their symbol (either 'X' or 'O'). The objective is to be the first to
align three of their symbols in a row, column, or diagonal.

The program uses a graphical interface to display the grid and


allows players to move their cursor using the arrow keys. Players
mark their symbol in an empty cell by pressing the spacebar. The
program checks after each move if the current player has won or if
the game has resulted in a draw. Once the game ends, the result
(win or draw) is displayed along with a simple visual effect to
celebrate the outcome.

The graphics in the program are managed using the `graphics.h`


library, which was commonly used in older DOS-based
environments like Turbo C++. The game uses several utility
functions to handle user input, draw the grid, check for wins or
draws, and handle the end game sequence.

This program serves as a great example of combining fundamental


game logic with graphical elements in C++, making it both
educational and fun to play!
Chapter : 2
FUNCTIONS TO BE USED

Sr.No. Function to be used Description

1 int main() The main function where


the game loop and overall
logic are executed.
2 int getkey() This function captures and
returns arrow key inputs
from the user, allowing
movement within the grid.
3 void display(int sx, int sy) This function displays the
current Tic-Tac-Toe grid
on the screen, including
highlighting the selected
cell.
4 int checkWin(int sx, int sy, int This function checks if
the current player has won
player) the game. It returns 1 if the
player wins, otherwise 0.
5 int checkDraw(int sx, int sy) This function checks if the
game has resulted in a
draw (i.e., all cells are
filled, but no player has
won). It returns 1 if it's a
draw, otherwise 0.
6 void end(const char* str) This function is called
when the game ends
(either through a win or a
draw). It displays the
result and creates a visual
effect with circles and
sound.
Chapter : 3

HARDWARE & SOFTWARE


REQUIREMENTS

Problem Statement :
Design and implement a graphical Tic-Tac-Toe game using C++
that allows two players to play the game in real-time on a 3x3
grid.
The program should use the graphics.h library to render the grid
and other visual elements, providing an
engaging graphical interface for the players. The game should be
simple, intuitive, and responsive to user input.

Hardware Requirement :
Any Intel Pentium or later processor.
At least 4 MB of RAM.
A graphics card that supports DOS graphics modes.

Software Requirement:
Turbo C++ (or Turbo C): This is the most commonly used IDE
and compiler for C and C++ programs using graphics.h.
Chapter :8
6
APPLICATION

• Learning Tool for Beginners. - This program provides a


basic introduction to game logic and flow, making it a great
learning resource for beginners in C++ programming.

• Introduction to 2D Graphics. - This program shows how to


build a simple graphical interface from scratch using basic
shapes like rectangles, and text rendering, which can be
extended to more complex graphical applications.

• Game Logic Implementation. - The game logic can be


expanded to implement an AI opponent for single-player
mode. This would give developers experience in building
decision-making algorithms and strategies.

• Software Testing Practice. - The Tic-Tac-Toe program


provides a simple environment for practicing manual and
automated testing techniques. Testers can write test cases for
winning conditions, draws, and invalid moves.

• Educational Game for Kids. - This simple Tic-Tac-Toe


game can be used as an educational tool for young children to
learn about patterns, logic, and strategy while having fun.
Chapter :8
7
ADVANTAGES & DISADVANTGES

ADVANTAGES:

Educational Value-
• Simple Game Logic: The game is easy to understand and
provides beginners a great opportunity to learn basic game
development principles such as grid-based logic, turn-based
systems, and handling user input.
• Introduction to Graphics Programming: Using the

graphics.h library introduces students to 2D graphical


programming in C++, which is more engaging than simple
console-based programs.

Minimal Resource Requirements-


• Lightweight: The program can run on older hardware with
minimal processing power and memory, making it accessible
for almost any system.
• Simple Dependencies: Only the Turbo C++ compiler and
graphics.h library are needed, making it easy to set up and
run in a DOS-like environment or using emulation.

Visual and Interactive-


• The graphical interface makes the game more engaging than
a text-based version. It allows users to visually see the grid,
symbols, and interact using arrow keys, making the learning
experience more interactive.
Chapter :8
8
DISADVANTAGES:

Outdated Graphics Library (graphics.h):


• Legacy Code: The graphics.h library is outdated and
primarily supported in old Turbo C++ compilers or DOS
environments. It is no longer supported or useful for modern
graphical programming, making it difficult to port to modern
systems without modification.

Non-Portable:
• DOS-Specific Environment: Since the code relies on Turbo

C++ and the DOS-based graphics.h library, it cannot run


natively on modern operating systems like Windows, macOS,
or Linux without using emulators like DOSBox.

Lack of Error Handling:


• Rigid Input Handling: The program may not handle

unexpected inputs (like invalid keys) gracefully, and the error


handling is minimal. This can make the game crash or behave
unexpectedly if improper input is given.
Chapter :8
9
PROGRAMMING MODULE
Module 1: Main Game Module
• Purpose: This module serves as the entry point for the game, managing the
overall game loop and player interactions.
• Functions:
int main(): Initializes graphics, runs the main game loop, and handles
player turns until the game ends.

Module 2: Graphics Module


• Purpose: Responsible for rendering the game interface, including the grid
and player symbols.
• Functions:
o void display(int sx, int sy): Draws the Tic-Tac-Toe grid on the
screen, highlights the selected cell, and displays player symbols.

Module 3: Input Handling Module


• Purpose: Manages user inputs, including keyboard interactions for moving
the cursor and making selections.
• Functions:
o int getkey(): Captures keyboard input, specifically arrow keys for
navigation and the spacebar for selecting cells.

Module 4: Game Logic Module


• Purpose: Contains functions that handle the rules of the game, such as
checking for wins and draws.
• Functions:
int checkWin(int sx, int sy, int player): Checks if the current player has won by
evaluating rows, columns, and diagonals.

Module 5: Game State Module


• Purpose: Manages the game state, including the grid's current configuration
and player turns.
• Data Structures:
o char grid[3][3]: A 2D array representing the game board, with each
cell initialized to blank and filled with 'X' or 'O' during the game.
Chapter :8
10
SOURCE CODE
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <string.h>
#include <time.h>
#include <dos.h>

#define d 35 // d=distance
#define s 30 // s=size
#define f 200 // f=display coordinate factor
#define mx getmaxx()
#define my getmaxy()

using namespace std;

char grid[3][3];

int getkey(); // To capture arrow keys pressed


void display(int, int); // To display grid
int checkWin(int, int, int); // Check win; return 1 if any one of two
players win else 0
int checkDraw(int, int); // Check draw; return 1 if draw else 0
void end(const char*); // Game end

int main() {
int gd, gm, sx = 0, sy = 0, i, j, k, count = 2, player;
char str[25], ch;

detectgraph(&gd, &gm);
initgraph(&gd, &gm, "C:\\TC\\BGI");

for (i = 0; i < 3; i++) // Initialize grid with blank


spaces
for (j = 0; j < 3; j++)
Chapter : 8
grid[i][j] = ' ';

settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); // Initialize text style

while (1) {
cleardevice();
// Print TIC-TAC-TOE on screen
setcolor(BLUE);
outtextxy(200, 150, "TIC-TAC-TOE");
// Print current Player number
player = count % 2;
sprintf(str, "Player : %d (%c)", player + 1, player ? 'O' : 'X');
setcolor(WHITE);
outtextxy(350, 250, str);
display(sx, sy);
ch = getkey(); // Capture arrow key input
switch (ch) {
case 72: // Up arrow
if (sy != 0)
sy--;
break;
case 80: // Down arrow
if (sy != 2)
sy++;
break;
case 75: // Left arrow
if (sx != 0)
sx--;
break;
case 77: // Right arrow
if (sx != 2)
sx++;
break;
case ' ': // Space key
if (grid[sy][sx] == ' ') { // Mark the cell only if it is empty
if (player == 0)
grid[sy][sx] = 'X';
else
grid[sy][sx] = 'O';
Chapter : 8
count++;
}
break;
case 'e':
case 'E': //'e' or 'E' key
cleardevice();
closegraph();
return 0;
default:
break;
}
if (checkWin(sx, sy, player) == 1 || checkDraw(sx, sy) == 1)
break;
}
return 0;
}

int getkey() {
int ch;
ch = getch();
if (ch == 0) {
ch = getch();
return ch;
}
return ch;
}

void display(int sx, int sy) {


int i, j;
char str[2];
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if (j == sx && i == sy) // If the cell is selected
setcolor(RED);
else
setcolor(WHITE); // For non-selected cell
rectangle(j * d + f, i * d + f, j * d + s + f, i * d + s + f);
sprintf(str, "%c", grid[i][j]); // To print Player's symbol in cell
Chapter : 8
outtextxy(j * d + 8 + f, i * d + 8 + f, str);
}
}
}

int checkWin(int sx, int sy, int player) {


char str[25];
int i;
for (i = 0; i < 3; i++) {
if ((grid[i][0] == grid[i][1] && grid[i][0] == grid[i][2] && grid[i][0] !=
' ') ||
(grid[0][i] == grid[1][i] && grid[0][i] == grid[2][i] && grid[0][i] !=
' ')) {
display(sx, sy);
getch();
sprintf(str, "Player %d (%c) You Won!!!", player + 1, player ? 'O' :
'X');
end(str);
return 1;
}
if ((grid[0][0] == grid[1][1] && grid[1][1] == grid[2][2] && grid[2][2]
!= ' ') ||
(grid[0][2] == grid[1][1] && grid[1][1] == grid[2][0] && grid[2][0]
!= ' ')) {
display(sx, sy);
getch();
sprintf(str, "Player %d (%c) You Won!!!", player + 1, player ? 'O' :
'X');
end(str);
return 1;
}
}
return 0;
}

int checkDraw(int sx, int sy) {


int i, j, k = 0;
char str[25];
for (i = 0; i < 3; i++)
Chapter : 8
for (j = 0; j < 3; j++)
if (grid[i][j] != ' ')
k++;
if (k == 9) { // All cells marked but yet no win i.e. Draw
display(sx, sy);
getch();
sprintf(str, "The game is draw!!!");
end(str);
return 1;
}
return 0;
}

void end(const char* str) {


int i, j;
delay(800);
cleardevice();
setcolor(WHITE);
outtextxy(mx / 2 - 150, my / 2, str);
for (i = 0, j = 0; i < 400; i += 14) {
j = (i < 200) ? 0 : 1;
setcolor(j);
sound(200 * j);
circle(mx / 2, my / 2, i);
delay(100);
}
nosound();
outtextxy(mx / 2 - 150, my / 2, str);
getch();
closegraph();
}
Chapter : 8

OUTPUT
Chapter:9

FUTURE APPLICATION
1. AI Opponent:

• Description: Implement an AI that plays against the user. Use algorithms


like Minimax to create a challenging opponent.

• Benefits: Enhances gameplay by allowing single-player mode against the


computer.

2. Multiplayer Mode over Network:

• Description: Extend the game to support multiplayer gameplay over a


network using sockets or a game server.

• Benefits: Allows players to compete with friends or others online,


increasing the game's reach and enjoyment.

3. Graphical User Interface (GUI) Enhancement:

• Description: Transition from a text-based interface to a more sophisticated


GUI using libraries like Qt or SFML.

• Benefits: Improves user experience with a modern look and feel, including
animations and better interactions.

4. Mobile Application:

• Description: Adapt the code to create a mobile version for Android or iOS
using frameworks like Cocos2d-x or Unity.

• Benefits: Expands accessibility, allowing players to enjoy the game on their


mobile devices.
Chapter:11

CONCLUSION

The C++ Tic-Tac-Toe program exemplifies a classic game that combines


simplicity with strategic depth, offering an engaging experience for players
of all ages. Through the implementation of various programming concepts,
including user input handling, game logic, and graphics rendering, this
project demonstrates the essential elements of game development.
Chapter:11

REFERENCES

• https://www.geeksforgeeks.org/implementation-of-tic-tac-toe-game/

• https://www.scribd.com/document/385171876/Tic-Tac-Toe-
Documentation-in-python-3

• https://www.researchgate.net/publication/365802213_Implementation
_of_a_Tic-Tac-
Toe_game_Using_Python_Environment_for_gaming_application

• https://graphicswithc.wordpress.com/

• https://github.com/Ahsan483/

You might also like