CENTRAL BOARD OF SECONDARY EDUCATION
“ TIC TAC TOE ”
SUBJECT REPORT SUBMITTED IN PARTIAL
FULFILLMENT OF THE
REQUIREMENTS OF CLASS 12TH INFORMATICS PRACTICES 2021-2022 OF CBSE
BY
“ ANUBHAV SHRIVASTAVA ”
ENROLLMENTNO: - “… ..................... ”
ROLL NO: -“… .............................................. ”
UNDER THE GUIDANCE OF
“Er. SHISHIR KUMAR MISHRA”
DEPARTMENT OF INFORMATICS PRACTICES
ST. MARY’S SCHOOL,
ASHRAM ROAD,
MAINPURI
1
Page
CERTIFICATE
This is to certify that “ ANUBHAV SHRIVASTAVA ”
Bearing Roll No………………………. has successfully completed
the project under the guidance of “Er. SHISHIR KUMAR
MISHRA” As partial fulfilment of the requirement of class XII
section B in ST. MARY’S SCHOOL, MAINPURI, CBSE
New Delhi for
Academic years 2021-22
NAME & SIGN Signature NAME & SIGN
INTERNAL EXAMINER (Principal) EXTERNALEXAMINER
2
Page
ACKNOWLEDGEMENT
I would like to convey my heartfelt thanks to Er. SHISHIR
KUMAR MISHRA my teacher who guided me through
the project and also gives suggestion and guidance for
completion of the project. He helped me to understand
and remember input and details of the project that I
would have otherwise lost.
ANUBHAV SHRIVASTAV
ROLL NO…………………
CLASS: - 12TH C
3 Page
INDEX
Sr CONTENTS PAGE NO
no.
1. INTRODUCTION
1. ABOUT PYTHON 5–6
2. ABOUT MYSQL 7–8
3. ABOUT TIC – TAC – TOE 9
2. SOURCE CODE 11 – 22
3. OUTPUT 23 – 26
4. BIBLIOGRAPHY 27
4
Page
INTRODUCTION
Python is an interpreted, object-oriented, high-level
programming language with dynamic semantics. Its high-
level built in data structures, combined with dynamic typing
and dynamic binding, make it very attractive for Rapid
Application Development, as well as for use as a scripting
or glue language to connect existing components together.
Python's simple, easy to learn syntax emphasizes
readability and therefore reduces the cost of program
maintenance. Python supports modules and packages,
which encourages program modularity and code reuse. The
Python interpreter and the extensive standard library are
available in source or binary form without charge for all
major platforms, and can be freely distributed.
Often, programmers fall in love with Python because of the
increased productivity it provides.
Since there is no compilation step, the edit-test-debug
cycle is incredibly fast. Debugging Python programs is easy:
a bug or bad input will never cause a segmentation fault.
Instead, when the interpreter discovers an error, it raises
5
Page
an exception. When the program doesn't catch the
exception, the interpreter prints a stack trace.
Debugger allows inspection of local and global variables,
evaluation of arbitrary expressions, setting breakpoints,
stepping through the code a line at a time, and so on. The
debugger is written in Python itself, testifying to Python's
introspective power. On the other hand, often the quickest
way to debug a program is to add a few print statements to
the source: the fast edit-test-debug cycle makes this
simple approach very effective.
6
Page
ABOUT MYSQL:
Mysql is a fast, easy-to-use RDBMS being used for many small
and big businesses. Mysql is developed, marketed and supported
by mysql AB, which is a Swedish company. Mysql is becoming so
popular because of many good reasons −
Mysql is released under an open-source license. So you have
nothing to pay to use it.
Mysql is a very powerful program in its own right. It handles
a large subset of the functionality of the most expensive and
powerful database packages.
Mysql uses a standard form of the well-known SQL data
language.
Mysql works on many operating systems and with many
languages including PHP, PERL, C, C++, JAVA, etc.
Mysql works very quickly and works well even with large
data sets.
Mysql is very friendly to PHP, the most appreciated language
for web development.
7
Page
Mysql supports large databases, up to 50 million rows or
more in a table. The default file size limit for a table is 4GB,
But you can increase this (if your operating system can
handle it) to a theoretical limit of 8 million terabytes (TB).
Mysql is customizable. The open-source GPL license allows
programmers to modify the mysql software to fit their own
specific environments.
8
Page
ABOUT TIC TAC TOE
Tic-tac-toe (American English), noughts and crosses
(British English), or Xs and Os is a paper-and-pencil
game for two players, X and O, who take turns marking
the spaces in a 3×3 grid. The player who succeeds in
placing three of their marks in a horizontal, vertical, or
diagonal row is the winner.
tkinter Python library is used to create the GUI. Two
options are available to play the game, along with the
system or with another player.
A small winning strategy is used to play with the system.
The system will try to find the best place to put its naught
or cross by which the system will win or try to stop
players to win.
Approach:Create a landing page containing selection
buttons: Single-player or multiplayer.
Create a game-board containing nine tiles to play the
game along with other details (i.e. playing with a
system or another player, whose turn etc.).
Allow the player to press the tile and check the status
of the game (i.e. Tie game, anyone of the players won
the match or the game is still running).
9
Display the message, who won the match.
Page
SYSTEM REQUIREMENT
System requirement
Hardware:
CPU: Intel CORE i3
Hard Disk: 500GB
RAM: 8GB
VDU: Video Display Adaptar
Software:
Platform: Windows 10 and above
Programming Languages: Python,
Mysql
10
Page
SOURCE CODE
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> from tkinter
... import *
... import tkinter.messagebox as msg
...
... root = Tk()
... root.title('TIC-TAC-TOE---ANUBHAV SHRIVASTAV CLASS 12 TH C PROJECT ')#
labels
... Label(root, text = "player1 : X", font = "times 15").grid(row = 0, column = 1)
... Label(root, text = "player2 : O", font = "times 15").grid(row = 0, column = 2)
...
... digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
...
... #
... for player1 sign = X and
... for player2 sign = Y
... mark = ''
...
... #
... counting the no.of click
11
... count = 0
Page
...
...
... panels = ["panel"] * 10
...
...
... def win(panels, sign):
... return ((panels[1] == panels[2] == panels[3] == sign) or(panels[1] == panels[4]
== panels[7] == sign) or(panels[1] == panels[5] == panels[9] == sign) or(panels[2]
== panels[5] == panels[8] == sign) or(panels[3] == panels[6] == panels[9] == sign)
or(panels[3] == panels[5] == panels[7] == sign) or(panels[4] == panels[5] ==
panels[6] == sign) or(panels[7] == panels[8] == panels[9] == sign))
...
... def checker(digit):
... global count, mark, digits
...
... # Check which button clicked
...
... if digit == 1 and digit in digits:
digits.remove(digit)## player1 will play
if the value of count is even and
for odd player2 will play
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
12
elif count % 2 != 0:
Page
mark = 'O'
panels[digit] = mark
button1.config(text = mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 2 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
13
button2.config(text = mark)
Page
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 3 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button3.config(text = mark)
count = count + 1
14
sign = mark
Page
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 4 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button4.config(text = mark)
count = count + 1
sign = mark
15
Page
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 5 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button5.config(text = mark)
count = count + 1
sign = mark
16
if (win(panels, sign) and sign == 'X'):
Page
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 6 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button6.config(text = mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
17
root.destroy()
Page
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 7 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button7.config(text = mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
18
msg.showinfo("Result", "Player2 wins")
Page
root.destroy()
if digit == 8 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button8.config(text = mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
19
Page
if digit == 9 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button9.config(text = mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif(win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
20
###
Page
if count is greater then 8 then the match has been tied
if (count > 8 and win(panels, 'X') == False and win(panels, 'O') == False):
msg.showinfo("Result", "Match Tied")
root.destroy()
#### define buttons
button1 = Button(root, width = 15, font = ('Times 16 bold'), height = 7, command
= lambda: checker(1))
button1.grid(row = 1, column = 1)
button2 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(2))
button2.grid(row = 1, column = 2)
button3 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(3))
button3.grid(row = 1, column = 3)
button4 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(4))
button4.grid(row = 2, column = 1)
button5 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(5))
button5.grid(row = 2, column = 2)
button6 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(6))
button6.grid(row = 2, column = 3)
button7 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
21
= lambda: checker(7))
Page
button7.grid(row = 3, column = 1)
button8 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(8))
button8.grid(row = 3, column = 2)
button9 = Button(root, width = 15, height = 7, font = ('Times 16 bold'), command
= lambda: checker(9))
button9.grid(row = 3, column = 3)
root mainloop()
22
Page
OUTPUT
23
Page
Page
24
Page
25
Page
26
BIBLIOGRAPHY
http://www.google.com/
# http://en.wikipedia.org
#Informatics Practices by SUMITA
ARORA
#http://www.icbse.com
#www.codeproject.com
27
Page