SAMARITANS ENG. MED. HR. SEC.
SCHOOL, NARMADAPURAM (M.P.)
SESSION 2025 – 26
CLASS – XII
INVESTIGATORY PROJECT OF
COMPUTER SCIENCE
Project name: Tic Tac Toe
GUIDED BY: MADE BY…………
Miss Hema Nechlani ROLL NO……………...
Teacher’s Sign. Principal Sign.
External Sign.
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to my Computer
Science teacher, Hema Nechlani Ma'am, for his exceptional
guidance, support, and expertise throughout the completion of
my class 12 Computer Science project. His extensive
knowledge, insightful feedback, and constant encouragement
played a pivotal role in shaping the success of this project.
I am immensely thankful to my parents and family for their
unwavering support and belief in my abilities. Their continuous
encouragement and motivation provided me with the
determination to excel in this project and explore various
aspects of business studies.
I would also like to acknowledge the contributions of my
classmates who actively participated in group discussions,
shared their perspectives, and collaborated on different aspects
of the project. Their valuable insights and collaboration
significantly enriched the project and fostered a deeper
understanding of business concepts.
Furthermore, I extend my appreciation to the school
administration for providing access to relevant resources, such
as business textbooks, case studies, and online databases. Their
support and commitment to academic excellence have been
instrumental in the successful completion of this Computer
Science project.
CERTIFICATE
This is to certify that the contents of this project file
submitted by Karan Chawra of class XII for the subject of
Computer Science is his/her Bonafide work submitted to
Samaritans Eng. Med. School for partial fulfilment of the
requirements for CBSE examinations of class XII. The project
has been completed under my guidance and supervision Karan
Chawra has been working on the completion of the project
sincerely from start to finish. I certify that the project is up to
my expectations and can be submitted for evaluation.
Teacher’s Signature
Student’s Signature
Date: -……………….
Introduction
Introduction to Tic Tac Toe Python Game
Tic Tac Toe is a timeless and universally
recognized game that is often one of the first
logic-based games introduced to children. It
is a simple two-player game played on a 3x3
grid, where players take turns marking a
space in the grid with either an "X" or an "O".
The objective is to be the first to place three
of their symbols in a row—either horizontally,
vertically, or diagonally.
This project involves developing the classic
Tic Tac Toe game using the Python
programming language. The goal is to
recreate the gameplay in a console-based
environment, allowing two users to play
against each other in a turn-by-turn fashion.
The simplicity of the game mechanics makes
it an excellent choice for beginner
programmers looking to apply fundamental
concepts such as loops, conditionals,
functions, and input handling.
By implementing this game in Python, we
explore essential programming skills while
also engaging in practical software
development. This version of the game does
not require external libraries or advanced
tools, making it accessible and
straightforward for anyone with a basic
understanding of Python.
The project not only enhances problem-
solving and logical thinking but also serves as
a foundation for more advanced game
development techniques in the future, such
as integrating a graphical user interface (GUI)
or implementing artificial intelligence for
single-player mode.
Python overview :-
Python is a versatile, high-level, interpreted
programming language developed by Guido
van Rossum and first released in 1991. Its
design philosophy emphasizes code
readability and simplicity, making it an
excellent choice for both beginners and
experienced developers. Python uses
indentation to define code blocks, resulting in
clean and easy-to-read syntax.
The language supports multiple programming
paradigms, including procedural, object-
oriented, and functional programming.
Python's extensive standard library provides
modules and packages for handling
everything from file I/O and regular
expressions to internet protocols and data
serialization. Its large ecosystem of third-
party libraries extends its capabilities even
further, with popular packages such as
NumPy and Pandas for data analysis,
TensorFlow and PyTorch for machine
learning, Django and Flask for web
development, and Matplotlib for data
visualization.
Python is platform-independent and widely
used across various domains, including web
development, scientific computing, artificial
intelligence, automation, cybersecurity,
finance, and education. Its strong community
support, comprehensive documentation, and
abundance of online resources make it one of
the most accessible and popular
programming languages today. Python’s
ability to integrate with other languages and
tools, along with its ongoing development
and support, ensures its continued relevance
and growth in the software industry.
Features of python :-
Simple
And Readable Syntax
Python is designed to be easy to read and
write. Its clean, straightforward syntax uses
indentation to define code blocks, which
enhances code clarity and reduces the
chance of syntax errors. This simplicity
makes Python an excellent choice for
beginners and allows experienced
developers to write maintainable code
quickly.
Interprete
d Language
Python does not require compilation
before execution. The Python interpreter
reads and executes the code line-by-line,
which makes the development process
faster and easier, especially for testing
and debugging.
Dynamical
ly Type
In Python, you do not need to declare
variable types explicitly. The interpreter
assigns the data type during runtime based
on the value assigned. This dynamic typing
allows for more flexible and concise
code.
Cross-Platform Compatibility
Python is platform-independent, meaning
the same code can run on various
operating systems such as Windows,
macOS, and Linux without modification, as
long as the Python interpreter is installed.
Extensive Standard Library
Python includes a rich standard library that
provides modules and functions for tasks
like file I/O, regular expressions, data
serialization, web services, and more,
reducing the need for external libraries for
many common tasks.
Large and Community Support
Python one of the largest and most active
programming communities. This
community contributes to continuous
improvement, extensive documentation
and a vast amount of online tutorial, forms
and third-party libraries.
Open
Source And Free
Python is open-source software,meaning it
is free to use,distribute, and modify. Its
open development model encourage
contributions from developers worldwide.
Multiple Programming Paradigms
Python supports procedural, object-
orientated, and functional programming
paradigms. The flexibility allows developer
to choose best approach for their specific
project needs.
Extensible And Embeddable
Python can be extended with modules
written in other language like C or C++,
allowing to performance optimization. It
can also embed within other application to
provide scripting capabilities.
Vast
Third-Party Ecosystem
Beyond the standard library, python
has a massive collection of third-party
libraries and frameworks that extend
its functionality. Popular ones include
Django and Flask for Web-
Development, NumPy and Pandas for
data analysis. TensorFlow and PyTorch
for machine learning and Selenium for
automation.
Automatic Memory Management
Python has built-in garbage
collection, automatically managing
memory allocation and deallocation.
This helps developers focus more on
problem-solving rather than low-level
memory management.
Strong
Support for Integration
Python can easily integrate with other
technologies and languages (e.g., .NET,
Java, C/C++), as well as databases and
network protocols, making it highly
versatile for various applications.
Portability
Since Python code can be run on any
machine with a compatible interpreter, it’s
highly portable, reducing concerns about
hardware or system compatibility.
Advantages of python: -
1. Extensible
2. Portable
3. Free & Open-Source
4. Readable
5. Embeddable
6. Improved Productivity
7. Simple & Easy
8. Object Oriented
9. Interpreted
10.Extensive Libraries
Objective Of This Project
The objective of this project is to design
and develop a simple Tic Tac Toe game
using Python programming language
without any hardware or circuit
components. The game will allow two
players to play alternately on a 3x3 grid,
following standard Tic Tac Toe rules. The
main focus is to apply fundamental
programming concepts such as:
1.Control structures: loops, conditionals,
and functions.
2.Data structures: lists and matrices to
represent the game board.
3.Input/Output handling: user input and
display of the game state.
4.Game logic: checking for win, draw, or
invalid moves.
5.Code modularity: using functions for
better organization and maintainability.
Proposed System
The proposed system is a console-
based Tic Tac Toe game developed
using Python programming language. It
allows two players to play alternately
on a 3x3 grid by entering their moves
via the keyboard. The system initializes
an empty game board and displays it
after every move, providing real-time
updates of the game status. It validates
each player's move to ensure the
chosen cell is empty and within the
valid range. The program implements
the complete game logic to check for
winning conditions after every move,
including horizontal, vertical, and
diagonal wins. It also checks for a draw
if all cells are filled without a winner.
The system switches turn between the
players automatically and provides
appropriate messages for invalid
inputs, wins, and draws. This project
aims to demonstrate the use of
fundamental programming concepts
such as functions, loops, conditional
statements, and lists in Python. Since
the system runs entirely on software, it
does not require any hardware or
circuit integration and can be executed
on any platform with Python installed.
The simplicity of the interface and the
modular structure of the code make it
easy to understand, maintain, and
expand for future improvements.
System Development Life
Cycle (SDLC)
The development of the Tic Tac Toe game in
Python follows the System Development Life
Cycle (SDLC) to ensure a structured and
efficient development process. In the
Planning phase, the objective of creating a
simple, interactive, and educational console-
based game was defined, with a focus on
applying Python programming concepts.
During the Analysis phase, the requirements
were gathered, identifying the need for a 3x3
grid, two-player functionality, move
validation, win/draw detection, and user-
friendly interaction. In the Design phase, the
game structure was planned, including the
use of functions for modular code, lists for
board representation, and control structures
for game flow management. The
Development phase involved writing the
Python code, implementing the game logic,
input handling, and board display. The
Testing phase included running multiple test
cases to verify correct win detection, draw
conditions, invalid move handling, and
overall game stability. After successful
testing, the game proceeded to the
Implementation phase, where it was
deployed to run on any Python-supported
platform. Finally, in the Maintenance phase,
the game can be updated for improvements,
such as adding a graphical interface, AI
opponent, or additional features based on
user feedback and future requirements.
Modules And Its Uses
1.random (optional, if AI or random
first player is added)
Used to randomly select which
player starts first.
Can be used to generate ai moves
(random valid cell selection)
2.os (optional)
Used to clear the console screen
after each move for a cleaner
interface (os. system('cls') or os.
system('clear') depending on the
OS).
3.Custom User-Defined Modules
(Functions):
Display_board (): To print the
current state of the board.
Player_input (): To take player
move input.
check_win (): To check for
winning conditions
Check_draw (): To check if the
game is a draw.
Switch_player (): To alternate
turns between players.
Validate_move (): To ensure that
moves are within valid range and
not overwriting existing moves
Flowchart
Source code
# Tic Tac Toe Game - Python 3.13
Compatible
def display_board(board: list[str]):
"""Displays the current board state"""
print("\n")
for i in range(3):
print(f" {board[i*3]} | {board[i*3+1]} |
{board[i*3+2]} ")
if i < 2:
print("---+---+---")
print("\n")
def check_win(board: list[str], player: str) ->
bool:
"""Checks if the given player has won"""
win_conditions = [
(0, 1, 2), (3, 4, 5), (6, 7, 8), # Rows
(0, 3, 6), (1, 4, 7), (2, 5, 8), # Columns
(0, 4, 8), (2, 4, 6) # Diagonals
]
return any(board[a] == board[b] ==
board[c] == player for a, b, c in
win_conditions)
def check_draw(board: list[str]) -> bool:
"""Checks if the board is full (draw)"""
return all(cell != " " for cell in board)
def get_valid_move(board: list[str]) -> int:
"""Gets a valid move from the player"""
while True:
try:
move = int(input("Choose your move
(1-9): ")) - 1
if move not in range(9):
print("Invalid input! Enter a number
between 1 and 9.")
elif board[move] != " ":
print("Cell already occupied!
Choose another.")
else:
return move
except ValueError:
print("Invalid input! Please enter a
valid number.")
def play_game():
"""Main game function"""
board = [" "] * 9
current_player = "X"
while True:
display_board(board)
print(f"Player {current_player}'s turn:")
move = get_valid_move(board)
board[move] = current_player
if check_win(board, current_player):
display_board(board)
print(f"🎉 Player {current_player}
wins!")
break
elif check_draw(board):
display_board(board)
print("It's a draw!")
break
current_player = "O" if current_player
== "X" else "X"
if __name__ == "__main__":
play_game()
Output screen
When “X” wins
When ”O” wins
When “X” draws the game
When “O” draws the game
Limitation And Future Scope
Limitations:
1.Two-Player Only:
The current version only supports two
human players taking turns; no single-
player mode or AI opponent is available.
2.Text-Based Interface:
The game uses a simple console
interface, which may not be as user-
friendly or visually appealing as a
graphical interface.
3.Limited Board Size:
The game is restricted to a standard 3x3
grid; larger or customizable boards are
not supported.
4.No Save or Resume Functionality:
Players cannot save the game progress
and resume later.
5.Basic Input Validation:
While it handles invalid inputs, there is no
sophisticated error recovery or help
system for players.
6.No Score Tracking:
The game does not keep track of the
number of wins, losses, or draws over
multiple rounds.
Future Scope:
1.Single-Player Mode with AI:
Implement AI using algorithms like
Minimax, allowing players to play against
the computer.
2.Graphical User Interface (GUI):
Use libraries like tkinter or pygame to
develop a visually appealing and
interactive interface.
3.Multiplayer Over Network:
Extend the game to allow online
multiplayer functionality.
4.Custom Board Sizes:
Allow players to choose different grid
sizes like 4x4 or 5x5, making the game
more challenging.
5.Game History and Score Tracking:
Add features to store past game results
and track player performance.
6.Mobile App Development:
Develop versions for Android or iOS
platforms using frameworks like Kivy.
7.Sound Effects and Animations:
Enhance user experience by adding audio
feedback and simple animations.
Requirement
Software Requirements:
Operating System:
Windows / Linux / macOS (any OS that
supports Python)
Programming Language:
Python 3.x (recommended: Python 3.8 or
higher, including Python 3.13)
Python IDE or Editor (any one):
o IDLE (default Python IDE)
o PyCharm
o VS Code
o Sublime Text
o Jupyter Notebook (optional)
Python Interpreter:
Python 3 installed on the system
External Libraries:
None (the basic version doesn’t require
any external packages)
Processor
Minimum: Dual-core (Intel or AMD)
RAM:
Minimum: 2 GB
Recommended: 4 GB or higher
Storage:
Around 100 MB for Python installation and
code files
Display:
Standard monitor or laptop screen for
console display
Input Devices:
Keyboard (for entering moves)
Functional Requirements:
Initialize and display a 3x3 Tic Tac Toe
board.
Accept input from two players.
Validate the moves to ensure legal
inputs.
Check for winning or draw conditions
after each move.
Display the winner or announce a draw.
Allow replay or exit after a game ends.
Non-Functional Requirements:
User-friendly console interface.
Fast response and minimal delay in
processing.
Reliable error handling for invalid inputs.
Maintainable and modular code structure
for easy updates.
Biblography
1. www.wikipedia.com
2. www.slideshare.net
3. www.geeksforgeeks.org
4. www.google.com
5. www.youtube.com
6. COMPUTER SCIENCE WITH PYTHON BY SUMITA ARORA
CLASS XIITH(BOOK).