Minor Project Report
Minor Project Report
Brain Game
In python 3
2|Page
PYTHON (MCAM2107L)
(Brain Game)
Programming Lab - VI
A report submitted to Punjabi University, PATIALA in
partial fulfilment of the requirement for the award of
degree course
In
MASTER OF COMPUTER APPLICATIONS (MCA)
(2022-2023)
3rd SEMESTER
(DEPARTMENT OF COMPUTER SCIENCE)
DECLARATION
We affirm that the minor project work titled “BRAIN GAME” being
Science is the original work carried out by us. It has not formed the part of
any other project work submitted for award of any degree or diploma,
CERTIFICATE
I here by certify that the work presented in this report entitled "BRAIN GAME"
submitted in the partial fulfilment of the requirement for the award of degree of
Project Guide
Dr. Jaswinder Singh
ACKNOWLEDGEMENT
I also express our sincere thanks to our other for giving us consistent
encouragement, support and valuable guidance throughout the course of
the project without their stable guidance this project would not have been
achieved.
Our due thanks to our HEAD OF DEPARTMENT MAM, Dr. Jaspreet Kaur, for
his support throughout the course.
Finally, we would like to thank all those friends who are involved directly
and indirectly in completion of our project.
6|Page
CONTENT
1. Abstract 6
2. Introduction 7
3. System Analysis 8 to 10
4. System Specification 11
5. Software Description 12 to 15
6. Project Description 16 to 22
7. Code Execution 23 to 27
9. Methods 29
10. Coding 30 to 37
11. Limitations 38
13. Reference 38
7|Page
1. ABSTRACT
The game TIC TAC TOE had an early variant which began in the first
century in the Roman Empire. During that time, it was called Terni Lapilli
where the players only had three pieces and had to move around the
empty spaces to play. The actual game of TIC TAC TOE could be
traced back to ancient Egypt. The game was also known during that time
as ʖ Three Men's Morrisʗ. The first reference to Noughts and crosses was
made in 1864 in a British novel called Can You Forgive Her. For many
years the game was referred to as noughts and crosses but was changed
in the 20th century by the United States to TIC TAC TOE.
`
8|Page
2. INTRODUCTION
2.1 OBJECTIVE:
If all nine squares are filled and none of the players have three in a
row, the game is a draw.
9|Page
3 SYSTEM ANALYSIS
INTRODUCTION:
4. SYSTEM SPECIFICATION
5. SOFTWARE DESCRIPTION
PYTHON 3.10.2 IDLE 2022
5.2.1 PYTHON 3:
Tkinter.mainloop()
6. 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
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:
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.
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:
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.
19 | P a g e
1 2 3
4 5 6
7 8 9
Figure: 2.2
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
20 | P a g e
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:
X
O O
X
O
X X O O
O O
O X
X
O
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.
22 | P a g e
Case 2:
X X X
4 O 6 4 O 6 4 O 6
X X X
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.
23 | P a g e
Case 3:
2 2 2
O X X O X X O
X 8 8 8 X
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
1 3 1 3
X O O X
7 X 9 7 X 9
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.
24 | P a g e
O X O
X O X O
X X X
O
Figure: 3.16 Figure: 3.17
X X O
O O X
X
O
Figure: 3.18
7. CODE EXECUTION
import tkinter.messagebox
from tkinter import*
root =Tk()
root.geometry("1350x750+0+0")
Start Game
Player 1
moves
Player 2
moves
Check the
result
Player 1 Player 2
Play again
30 | P a g e
9. Methods
1. def checker(buttons)
2. def scorekeeper()
3. def reset():
4. def NewGame()
31 | P a g e
10. Coding
import tkinter.messagebox
from tkinter import*
root =Tk()
root.geometry("1350x750+0+0")
root.title("Tic Tac Toe")
root.configure(background='Pink')
PlayerX=IntVar()
PlayerO=IntVar()
32 | P a g e
PlayerX.set(0)
PlayerO.set(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():
button7.configure(background ="Pink")
button8.configure(background ="Pink")
button9.configure(background ="Pink")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")
button8.configure(background ="Pink")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")
button8.configure(background ="Green")
button9.configure(background ="Green")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")
game")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")
def reset():
button1['text']=" "
button2['text']=" "
37 | P a g e
button3['text']=" "
button4['text']=" "
button5['text']=" "
button6['text']=" "
button7['text']=" "
button8['text']=" "
button9['text']=" "
button1.configure(background ="gainsboro")
button2.configure(background ="gainsboro")
button3.configure(background ="gainsboro")
button4.configure(background ="gainsboro")
button5.configure(background ="gainsboro")
button6.configure(background ="gainsboro")
button7.configure(background ="gainsboro")
button8.configure(background ="gainsboro")
button9.configure(background ="gainsboro")
def NewGame():
reset()
PlayerX.set(0)
PlayerO.set(0)
root.mainloop()
39 | P a g e
11. Limitations
1. GUI is not so attractive.
13. Reference
Books
: 1. H.M.Deitel and P.J.Deital, Java How to program: Sixth
Edition Herbert Schildt, The Complete Reference: Fifth
edition
2. Youtube
3. Google Chrome