1|Page
TIC – TAC – TOE GAME
In PYTHON 3
2|Page
MINOR PROJECT REPORT
PYTHON (BCAB07L)
(TIC-TAC-TOE Game)
Programming Lab - VI
A report submitted to Punjabi University, PATIALA in
partial fulfilment of the requirement for the award of
degree course
In
BACHELOR OF COMPUTER APPLICATIONS (BCA)
(2025-2026)
6TH SEMESTER
(DEPARTMENT OF COMPUTER SCIENCE)
Submitted to: Submitted by:
AKASHDEEP Name: Muskan
(Assistant Professor) Roll No:
BABA MONI JI GROUP OF INSTITUTIONS
LEHRA MOHABBAT (BATHINDA)
3|Page
CONTENT
Sr. No. TITLE Page No.
1. Abstract 4
2. Introduction 5
3. System Analysis 6 to 8
4. System Specification 9-10
5. Software Description 11-12
6. Project Description 13 to 20
7. Code Execution 21 to 23
8. Use Case Diagram 24
9. Methods 25
10. Coding 26 to 33
11. Limitations 34
12. Future Plan 34
13. Reference 34
4|Page
1. ABSTRACT
Tic-Tac-Toe is a classic two - player strategy game played on a 3×3 grid,
where players take turns marking spaces with ‘X’ and ‘O’. The objective
of the game is to form a line of three matching symbols horizontally,
vertically, or diagonally before the opponent. This game is believed to
have originated from an ancient Roman game called Terni Lapilli,
making it one of the oldest known strategy games.
This project focuses on the creation and development of the Tic-Tac-Toe
game using basic programming concepts such as loops, conditional
statements, and functions. The game system allows two players to play
alternately, ensures valid moves, updates the game board after each turn,
and checks for winning or draw conditions.
The development of this project demonstrates fundamental programming
skills and logical thinking. It provides a simple and interactive platform for
users while helping developers understand game design and structure.
The project can be further enhanced by adding features like a computer-
Based opponent (AI), Graphical User Interface (GUI), and score tracking
system.
5|Page
2. INTRODUCTION
2.1 OBJECTIVE:
One of the most universally played childhood games is TIC
TAC TOE. An interactive TIC TAC TOE game is developed
where two players will be able to play against each other in a
suitable GUI by using proper mouse movements. This game
will start by showing a simple display, prompt the user for a
move and then prints the new board. The board looks like a
large hash symbol (#) with nine slots that can each contain an
X, an O, or a blank. There are two players, the X player and
the O player. By default, player1 (the O player) takes the
initiative. The game will end in two situations: a win, when one
player gets three in a row, horizontally, vertically or diagonally.
A draw, when there are no remaining places to choose and
neither of them has won. Here are some rules for the game:
The player with symbol ʒO or ʓX goes first
Players alternate placing X s and O s on the board until either
one player has three in a row, horizontally, vertically or diagonally; or
all nine squares are filled.
The player who can draw three X s or three O s in a row wins.
If all nine squares are filled and none of the players have three in a row,
the game is a draw.
3 SYSTEM ANALYSIS
6|Page
INTRODUCTION:
Tic-Tac-Toe is a simple and popular two-player game that is
played on a 3×3 grid. Each player chooses a symbol, either
‘X’ or ‘O’, and takes turns marking empty spaces on the grid.
The main goal of the game is to place three matching symbols
in a straight line, either horizontally, vertically, or diagonally. If
all the spaces are filled and no player achieves this, the game
ends in a draw.
This game has been played for many years and is easy to
understand, making it suitable for players of all ages. In the
field of computer science, Tic-Tac-Toe is often used as a
basic example to learn programming and game development
concepts.
The development of this project involves creating a digital
version of the game using programming techniques. It helps
in understanding important concepts such as decision-
making, loops, user input handling, and game logic. This
project serves as a foundation for developing more complex
games and improving logical and analytical skills.
3.1 EXISTING SYSTEM:
The existing system of Tic-Tac-Toe is a manual system,
7|Page
where two players play the game using paper and pen by
drawing a 3×3 grid.
Working of Existing System:
Two players participate in the game
Players choose symbols (‘X’ and ‘O’)
They take turns to mark the grid
The winner is decided manually by checking rows, columns, or
diagonals
Limitations of Existing System:
❌ Requires physical materials (paper, pen)
❌ No automatic validation of moves
❌ Manual checking of winner may lead to errors
❌ No record or history of games
❌ Not interactive or visually attractive
❌ Cannot play alone (no AI opponent)
3.2 PROPOSED SYSTEM:
The proposed system is a computer-based Tic-Tac-Toe game
developed using programming techniques. It aims to overcome the
drawbacks of the existing system by providing an automated and
interactive platform.
8|Page
Working of Proposed System:
The game is displayed on screen with a 3×3 grid
Players enter their moves through keyboard or mouse
The system automatically updates the board
It checks for winner or draw after each move
Displays result instantly
Features of Proposed System:
✔ Automated game logic and rule enforcement
✔ User-friendly interface
✔ Error-free result calculation
✔ Prevents invalid inputs
✔ Fast and efficient gameplay
✔ Option to extend with AI opponent
✔ Score tracking (future enhancement)
SYSTEM SPECIFICATION
1. Introduction
System specification defines the technical requirements needed to
develop and run the Tic -Tac -Toe game. It includes details about
Hardware , software , and other resources required for proper
9|Page
functioning of the system.
2. Hardware Requirements
The system does not require high-end hardware. Basic computer
specifications are sufficient:
Processor: Intel Core i3 or above
RAM: Minimum 2 GB (4 GB recommended)
Hard Disk: At least 100 MB free space
Input Devices: Keyboard / Mouse
Output Devices: Monitor
3. Software Requirements
The software requirements depend on the programming language used:
Operating System: Windows / Linux / macOS
Programming Language: Python / C++ / Java
IDE/Editor: VS Code / Turbo C++ / PyCharm / Notepad++
Compiler/Interpreter:
o Python Interpreter (for Python)
o GCC / Turbo C++ (for C++)
4. Functional Requirements
These define what the system should do:
The system should allow two players to play the game
The system should display a 3×3 grid
The system should accept user input for moves
The system should validate moves (no overwriting allowed)
The system should switch turns between players
The system should check for win or draw conditions
The system should display the result (Winner/Draw)
5. Non-Functional Requirements
10 | P a g e
These define how the system performs:
Usability: Easy to understand and play
Performance: Fast response time
Reliability: Accurate game results
Security: Prevent invalid inputs
Maintainability: Easy to update and improve
6. System Constraints
Limited to a 3×3 grid
Only two players (in basic version)
Requires basic programming environment
4. SOFTWARE DESCRIPTION
1. Introduction
The Tic-Tac-Toe game is developed using simple and easy – to - use
11 | P a g e
software tools. The main aim of using these tools is to create a game
that is interactive, user-friendly, and easy to understand. The develop-
ment of this project is done using Python programming language along
with graphical interface technology (GUI). These technologies help in
making the game more attractive and efficient.
2. Programming Language: Python 3
Python 3 is a high – level programming language that is very popular
because of its simple syntax and easy readability. It is widely used by
beginners as well as professionals for developing different types of
applications.
In this project, Python 3 is used to build the complete logic of the Tic-
Tac-Toe game. It helps in controlling how the game works. Python is
responsible for taking input from players , switching turns between
Players , checking whether a player has won the game, and deciding
if the game ends in a draw.
Another important advantage of Python is that it requires less code
compared to other programming languages, which makes development
faster and easier. It also helps students understand programming
concepts in a simple way.
3. Python Version: Python 3.10.2 (IDLE)
The game is created using Python version 3.10.2 along with IDLE. IDLE
stands for Integrated Development and Learning Environment. It is a basic
software that comes with Python and is mainly used for writing and running
Python programs.
IDLE provides a simple interface where users can type their code, run it,
and see the output. It also helps in finding errors in the code, correcting
them easily. Because of its simple design, it is very useful for students
and beginners who are learning programming.
4. Development Tools and Technologies
12 | P a g e
a) Python 3
Python 3 is the main technology used in this project. It performs many
important tasks such as:
Managing the flow of the game
Taking input from users
Checking valid and invalid moves
Deciding the winner of the game
Displaying the final result
It plays a major role in making the game functional and accurate.
b) GUI (Graphical User Interface)
GUI stands for Graphical User Interface. It is used to make the game
look attractive and easy to use. Instead of using a simple text -based
game, GUI allows users to interact with buttons, boxes, and graphics.
In this project , GUI is used to create a 3×3 grid where players can
click on boxes to place their marks (X or O). It also shows the game
result in a clear and understandable way.
GUI makes the game more interesting and improves the overall user
experience. It also helps users who are not familiar with coding to
easily play the game.
PROJECT DESCRIPTION
Objectives:
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
13 | P a g e
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.
1. 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
Figure: 2.1
2.1 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.
2.2 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.
14 | P a g e
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.
1 2 3
4 5 6
7 8 9
Hence there are only three possible results – a player wins, his
opponent (human or computer) wins or it’s a tie.
15 | P a g e
If any player is able to draw three Xs or three Os in the following
combinations then that player wins. The combinations are:
a) 1, 2, 3 b) 4, 5, 6
c) 7, 8, 9 d) 1, 4, 7
e) 2, 5, 8 f) 3, 6, 9
h) 1, 5, 9 i) 3, 5, 7
16 | P a g e
2. Core Logic - AI:
There are two core logics in this game – when both players are
human, and when one is computer. Suppose the player use X and
the computer use O . The logic used for the AI is as follows:
3.1 First move:
a) If the center is free, get the center. (Figure: 3.1)
b) Otherwise, get any of the corners. (Figure: 3.2)
X
O O
X
O
O O
Figure: Figure: 3.2
3.1
3.2 Second move:
a) Block user from winning. (Figure: 3.3)
b) Option for winning by applying the following logic:
If the center is occupied by user, get any of the
(Figure: 3.4)
17 | P a g e
X X O O
O O
O X
X
O
Figure: 3.3 Figure: 3.4
Otherwise, the following cases happen:
Case 1:
X
O
O
O O
X
O
Figure: 3.5
If any situation arises like the figure 3.5 then the computer sets its
symbol any one of the position among 2, 4, 6 and 8.
18 | P a g e
Case 2:
X X X
4 O 6 4 O 6 4 O 6
X X X
Figure: 3.6 Figure: 3.7 Figure: 3.8
If any situation arises like the figure 3.6 or figure 3.7 or figure 3.8
then the computer sets its symbol at any position among 4 and 6.
Case 3:
2 2 2
O X X O X X O
X 8 8 8 X
Figure: 3.9 Figure: 3.10 Figure: 3.11
If any situation arises like the figure 3.9 or figure 3.10 or figure 3.11 then
the computer sets its symbol at any position among 2 and 8.
Case 4:
1 X 3 1 X 3
O X X O
7 9 7 9
Figure: 3.12 Figure: 3.13
19 | P a g e
1 3 1 3
X O O X
7 X 9 7 X 9
Figure: 3.14 Figure: 3.15
If any situation arises like the figure 3.12 or figure 3.13 or figure 3.14 or
3.15 then the computer sets its symbol at any position among 1, 3, 7 and 9.
3.3 Third and fourth move:
a) Option for winning. (Figure: 3.16)
b) Block user from winning. (Figure: 3.17)
c) Randomly play a move. (Figure: 3.18)
O X O
X O X O
X X X
O
Figure: 3.16 Figure: 3.17
X X O O
O O X
X
O
Figure: 3.18
20 | P a g e
3. Core Logic - Humans:
For each move, check whether any 3 combination is occupied by any
player and display the winner accordingly.
21 | P a g e
4. CODE EXECUTION
22 | P a g e
23 | P a g e
24 | P a g e
5. USE CASE DIAGRAM
Start Game
Player 1
moves
Player 2
moves
Check the
result
Player 1 Player 2
Play again
25 | P a g e
6. Methods
The methods we used in our program are as follows:
1. def checker(buttons)
2. def scorekeeper()
3. def reset():
4. def NewGame()
26 | P a g e
7. Coding
import [Link]
from tkinter import *
root = Tk()
[Link]("1350x750+0+0")
[Link]("Tic-Tac-Toe Game")
[Link](background='sky blue')
Tops = Frame(root, bg='sky blue', pady=2, width=1350, height=100,
relief=RIDGE)
[Link](row=0, column=0)
lblTitle = Label(Tops, font=('arial', 50, 'bold'), text="Tic-Tac-Toe Game",
bd=21, bg='sky blue', fg='Cornsilk', justify=CENTER)
[Link](row=1, column=0)
MainFrame = Frame(root, bg='sky blue', bd=10, width=1350,
height=600, relief=RIDGE)
[Link](row=1, column=0)
LeftFrame = Frame(MainFrame, bd=10, width=750, height=500, pady=2,
padx=10, bg="sky blue", relief=RIDGE)
[Link](side=LEFT)
RightFrame = Frame(MainFrame, bd=10, width=560, height=500,
padx=10, pady=2, bg="sky blue", relief=RIDGE)
[Link](side=RIGHT)
RightFrame1 = Frame(RightFrame, bd=10, width=560, height=200,
padx=10, pady=2, bg="sky blue", relief=RIDGE)
[Link](row=0, column=0)
RightFrame2 = Frame(RightFrame, bd=10, width=560, height=200,
padx=10, pady=2, bg="sky blue", relief=RIDGE)
[Link](row=1, column=0)
PlayerX = IntVar()
PlayerO = IntVar()
27 | P a g e
[Link](0)
[Link](0)
button = StringVar()
click = True
def checker(buttons):
global click
if buttons["text"] == " " and click == True:
buttons["text"] = "X"
click = False
scorekeeper()
elif buttons["text"] == " " and click == False:
buttons["text"] = "O"
click = True
scorekeeper()
def scorekeeper():
if(button1["text"] == "X" and button2["text"] == "X" and
button3["text"] == "X"):
[Link](background="powder blue")
[Link](background="powder blue")
[Link](background="powder blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just won a
game")
if(button4["text"]=="X" and button5["text"]=="X" and
button6["text"]=="X"):
[Link](background="Red")
[Link](background="Red")
[Link](background="Red")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just won a
game")
28 | P a g e
if(button7["text"]=="X" and button8["text"]=="X" and
button9["text"]=="X"):
[Link](background="Cadet blue")
[Link](background="Cadet blue")
[Link](background="Cadet blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just won a
game")
if(button3["text"]== "X" and button5["text"]== "X" and
button7["text"]== "X"):
[Link](background="Cadet Blue")
[Link](background="Cadet Blue")
[Link](background="Cadet Blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just won a
game")
if(button1["text"]== "X" and button5["text"]== "X" and
button9["text"]== "X"):
[Link](background="Purple")
[Link](background="Purple")
[Link](background="Purple")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just
won a game")
if(button1["text"]== "X" and button4["text"]== "X" and
button7["text"]== "X"):
[Link](background="Yellow")
[Link](background="Yellow")
[Link](background="Yellow")
n = float([Link]())
score = (n + 1)
[Link](score)
29 | P a g e
[Link]("Winner X", "You have just won a
game")
if(button2["text"]== "X" and button5["text"]== "X" and
button8["text"]== "X"):
[Link](background="Pink")
[Link](background="Pink")
[Link](background="Pink")
n = float([Link]())
score = (n + 1 )
[Link](score)
[Link]("Winner X", "You have just won a
game")
if(button3["text"]== "X" and button6["text"]== "X" and
button9["text"]== "X"):
[Link](background="powder blue")
[Link](background="powder blue")
[Link](background="powder blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner X", "You have just won a
game")
if(button1["text"]== "O" and button2["text"]== "O" and
button3["text"]== "O"):
[Link](background="Orange")
[Link](background="Orange")
[Link](background="Orange")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button4["text"]== "O" and button5["text"]== "O" and
button6["text"]== "O"):
[Link](background="Blue")
[Link](background="Blue")
[Link](background="Blue")
n = float([Link]())
30 | P a g e
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button7["text"]== "O" and button8["text"]== "O" and
button9["text"]== "O"):
[Link](background="Green")
[Link](background="Green")
[Link](background="Green")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button3["text"]== "O" and button5["text"]== "O" and
button7["text"]== "O"):
[Link](background="Cadet blue")
[Link](background="Cadet blue")
[Link](background="Cadet blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button1["text"]== "O" and button5["text"]== "O" and
button9["text"]== "O"):
[Link](background="Orange")
[Link](background="Orange")
[Link](background="Orange")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button1["text"]== "O" and button2["text"]== "O" and
button3["text"]== "O"):
[Link](background="Powder blue")
[Link](background="Powder blue")
31 | P a g e
[Link](background="Powder blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button2["text"] == "O" and button5["text"]== "O" and
button8["text"]== "O"):
[Link](background="Cadet blue")
[Link](background="Cadet blue")
[Link](background="Cadet blue")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
if(button3["text"]== "O" and button6["text"]== "O" and
button9["text"]== "O"):
[Link](background="Red")
[Link](background="Red")
[Link](background="Red")
n = float([Link]())
score = (n + 1)
[Link](score)
[Link]("Winner O", "You have just won a
game")
def reset():
button1['text']=" "
button2['text']= " "
button3['text']= " "
button4['text']= " "
button5['text']= " "
button6['text']= " "
button7['text']= " "
button8['text']= " "
button9['text']= " "
32 | P a g e
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
[Link](background ="gainsboro")
def NewGame():
reset()
[Link](0)
[Link](0)
lblPlayerX=Label(RightFrame1, font=('arial',40,'bold'),text="Player X :",
padx=2, pady=2, bg="sky blue")
[Link](row=0, column=0, sticky=W)
txtPlayerX=Entry(RightFrame1, font=('arial',40,'bold'),bd=2, fg = 'black',
textvariable= PlayerX, width=14,
justify=LEFT).grid(row=0,column=1)
lblPlayerO=Label(RightFrame1, font=('arial',40,'bold'),text="Player O :",
padx=2, pady=2, bg="sky blue")
[Link](row=1, column=0, sticky=W)
txtPlayerO=Entry(RightFrame1, font=('arial',40,'bold'),bd=2, fg = 'black',
textvariable= PlayerO, width=14,
justify=LEFT).grid(row=1,column=1)
btnReset=Button(RightFrame2, text="Reset" , font=('arial',40,'bold'),
height = 1, width = 20, command=reset)
[Link](row=2, column=0, padx=6, pady=11)
btnNewGame=Button(RightFrame2, text="NewGame" ,
font=('arial',40,'bold'), height = 1, width = 20, command=NewGame)
[Link](row=3, column=0, padx=6, pady=10)
button1 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button1))
[Link](row=1, column=0, sticky = S+N+E+W)
33 | P a g e
button2 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button2))
[Link](row=1, column=1, sticky = S+N+E+W)
button3 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button3))
[Link](row=1, column=2, sticky = S+N+E+W)
button4 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button4))
[Link](row=2, column=0, sticky = S+N+E+W)
button5 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button5))
[Link](row=2, column=1, sticky = S+N+E+W)
button6 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button6))
[Link](row=2, column=2, sticky = S+N+E+W)
button7 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button7))
[Link](row=3, column=0, sticky = S+N+E+W)
button8 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button8))
[Link](row=3, column=1, sticky = S+N+E+W)
button9 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,
width=8, bg='gainsboro', command=lambda:checker(button9))
[Link](row=3, column=2, sticky = S+N+E+W)
[Link]()
34 | P a g e
8. Limitations
1. GUI is not so attractive.
2. Only mouse interface is implemented, keyboard is not
activated in the game.
9. Future plan
1. Keyboard functions will be added.
2. We want to design more complex boards for the game in future.
13. Reference
Books
: 1. Charanjeet Singh and Raman Kumar , Edition Fifth
2. Youtube
3. Google Chrome