Python Microproject

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

GOVERNMENT POLYTECHNIC, HINGOLI

Sixth Semester (Year: 2022-23)

Subject

Programming with Python

Title of the Project

“Tic Tac Toe”

Branch: Computer Engineering (CO6I)

Members of the Group

Sr. Roll Enrollmen t Exam


Name of the Student
No. No. No. Seat No.

1 3144 2011630094 448329 Sakhare Munja Arjun

2 3115 2011630017 448292 Bade Keshav Santosh

3 3114 2011630016 448291 Swami Shivprasad Buddivant

Guided by
Prof. P.H.Gutte
This is to certify that this Micro-Project contains the bonafied work of
following students of Sixth Semester Diploma in Computer
Engineering, of Government Polytechnic, Hingoli for the session 2022-
23. They have completed their Capstone project Planning entitled
" Tic Tac Toe” under the guidance of Prof.P.H.Gutte. This Project
report is being submitted to MSBTE, Mumbai, in the partial fulfillment
for the Diploma in computer Engineering

Rol
Sr. Enrollmen Exam
l Name of the Student
No. t No. Seat No.
No.
1 3144 2011630094 448329 Sakhare Munja Arjun
2 3115 2011630017 448292 Bade Keshav Santosh
3 3114 2011630016 448291 Swami Shivprasad Buddivant

Prof. P.H.Gutte Prof. A.T. Adhave Dr. Ashok


Upadhyay

(Guider) (HOD) (Principal)


ACKNOWLEDGEMENT

The satisfaction that accompanies that the successful Completion of any

task would be incomplete without the Mention of people whose ceaseless

operation made it Possible, whose constant guidance and encouragement

crown All efforts with success. We are be grateful to our project guide

Prof. P.H. Gutte for the guidance, inspiration and Constructive suggestions

that helpful us in the preparation of This project. Our me to this project and

encouragement given to me. We own Deep sense of gratitude to Adhave sir

Head of Department Of Computer Engineering for appreciating us goal. We

express our sincere thanks to her for constant encouragement. express our

sincere thanks to microproject guide staff Members of Department of

Computer Engineering for their Encouragement and valuable guidance

throughout this project Last but not the least; we extend my sincere thanks

to Our family members and our friends for their constant support

throughout this project.


1.0 Rationale
The objective of this project is to develop the well-known board game Tic-Tac- Toe
for two players. Generally, this is a two-player strategy board game. The Tic-Tac-Toe
game is based on having a game board (2D array) of size 3 x 3. The players alternate
placing Xs and Os on the board until either one has placed three Xs or Os in a row
horizontally, vertically, or diagonally; or all nine board squares are filled. The player
wins if s/he draws three Xs or three Os in a row. Otherwise, the game is draw.
Initially the board grid squares are initialized to zeros. Xs and Os might be denoted
by numbers inside the board grid by ones and twos respectively. I.e. if player one
chooses X, the location of that choice is registered as 1 and when player two
chooses O the location of that choice in your array is registered as 2. At the end if a
row of 1s is registered then player one won the game. Or if a row of 2s is registered
thus player two won the game. If not, the game is draw. The game ends when there
is no more empty fields in the array (board) to fill or if one of the players wins the
game.

2.0 Aim of the project


1. To develop an interesting game for children to pass their free time.
2. To develop the well-known board game Tic-Tac-Toe for two players.
3. To be one of the players to get three same symbols in a row –
horizontally, vertically or diagonally on a 3 x 3 grid.

3.0 Course Outcomes Achieved


1. Display message on screen using Python script on IDE.
2. Develop python program to demonstrate use of Operators.
3. Perform operations on data structures in Python.
4. Develop functions for given problems.

4.0 Literature Review

Author Abstract Conclusion


(Publication)
Kalyani This paper describes the We used this paper to
Adawadkar main learn
(Sigma Institute features and applications of different features available
of in
Engineering) Python Programming Python and its applications.
David Beazley This book contains a We used this book to learn
complete the
(Sams learning of Python basic concepts of Python
Publishing) Programming Programming

Tom Gutschmidt This book covers game We used this book to learn
how to
(Premier Press) programming in three build efficient, flexible and
different well-
scripting languages i.e, integrated programs and
Python, Lua and Ruby systems
5.Program
def print_board(board):
"""
This function prints out the current state of the board.
"""
print(" | | ")
print(" "+board[0]+" | "+board[1]+" | "+board[2]+" ")
print("___|___|___")
print(" | | ")
print(" "+board[3]+" | "+board[4]+" | "+board[5]+" ")
print("___|___|___")
print(" | | ")
print(" "+board[6]+" | "+board[7]+" | "+board[8]+" ")
print(" | | ")

def check_win(board):
"""
This function checks if a player has won.
"""
win_combinations = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0,
4, 8), (2, 4, 6)]
for comb in win_combinations:
if board[comb[0]] == board[comb[1]] == board[comb[2]] != " ":
return board[comb[0]]
return False

def check_tie(board):
"""
This function checks if the game is a tie.
"""
for i in board:
if i == " ":
return False
return True

def get_move(player, board):


"""
This function gets the player's move.
"""
move = input(f"Player {player}, please choose a square (1-9): ")
while True:
if move.isnumeric():
move = int(move)
if move > 0 and move < 10 and board[move-1] == " ":
return move-1
move = input("Invalid move. Please choose a square (1-9): ")

def play_game():
"""
This function plays a game of Tic Tac Toe.
"""
print("Welcome to Tic Tac Toe!")
board = [" "]*9
players = ["X", "O"]
current_player = 0
while True:
print_board(board)
move = get_move(players[current_player], board)
board[move] = players[current_player]
winner = check_win(board)
if winner:
print_board(board)
print(f"Player {players.index(winner)+1} ({winner}) wins!")
break
elif check_tie(board):
print_board(board)
print("Tie game!")
break
current_player = (current_player+1)%2

play_game()

6.Output
1)
2)

3)

4)

5)
6)

7)

8)
8.0 Skill Developed/ learning out of this Micro-Project
We learnt,
1. To demonstrate the use of Operators.
2. To perform operations on data structures in Python.
3. To develop functions for given problems.
4. Efficient communication skills.
5. Working as a team member for developing c program.
6. Developing leadership qualities.

9.0 Applications of the Project


1. Thisproject can be used as an interesting game for
children to pass their free time.
2. The project can be also used to understand the. 3.
The project can be used in learning the

Subject Teacher

Prof.P.H.Gutte

You might also like