Mini Projext
Mini Projext
Submitted to
RAJIV GANDHI PROUDYOGIKI VISHWAVIDYALAYA
BHOPAL (M.P)
Department of CSE-AIDS
Lakshmi Narain College of Technology, Bhopal (M.P.)
Session
2023-24
LAKSHMI NARAIN COLLEGE OF TECHNOLOGY, BHOPAL
DEPARTMENT OF CSE-AIDS
CERTIFICATE
This is to certify that the work embodied in this project work entitled ”Tic Tac Toe
Game” has been satisfactorily completed by the Yash kumar soni (Roll no. =
227). It is a bonafide piece of work, carried out under the guidance in
Department of CSE- AIDS, Lakshmi Narain College of Technology, Bhopal
for the partial fulfillment of the Bachelor of Technology during the academic
year 2023-2024.
Jyoti Pasi
Approved By
DEPARTMENT OF CSE-AIML
ACKNOWLEDGEMENT
We would also thank our institution and all the faculty members without
whom this project work would have been a distant reality.
Signature
8. Coding 13-23
10. References 26
Total 26 Pages
CHAPTER 1
Overview
Tic Tac Toe is a simple, two-player game where players
take turns marking spaces in a 3x3 grid.
Players
Player 1: Marks their moves with an "X".
Player 2: Marks their moves with an "O".
Rules
1. Turn Order: Players take turns to make a move, starting
with Player 1.
2. Move: On their turn, a player places their mark ("X" or
"O") in one of the empty cells.
3. Winning Condition: The first player to have three of
their marks in a row (horizontally ,
Literature Survey
Historical Background
Origins: The exact origins of Tic Tac Toe are unclear, but
the game is believed to have ancient roots.
Similar games were played in ancient Egypt
(circa 1300 BC) and Rome.
Evolution: The modern version of Tic Tac Toe emerged in
the 19th century, with its simple rules making
it a popular pastime.
Educational Value
Learning Tool: The game is used in educational settings to teach
logic, strategy, and critical thinking. It is simple
enough for young children to understand but
complex enough to introduce basic
programming concepts.
Programming Projects: Many introductory programming
courses include projects to develop Tic
Tac Toe games, covering topics like user
interface design, algorithm
implementation, and game logic.
[3]
CHAPTER 3
application.
3. Technical Requirements:
Programming Languages:
=> For web-based: HTML, CSS, JavaScript.
=> For standalone applications: Python, Java, or any other
preferred language.
Development Frameworks (optional): Use frameworks such as
React for web applications or libraries like Pygame for
Python-based implementations.
AI Implementation: Use the minimax algorithm to create an AI
opponent that plays optimally.
4. Project Phases:
Planning: Define detailed requirements and design the game
architecture.
Design: Create wireframes and design the user interface.
Implementation:
=> Develop the game board and user interface.
=> Implement game logic and rule enforcement.
=> Develop AI for the computer opponent.
Testing: Conduct thorough testing to ensure functionality,
usability, and performance.
Deployment: Deploy the game on a suitable platform (web
server, app store, etc.).
Documentation: Provide comprehensive documentation for[5]
CHAPTER 4
Problem Analysis
Tic Tac Toe is a simple and popular game with straightforward
rules, making it an ideal project for learning basic game
development concepts.
Key Elements:
Game Board: A 3x3 grid where players place their marks (X or
O).
Players: Two players take turns to place their marks on the
board.
Game Logic: Rules that determine valid moves, win conditions,
and draw conditions.
User Interface: The visual representation of the game board
and the means by which players interact with
the game.
Requirement Specification
1. Functional Requirements:
Game Initialization:
*The game should initialize with an empty 3x3 grid.
*The game should indicate which player starts first
(typically
*Player 1 with 'X').
2.Player Input:
*The game should accept input from two players,
alternating turns.
*Players should be able to select an empty cell to place [6]
their mark (X or O).
Game Board Update:
The game board should update to reflect the player's move
immediately after input.
Win Condition:
The game should check for a win condition after each move.
A win is achieved when a player places three of their marks in
a horizontal, vertical, or diagonal row.
If a win condition is met, the game should announce the
winner and end the game.
Draw Condition:
The game should check for a draw condition when all cells
are filled.
If all cells are filled and no player has won, the game should
declare a draw and end the game.
Invalid Move Handling:
The game should prevent players from placing a mark in an
already occupied cell.
The game should prompt the player to make a valid move if
an invalid move is attempted.
Restart Option:
The game should provide an option to restart the game after
it ends.
2. Non-Functional Requirements:
Usability:
The game should have a user-friendly interface that is easy
[8]
CHAPTER 5
1. System Architecture
The Tic Tac Toe game system can be divided into several
components:
User Interface (UI): Handles user input and displays the game
board.
Game Logic: Manages the game rules, state, and win/draw
conditions.
Controller: Mediates interactions between the UI and the Game
Logic.
[9]
3. Entity-Relationship Diagram (ERD)
Player Game
Game_id
Player_id
Mark CurrentTurn
Board
Player_name
[10]
CHAPTER 6
Software Environment
Development Tools:
Integrated Development Environment (IDE):
Visual Studio Code
Version Control System:
Git (with GitHub, GitLab, or Bitbucket for remote repositories)
Build Tools:
npm (for JavaScript projects)
Make (for C/C++ projects)
Programming Languages:
Primary Language: Java, Python, JavaScript, C#, or any language
suitable for the platform chosen
Optional Languages: HTML/CSS (for web interface)
Frameworks/Libraries:
Frontend (if applicable):
HTML5, CSS3, JavaScript
React, Angular, or Vue.js (optional)
Backend (if applicable):
Node.js (JavaScript)
Flask/Django (Python)
Spring Boot (Java)
Operating System:
Development OS: Windows 10/11, macOS, or any Linux distribution
Target OS:
Windows, macOS, Linux (for desktop)
Android, iOS (for mobile)
[11]
CHAPTER 7
[12]
CHAPTER 8
Coding
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>xo-game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Tic Tac Toe</h1>
<a href="single.html"><button class="single">Single Player</button></a>
<a href="multi.html"><button class="multi">Multi Player</button></a>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi Player</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<p class="game-info"></p>
<div class="tic-tac-toe">
[13]
<div class="box box1"></div>
<div class="box box2"></div>
<div class="box box3"></div>
<div class="box box4"></div>
<div class="box box5"></div>
<div class="box box6"></div>
<div class="box box7"></div>
<div class="box box8"></div>
<div class="box box9"></div>
</div>
let currentPlayer;
let gameGrid;
const winningPositions = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]; [14]
function initGame() {
currentPlayer = "X";
gameGrid = ["","","","","","","","",""];
newGameBtn.classList.remove("active");
gameInfo.innerText = `Current Player - ${currentPlayer}`;
initGame();
function swapTurn() {
currentPlayer = currentPlayer === "X" ? "O" : "X";
gameInfo.innerText = `Current Player - ${currentPlayer}`;
}
function checkGameOver() {
let winner = "";
winningPositions.forEach((position) => {
if (gameGrid[position[0]] !== "" &&
gameGrid[position[0]] === gameGrid[position[1]] &&
gameGrid[position[1]] === gameGrid[position[2]]) {
winner = gameGrid[position[0]];
boxes.forEach((box) => {
box.style.pointerEvents = "none";
}); [15]
boxes[position[0]].classList.add("win");
boxes[position[1]].classList.add("win");
boxes[position[2]].classList.add("win");
}
});
if (fillCount === 9) {
gameInfo.innerText = "Game Tied !";
newGameBtn.classList.add("active");
}
}
function handleClick(index) {
if (gameGrid[index] === "") {
boxes[index].innerText = currentPlayer;
gameGrid[index] = currentPlayer;
boxes[index].style.pointerEvents = "none";
swapTurn();
checkGameOver();
// If it's the computer's turn and the game is still active, let the
computer make a move
if (currentPlayer === "O" && !document.querySelector(".active")) {
setTimeout(computerMove, 500);
}
}
} [16]
function computerMove() {
let emptyCells = gameGrid.reduce((acc, val, idx) => {
if (val === "") {
acc.push(idx);
}
return acc;
}, []);
handleClick(computerMoveIndex);
}
newGameBtn.addEventListener("click", initGame);
[18]
Java script of multi player
const boxes = document.querySelectorAll(".box");
const gameInfo = document.querySelector(".game-info");
const newGameBtn = document.querySelector(".btn");
let currentPlayer;
let gameGrid;
const winningPositions = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
];
function checkGameOver() {
let answer = "";
winningPositions.forEach((position) => {
//all 3 boxes should be non-empty and exactly same in value
if( (gameGrid[position[0]] !== "" || gameGrid[position[1]] !== "" ||
gameGrid[position[2]] !== "")
&& (gameGrid[position[0]] === gameGrid[position[1]] ) &&
(gameGrid[position[1]] === gameGrid[position[2]])) {
//check if winner is X
if(gameGrid[position[0]] === "X")
answer = "X";
else {
answer = "O";
}
Project Limitations
Simple Game Mechanics:
Limitation: The game only supports basic 3x3 Tic Tac Toe,
limiting strategic depth and replayability.
Impact: Players may quickly lose interest after a few
rounds.
Two-Player Local Mode Only:
Limitation: The current implementation only supports two
players on the same device.
Impact: This restricts the game's accessibility and
enjoyment to situations where both players are physically
present.
Future Scope
Enhanced Game Mechanics:
Expansion: Introduce larger grid sizes (e.g., 4x4, 5x5) or
different variations of the game (e.g., 3D Tic Tac Toe).
Benefit: Increases the game's complexity and strategic
depth, offering more challenges and replay value.
Online Multiplayer Support:
Expansion: Implement online multiplayer functionality,
allowing players to compete over the internet.
Benefit: Broadens the player base and enables friends and
strangers to play together, enhancing social interaction.
[24]
AI Opponent:
Expansion: Develop various levels of AI opponents, from beginner
to expert.
Benefit: Allows solo play, helps players improve their skills, and
provides a challenging experience for all skill levels.
Online Multiplayer:
Implementing online multiplayer functionality to allow players to
for winning.
[25]
CHAPTER 10
References
[26]