Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

A MICRO PROJECT REPORT

ON

“Tic Tac Toe Game”

SUBMITTED BY

Rutuja Jalindar kane

UNDER THE GUIDANCE OF

PROF. Salunke.N.S

In partial fulfillment for the award


Of

DIPLOMA IN COMPUTER ENGINEERING

Sanjivani Pratisthan’s

S. P. I. T. POLYTECHNIC, KURUND

2023 – 2024
Sanjivani Pratisthan’s

S. P. I. T. POLYTECHNIC, KURUND

CERTIFICATE
This is to certify that a micro project work entitled

“Tic Tac Toe Game”


is bonafide work carried out by following students

Name of Student Enrollment Number

Rutuja Jalindar Kane 2111720057

in partial fulfillment for the award of “Diploma in Computer Engineering” during the year
2023-24 as required by the Maharashtra State Board of Technical Education, Mumbai. The micro
project report has been approved as it satisfies the academic requirements in respect of micro
project work prescribed by MSBTE, Mumbai.

Place: Kurund, Ahmednagar.


Date: / / 2024

Project Guide Head of Department Principal


(Prof.Salunke.N.S.) (Prof. Pawar.T.S.) (Prof. Kapse S. D.)
Acknowledgement

I would like to express my sincere thanks to Prof.Salunke.N.S. for his valuable guidance and
support in completing my project.

I would also like to express my gratitude towards our principal Prof. Kapse S. D. for giving me
this great opportunity to do a project on Tic Tac Toe Game Without their support and
suggestions, this project would not have been completed.

Micro Project
ON
"Tic tac toe game "

❖ Rationale

Both the player plays one by one simultaneously. In one move, players need to select
one position in the 3×3 grid and put their mark at that place. The game runs continuously
until one may wins. In the previous article, we have built a simple Tic Tac Toe Game in
Android but in this article, we have the following additional features inside the app .

❖ Aims/Benefits of the micro project.

• Create Tic Tac Toe Game using andriod.

• Understand different android concept.

❖ Course outcome addressed.

 Perform operations on data structures in Python


 Develop functions for a given problem.
 Design classes for a given problem.
 Handle exceptions.

❖ Proposed methodology

In this project, we create a tic tac toe game using python programming.

❖ Brief Description:-

A two- board player tic-tac-toe game, which we can play on the command line.
Initially, we’ll make a blank game and then we’ll take inputs from the players and
we’ll check for the winning situation if the entire board gets loaded and no one
wins, we’ll declare the result as “Tie” and ask users if they want to restart the
game.

❖ Used software /IDE


We will create this game using Python 3, so make sure you have it installed on
your laptop/computer and we are good to go.

❖ How does the game work?


The board is numbered like the keyboard’s number pad. And thus, a player can
make their action on the game board by entering the number from the keyboard
number pad.

❖ Coding
Utilize the dictionary to make our game board. A dictionary is a primitive data
type in python that kept data in “key: value” format. and thus, we’ll make a
dictionary of length 9 and each key will illustrate a block on the board and its
related value will illustrate the move made by a player. and we’ll make a function
printBoard() that we can utilize every time we want to print the updated board
in the game.

theBoard = {'7': ' ' , '8': ' ' , '9': ' ' ,
'4': ' ' , '5': ' ' , '6': ' ' ,
'1': ' ' , '2': ' ' , '3': ' ' }

def printBoard(board):
print(board['7'] + '|' + board['8'] + '|' + board['9'])
print('-+-+-')
print(board['4'] + '|' + board['5'] + '|' + board['6'])
print('-+-+-')
print(board['1'] + '|' + board['2'] + '|' + board['3'])

Originally, our game board will look like this:


||
-+-+-
||
-+-+-
||

Now, in the main function, we’ll first take the input from the player and review if the input
is a valid move or not. If the block that the player requests to move to is valid, we’ll fill
that block else we’ll ask the user to pick another block.
def game():
turn = 'X'
count = 0

for i in range(10):
printBoard(theBoard)
print("It's your turn," + turn + ".Move to which place?")
move = input()
if theBoard[move] == ' ':
theBoard[move] = turn
count += 1
else:
print("That place is already filled.\nMove to which place?")
continue
continue

Now, to inspect the winning condition, we’ll review a total of 8 conditions and whichever
player has made the last move, we’ll declare that player a winner. And if no one wins,
we’ll declare ‘tie’.

# Now we will check if player X or O has won,for every move after 5 moves.
if count >= 5:
if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': # across the
top
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': # across the
middle
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': # across the
bottom
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': # down the
left side
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': # down the
middle
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': # down the
right side
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': # diagonal
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': # diagonal
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
# If neither X nor O wins and the board is full, we'll declare the result as
'tie'.
if count == 9:
print("\nGame Over.\n")
print("It's a Tie!!")
# we have to change the player after every move.
if turn =='X':
turn = 'O'
else:
turn = 'X'

The tic-tac-toe game is ready to play full python code is given below.

#Implementation of Two Player Tic-Tac-Toe game in Python.


''' We will make the board using dictionary
in which keys will be the location(i.e : top-left,mid-right,etc.)
and initialliy it's values will be empty space and then after every move
we will change the value according to player's choice of move. '''
theBoard = {'7': ' ' , '8': ' ' , '9': ' ' ,
'4': ' ' , '5': ' ' , '6': ' ' ,
'1': ' ' , '2': ' ' , '3': ' ' }
board_keys = []
for key in theBoard:
board_keys.append(key)
''' We will have to print the updated board after every move in the game and
thus we will make a function in which we'll define the printBoard function
so that we can easily print the board everytime by calling this function. '''
def printBoard(board):
print(board['7'] + '|' + board['8'] + '|' + board['9'])
print('-+-+-')
print(board['4'] + '|' + board['5'] + '|' + board['6'])
print('-+-+-')
print(board['1'] + '|' + board['2'] + '|' + board['3'])
# Now we'll write the main function which has all the gameplay functionality.
def game():
turn = 'X'
count = 0
for i in range(10):
printBoard(theBoard)
print("It's your turn," + turn + ".Move to which place?")
move = input()
if theBoard[move] == ' ':
theBoard[move] = turn
count += 1
else:
print("That place is already filled.\nMove to which place?")
continue
# Now we will check if player X or O has won,for every move after 5 moves.
if count >= 5:
if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': # across the top
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': # across the middle
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': # across the bottom
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': # down the left side
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': # down the middle
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': # down the right side
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': # diagonal
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': # diagonal
printBoard(theBoard)
print("\nGame Over.\n")
print(" **** " +turn + " won. ****")
break
# If neither X nor O wins and the board is full, we'll declare the result as 'tie'.
if count == 9:
print("\nGame Over.\n")
print("It's a Tie!!")
# Now we have to change the player after every move.
if turn =='X':
turn = 'O'
else:
turn = 'X'
# Now we will ask if player wants to restart the game or not.
restart = input("Do want to play Again?(y/n)")
if restart == "y" or restart == "Y":
for key in board_keys:
theBoard[key] = " "
game()
if __name__ == "__main__":
game()

the output of the above python program the game is working and a working screenshot
of this game is given below.

❖ Actual Report:

Introduction:

In this article, we are going to make a tic-tac-toe game that has both online and offline
modes. So for this project, we are going to use Kotlin and XML. Tic-Tac-Toe is a two-
player game. Each player has X or O. Both the player plays one by one simultaneously. In
one move, players need to select one position in the 3×3 grid and put their mark at that
place. The game runs continuously until one may wins. In the previous article, we have
built a simple Tic Tac Toe Game in Android but in this article, we have the following
additional features inside the app:

Step by Step Implementation

Step 1: Create a New Project

Step 2: Before going to the coding section first you have to do some pre-task

Step 3: Working with the activity_main.xml file

Step 4: Working with the MainActivity.java file


❖ Outputs of the Micro-Project
After creating this game, we can get a pretty exact idea about dictionaries in
python, how to access dictionaries, how to iterate over dictionaries, for loop, if-else
conditions, and functions in python.

❖ Skill Developed / Learning outcomes of this Micro-Project


 Develop group discussion skills.
 Communication skills improved.
 MS WORD skills developed.
 Data collection skills
 python 3 programming skills.

❖ Conclusion
A two-player tic-tac-toe game, which we can play on the command line.
Python is generally utilized for creating websites and software, task
automation, data analysis, and data visualization.

❖ Actual Methodology Followed:


• The topic of micro-project on “tic tac toe Game” was decided under the guidance of
• The research on needs of information related to the microproject was done by using
internet and books.
• The reference from other professional software’s used in different programming which
are available on internet are also used.
• After the research of one week. The implementation of the collected information in
program will be implanted.
❖ Reference:
1. 22616– programming with python (Curriculum)
2. Laboratory manual (22616)
3. https://www.geeksforgeeks.org/tic-tac-toe-game-using-androidstudio /
4. android tic tac toe game - Create tic tac toe game andriod - Project Gurukul

❖ Applications of this Micro-Project:

The game is as easy to code as to play and in this article, since a long time when we used
to have keypad phones

You might also like