Tik Tac Toe game (2)
Tik Tac Toe game (2)
PROJECT REPORT ON
“Tik Tac Toe”
FOR THE DIPLOMA IN ARTIFICIAL INTELLIGENCE AND
MACHINE LEARNING
DATA STRUCTURE USING PYTHON
SUBMITTED BY
1. Baravkar Gauri Santaram
2. Bawaskar Ajinkya Pramod
3. Bhandarge Krushna Sudam
4. Bhujade Priti Navanath
5. Fraser K Boban
6. Chaudhari Akankshaa Jitendra
UNDER THE GUIDANCE OF
Mrs.S.S.Surwade
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE
LEARNING
CSMSS COLLEGE OF POLYTECHNIC, CHHATRAPATI SAMBHAJI
NAGAR MAHARASHTRA, INDIA
2
ACKNOWLEDGEMENT
We would like to express our thanks to the people who have helped us most
throughout our project We would like to express our sincere thanks to the principal of
CSMSS College of Polytechnic Dr. G B Dongre sir for being always with us as a
motivator. We are thankful to the H.O.D. Mrs. S. R. Borakhade Madam of
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING Department for her
kind support. We are grateful to our Project Guide Mrs. S.S.Surwade Madam for
nonstop support and continuous motivation for the project. Her help made us possible
to complete our project with all accurate information. Special thanks go to our friends
who helped us in completing the project, where they all exchanged their own
interesting ideas. We wish to thanks our parents for their personal support or attention
who inspired us to go our own way. Finally, we would like to thank God who made all
things possible for us till the end.
5 Fraser K Boban
3
INDEX
1 RATIONALE 5
2 COMPETENCY 5
3 COURSE OUTCOME 5
5 ACTION PLAN 6
6 INTRODUCTION 8
7 PROGRAM 10
8 OUTPUT 13
9 CONCLUSION 15
10 REFERENCE/BOOKS 16
4
RATIONALE:
Data structures are mathematical and logical model of storing and organizing
data in a particular way in computer. Python is powerful programming language,
it is effective for introducing computing and problem solving to beginners.
Python has efficient high-level data structures and a simple but effective
approach to object-oriented programming. After completing this course, student
will be able to implement different types of data structures to solve real life
problems.
COMPETENCY:
Competency is the ability to perform tasks effectively, combining knowledge,
skills, and behaviors. It includes understanding relevant concepts, practical
abilities (both technical and soft skills), and the attitudes that influence
performance. Experience enhances competency through real-world application,
while continuous learning is essential for adapting to changes in technology and
industry. Ultimately, competency is vital for personal growth, career
advancement, and organizational success.
COURSEOUTCOMES (COs):
Students will be able to achieve & demonstrate the following COs on completion
of course based learning
CO1 - Develop Python program using basic syntactical constructs.
CO2 - Perform operations on sequence structures in Python.
CO3 - Implement Modules, Packages in Python for given problem.
CO4 - Design classes for given problem.
CO5 - Implement Linear Data Structure in Python.
CO6 - Develop Python program to implement tree data structure.
5
“Tik Tac Toe game”
Aims/Benefits of the Micro-Project :-
7
INTRODUCTION OF TIK TAC TOE GAME:-
Tic-Tac-Toe is a simple yet classic two-player game that is easy to learn and
widely popular. Played on a 3x3 grid, the objective is for players to take turns
marking empty spaces with their respective symbols—traditionally, "X" for one
player and "O" for the other. The goal is to be the first to form a continuous line
of three of their symbols, which can be horizontal, vertical, or diagonal. If all
nine squares are filled without a winning line, the game ends in a draw.
2.Popular Learning Tool: In modern times, it has become a go-to project for
beginners in programming, offering an easy-to-understand framework for
learning basic coding principles.
8
4. Control Flow Introduction: The project helps students grasp the basics of
control flow, including turn-taking, checking for win conditions, and determining
when a game ends in a draw.
10. Foundation for Advanced Learning: Beyond just a fun project, Tic-Tac-
Toe serves as a foundation for further studies in game development, artificial
intelligence, and competitive programming.
9
PROGRAM
print()
print(row1)
print(row2)
print(row3)
print()
def player_move(icon):
if icon == "X":
number = 1
elif icon == "O":
number = 2
print("Your turn player {}".format(number))
choice = int(input("Enter your move (1-9): ").strip())
if board[choice - 1] == " ":
board[choice - 1] = icon
else:
print()
print("That space is already taken!")
10
def is_victory(icon):
if (board[0] == icon and board[1] == icon and board[2] == icon) or \
(board[3] == icon and board[4] == icon and board[5] == icon) or \
(board[6] == icon and board[7] == icon and board[8] == icon) or \
(board[0] == icon and board[3] == icon and board[6] == icon) or \
(board[1] == icon and board[4] == icon and board[7] == icon) or \
(board[2] == icon and board[5] == icon and board[8] == icon) or \
(board[0] == icon and board[4] == icon and board[8] == icon) or \
(board[2] == icon and board[4] == icon and board[6] == icon):
return True
else:
return False
def is_draw():
if " " not in board:
return True
else:
return False
while True:
print_board()
player_move("X")
print_board()
if is_victory("X"):
print("X wins! Congratulations!")
break
elif is_draw():
print("It's a draw!")
break
11
player_move("O")
if is_victory("O"):
print_board()
print("O wins! Congratulations!")
break
elif is_draw():
print("It's a draw!")
break
12
OUTPUT
13
EXPLANATION :-
Overview of the Game Structure
1. Game Board:-
The game board is represented as a list with nine empty spaces. Each space
corresponds to a cell in a 3x3 grid.
2. Display Function:-
There’s a function dedicated to displaying the current state of the board. It
formats the board into rows and prints it in a visually appealing way, showing
which cells are occupied and which are still available.
3. Player Turns:-
The game allows two players (X and O) to take turns. A function handles player
input, prompting them to choose a cell (from 1 to 9) to place their symbol. It
checks if the chosen cell is available before making a move.
4. Victory Check:-
After each move, the game checks if the current player has won. This is done by
evaluating possible winning combinations (like three in a row horizontally,
vertically, or diagonally).
5. Draw Condition:-
The game also checks if the board is full without any winner, which results in a
draw.
6. Game Loop:-
The game runs in a loop, alternating between players until one wins or the game
ends in a draw. Each iteration displays the updated board and processes the
current player’s move.
14
Improvements to Consider
- Input Validation: Ensure players only input valid numbers (1-9) and handle any
errors gracefully.
- User Experience: You could enhance the experience by clearing the console
after each turn, though this depends on the environment you’re using.
- Restart Option: After a game ends, you could prompt players to start a new
game.
CONCLUSION:-
In conclusion, This Tic-Tac-Toe game is a straight forward yet effective
implementation of the classic game. It allows two players to take turns, checks
for victories and draws, and prints the game board after each move.
Enhancements like input validation and reducing code duplication could improve
user experience and maintainability. the Tic Tac Toe project serves as an
effective and engaging introduction to programming concepts for beginners.
Through its implementation, learners not only grasp fundamental skills such as
working with variables, control structures, and data handling but also enhance
their logical thinking and problem-solving abilities. simplicity of the game allows
for easy modifications and expansions, encouraging creativity and further
exploration in coding. Overall, this project it serves as a great foundation for
further development or learning about game logic in programming.
15
REFERENCE:
https://chat.openai.com/c/b88f38ff-379d-4d4e-9e71-ac9c8df119eb
https://www.w3schools.com/c/c_intro.php
https://www.geeksforgeeks.org/e-library-management-system/
https://www.youtube.com/
BOOKS:
16