TicTacToe Class 11
TicTacToe Class 11
A Project Report
Submitted by
SHREYAS DAS
CBSE GRADE XI
IN
Computer Science
At
I am highly indebted to Mrs. Jean Mathew for the constant supervision, providing
necessary information and supporting in completing the project. I would like to
express my gratitude towards them for their kind co-operation and encouragement.
Finally I extend my gratefulness to one and all who are directly or indirectly involved
in the successful completion of this project work.
Signature of the
Candidate
TABLE OF CONTENTS
2. Synopsis 2
5. About Python 6
6. Flow chart 7
8. Output Screens 15
9. Future Enhancements 16
10. Bibliography 17
INTRODUCTION
Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper and
a pencil for two players, X and O, who take turn 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 wins the game.
In this project, we are using GUI (Graphical User Interface) to design this
project. We use Python programming language for coding. This is a
multiplayer game .
1
SYNOPSIS
In our program the moves taken by the human and the human are chosen
randomly.
If both the players play optimally then it is destined that you will never lose
(“although the match can still be drawn”). It doesn’t matter whether you play
first or second. In another ways – “Two expert players will always draw”.
PROCEDURE
• Importing the module – tkinter
• Create the main window (container)
• Add any number of widgets to the main window
• Apply the event Trigger on the widgets.
• Importing tkinter is same as importing any other module in Python.
2
REQUIREMENT ANALYSIS AND DESIGN
HARDWARE REQUIREMENTS:
SOFTWARE REQUIREMENTS:
3
MODULES AND FUNCTIONS
5
ABOUT PYTHON
Introduction
Advantages
Applications
def c_disable():
b1.config(state=DISABLED)
b2.config(state=DISABLED)
b3.config(state=DISABLED)
b4.config(state=DISABLED)
b5.config(state=DISABLED)
b6.config(state=DISABLED)
b7.config(state=DISABLED)
b8.config(state=DISABLED)
b9.config(state=DISABLED)
8
def c_enable():
b1.config(state=NORMAL)
b2.config(state=NORMAL)
b3.config(state=NORMAL)
b4.config(state=NORMAL)
b5.config(state=NORMAL)
b6.config(state=NORMAL)
b7.config(state=NORMAL)
b8.config(state=NORMAL)
b9.config(state=NORMAL)
def check_win():
global Score1
global Score2
global swapper
global player1_name
global player2_name
global quote
global quote_res
global win
if board[0] == board[1] == board[2]:
win = 1
elifboard[3] == board[4] == board[5]:
win = 2
elifboard[6] == board[7] == board[8]:
win = 3
if win in range(1,9):
c_disable()
if swapper == 0 and win in range(1, 9):
quote = quote_res
Score1 += 1
b10['text'] = str(player1_name) + quote + 'Retry'
elif swapper == 1 and win in range(1, 9):
quote = quote_res
Score2 += 1
b10['text'] = str(player2_name) + quote + 'Retry'
b4['text'] = board[3]
b5['text'] = board[4]
b6['text'] = board[5]
b7['text'] = board[6]
b8['text'] = board[7]
b9['text'] = board[8]
10
disable(number)
check_draw += 1
check_win()
if check_draw == 9:
b10['text'] = "It's a draw, Retry?"
def player_chooser():
global swapper
global player1_symbol
global player2_symbol
if swapper == 0:
swapper = 1
return player1_symbol
else:
swapper = 0
return player2_symbol
def disable(number):
if number == 0:
b1.config(state=DISABLED)
if number == 1:
b2.config(state=DISABLED)
if number == 2:
b3.config(state=DISABLED)
if number == 3:
b4.config(state=DISABLED)
if number == 4:
b5.config(state=DISABLED)
if number == 5:
b6.config(state=DISABLED)
if number == 6:
b7.config(state=DISABLED)
11
if number == 7:
b8.config(state=DISABLED)
if number == 8:
b9.config(state=DISABLED)
def score_board():
global swapper
if swapper == 0:
l1['text'] += 1
elif swapper == 1:
l2['text'] += 1
def clear():
global Score1
global Score2
global board
global check_draw
global winner
global quote_res
global quote
global win
win = 0
check_draw = 0
winner = '...'
quote_res = ' has won the game, '
quote = ' '
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '']
b1['text'] = board[0]
b2['text'] = board[1]
b3['text'] = board[2]
b4['text'] = board[3]
b5['text'] = board[4] 12
b6['text'] = board[5]
b7['text'] = board[6]
b8['text'] = board[7]
b9['text'] = board[8]
b10['text'] = 'Reset'
l1['text'] = str(Score1)
l2['text'] = str(Score2)
c_enable()
b1.grid(column=1, row=1)
b2.grid(column=1, row=2)
b3.grid(column=1, row=3)
b4.grid(column=2, row=1)
b5.grid(column=2, row=2)
b6.grid(column=2, row=3)
b7.grid(column=3, row=1)
b8.grid(column=3, row=2)
b9.grid(column=3, row=3)
b10.grid(column=1, row=4, columnspan=5)
l1.grid(column=5, row=2, rowspan=1)
l2.grid(column=5, row=3, rowspan=1)
l3.grid(column=4, row=2, rowspan=1)
l4.grid(column=4, row=3, rowspan=1)
l5.grid(column=4, row=1, columnspan=2)
mainloop()
OUTPUT SCREEN
FUTURE ENHANCEMENTS
• The program can be easily modified so that both players play optimally
(which will fall under the category of Artificial Intelligence).
• Also, the program can be modified such that the user himself gives
the input (using scanf() or cin).
BIBLIOGRAPHY
https://www.youtube.com
https://google.com
https://www.geeksforgeeks.org
https://www.xda-developers.com