You are on page 1of 13

A

PROJECT REPORT

ON

“Tic Tac Toe Game”


“Subject – Programming with Python [22616]

Submitted by

Amruta Ajay Avhale (2100340145)

Under the Guidance of

Prof. M.V.Khasne

DEPARTMENT OF COMPUTER TECHNOLOGY


SANJIVANI.K.B.P.POLYTECHNIC, KOPARGAON
SANJIVANI RURAL EDUCATION SOCIETY
DIST.AHMEDNAGAR-423603
(2022-23)

i |Page
SANJIVANI K.B.P.POLYTECHNIC, KOPARGAON

Department of Computer Technology

CERTIFICATE

This is certify that the project work entitled

“Tic Tac Toe Game”

Submitted by-

Amruta Ajay Avhale(2100340145)

Is a bonafide work carried out by above students under the supervision of Prof.
M.V.Khasne and it is submitted towards the partial fulfillment of the requirement of
MSBTE, Mumbai for the award of Diploma in Computer Technology

Prof. M.V.Khasne Prof.G. N. Jorvekar


(Project Guide) (HOD)

ii| Page
ACKNOWLEDGEMENT

First and the foremost We express our deep sense of gratitude, sincere thanks and deep
sense of appreciation to Project Guide Prof.M.V.Khasne, Department of Computer
Technology, Sanjivani K.B.P. Polytechnic, Kopargaon. Your availability at any time
throughout the year, valuable guidance, opinion, view, comments, critics, encouragement,
and support tremendously boosted this project work. Lots of thanks to Head of Computer
Technology Department, Prof.G.N.Jorvekar for providing us the best support we ever had.
We like to express our sincere gratitude to Prof.A.R.Mirikar, Principal, Sanjivani K. B. P.
Polytechnic, Kopargaon for providing a great platform to complete the project within the
scheduled time. We are also Thankful to all the faculty members, Computer Technology
Department, Sanjivani K. B. P. Polytechnic, Kopargaon for giving comments for
improvement of work, encouragement and help during completion of the Project.

Amruta Ajay Avhale(2100340145)

Department of Computer Technology

Sanjivani K.B.P. Polytechnic, Kopargaon

iii |Page
Table of Contents

1. Introduction .

2. Actual Resources Used .

3. Code .

4. Output.

5. Conclusion .

6. References .

iv |Page
INTRODUCTION

Tic tac toe Python, also known as Noughts and Crosses or Xs and Os, is a very
simple two-player game where both the player get to choose any of the
symbols between X and O. This game is played on a 3X3 grid board and one
by one each player gets a chance to mark its respective symbol on the empty
spaces of the grid. Once a player is successful in marking a strike of the same
symbol either in the horizontal, vertical or diagonal way as shown in the
picture below is created that player wins the game else the game goes on a
draw if all the spots are filled.

5|Page
ACTUAL RESOURCES USED

Sr.No Name of resources/material Specifications

1. Hardware-Computer system Computer(i3-i5 preferable)


RAM minimum 8GB and
onwards

2. Operating system Windows 10

3. Software Used IDLE (Python 3.12 64-bit)

6|Page
CODE:-

def sum(a, b, c):

return a + b + c

def printBoard(xState, zState):

zero = 'X' if xState[0] else ('O' if zState[0] else 0)

one = 'X' if xState[1] else ('O' if zState[1] else 1)

two = 'X' if xState[2] else ('O' if zState[2] else 2)

three = 'X' if xState[3] else ('O' if zState[3] else 3)

four = 'X' if xState[4] else ('O' if zState[4] else 4)

five = 'X' if xState[5] else ('O' if zState[5] else 5)

six = 'X' if xState[6] else ('O' if zState[6] else 6)

seven = 'X' if xState[7] else ('O' if zState[7] else 7)

eight = 'X' if xState[8] else ('O' if zState[8] else 8)

print(f"{zero} | {one} | {two} ")

print(f"--|---|---")

print(f"{three} | {four} | {five} ")

print(f"--|---|---")

print(f"{six} | {seven} | {eight} ")

def checkWin(xState, zState):

wins = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
7|Page
for win in wins:

if (sum(xState[win[0]], xState[win[1]], xState[win[2]]) == 3):

print("X Won the match")

return 1

if (sum(zState[win[0]], zState[win[1]], zState[win[2]]) == 3):

print("O Won the match")

return 0

return -1

if __name__ == "__main__":

xState = [0, 0, 0, 0, 0, 0, 0, 0, 0]

zState = [0, 0, 0, 0, 0, 0, 0, 0, 0]

turn = 1 # 1 for X and 0 for O

print("Welcome to Tic Tac Toe")

while (True):

printBoard(xState, zState)

if (turn == 1):

print("X's Chance")

value = int(input("Please enter a value: "))

xState[value] = 1

else:

print("O's Chance")

value = int(input("Please enter a value: "))

zState[value] = 1

cwin = checkWin(xState, zState)


8|Page
if (cwin != -1):

print("Match over")

break

turn = 1 - turn

9|Page
OUTPUT:

1. X Win The Game

10|Page
2. O Win the Game

11|Page
Conclusion

The course is designed to provide Basic knowledge of Python. Python programming is


intended for software engineers, system analysts, program managers and user support
personnel who wish to learn the Python programming language.

REFERENCE

 www.google.com

 www.chatgpt.com

 www.tutorialspoint.com

 www.wikipedia.com

12|Page
13|Page

You might also like