Daa_report_final[1]
Daa_report_final[1]
BACHELOR OF
TECHNOLOGY IN
COMPUTER SCIENCE AND ENGINEERING (DATA SCIENCE)
Submitted by
Guide: Head:
Vision
To become a Centre of Excellence in Data Science by imparting high quality
education through teaching, training and research
Mission
PSO3. Design and develop efficient software systems using modern tools,
techniques, and platforms to meet societal needs.
PSO4. Apply suitable tools and techniques to build secure distributed
systems.
PROGRAM OUTCOMES
On successful completion of the Program, the graduates of B.Tech. CSE (DS)
Program will be able to:
PO5. Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and
modeling to complex engineering activities with an understanding of the
limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and
the consequent responsibilities relevant to the professional engineering
practice.
PO8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO12 Life-long learning: Recognize the need for, and have the preparation
. and ability to engage in independent and life-long learning in the
broadest context of technological change.
DECLARATION
We hereby declare that this project report titled “Twists and tracks – The Maze Solver”
is a genuine work carried out by us, in B.Tech (Computer Science and Engineering (Data
Science)) degree course of Mohan Babu University, TIrupati and has not been submitted to
any other course or University for the award of any degree by us.
We declare that this written submission represents our ideas in our own words and where
others' ideas or words have been included, we have adequately cited and referenced the original
sources. We also declare that we have adhered to all principles of academic honesty and integrity
and have not misrepresented or fabricated or falsified any idea / data / fact / source in our
submission. We understand that any violation of the above will cause for disciplinary action by
the Institute and can also evoke penal action from the sources which have thus not been properly
cited or from whom proper permission has not been taken when needed.
1.
2.
3.
ABSTRACT
Our travel Our project, "Twists & Tracks – The Maze Solver," aims to create an
intuitive and efficient platform for solving mazes using advanced algorithms like Depth-first
Search (DFS), Breadth-First Search (BFS), and A-star Search. The website utilizes these
algorithms to navigate and find optimal paths through complex maze structures. The platform is
designed to offer users a smooth and interactive experience, where they can easily input maze
configurations and visualize the solving process. By employing DFS, BFS, and A-star
algorithms, the system explores multiple solving strategies to demonstrate different approaches to
pathfinding and optimization. Built with HTML, CSS, and JavaScript, the interface is clean,
responsive, and user-friendly, making it accessible across all devices and screen sizes. The core
of the project leverages efficient algorithms to ensure fast processing and accurate results. The
interface is designed to be visually engaging, with clear step-by-step visualizations of the
algorithm's progress, providing a seamless user experience. JavaScript handles the logic for maze
generation, user interaction, and algorithm execution, making the process dynamic and
interactive. The system is optimized for performance, ensuring that users can quickly solve even
the most challenging mazes. Our goal with "Twists & Tracks" is to offer both an educational and
entertaining experience by showcasing the power of maze-solving algorithms while providing
users with an enjoyable journey through the world of computational problem-solving.
Keywords: Maze solver, Depth-first search, Breadth-first search, A-star search, Algorithm, Java.
TABLE OF CONTENTS
CHAPTER- 1
INTRODUCTION
1.1 Introduction:
This report provides a detailed analysis of a maze solver project developed using advanced
algorithms like Depth-first Search (DFS), Breadth-first Search (BFS), and A-star Search. The
purpose of this project is to demonstrate the efficiency and effectiveness of these algorithms in
finding optimal paths through complex maze structures.
At Twists & Tracks, we understand that problem-solving is more than just finding a solution—
it’s about exploring various approaches, learning from each step, and improving efficiency. Our
maze solver showcases how these algorithms work in real-time to solve puzzles, offering users
the opportunity to see different strategies in action. Whether you're interested in the thorough
exploration of DFS, the level-wise solution of BFS, or the optimized pathfinding of A-star, our
platform allows users to engage with these methods in an interactive way.
Our goal is to make maze-solving both educational and engaging by providing a clear and
dynamic visualization of each algorithm’s process. By leveraging Java and interactive design,
we ensure that the experience is user-friendly and intuitive, enabling users to learn and
experiment with ease.
2
Department of CSSE
TWISTS & TRACKS
The fact that solving mazes efficiently can be complex due to the need for choosing the right
pathfinding algorithm creates challenges for developers and enthusiasts. The variety of
algorithms and their specific use cases make it difficult to select the best one for a given maze,
especially when considering factors like performance and optimality. This hinders developers'
ability to implement quick, reliable, and efficient maze-solving solutions. Therefore, there is a
need for a simple maze solver that incorporates multiple algorithms (Depth-First Search,
Breadth-First Search, and A-star Search) to provide different solving strategies and improve
accessibility for users. During the development of this project, we faced challenges with
optimizing the algorithms, handling large mazes, and ensuring smooth integration of various
features.
3
Department of CSSE
TWISTS & TRACKS
1.3 Objectives:
The main objective of the project is to provide users with an efficient and straightforward
maze-solving tool by implementing three popular algorithms—Depth-First Search, Breadth-
First Search, and A-star Search. The objectives are:
1.4 Limitations:
4
Department of CSSE
TWISTS & TRACKS
CHAPTER – 2
METHODOLOGY
The challenge in solving mazes efficiently arises from selecting the most suitable pathfinding
algorithm, as each algorithm has its strengths and limitations based on the maze's complexity and
size. Depth-First Search (DFS), Breadth-First Search (BFS), and A-star Search are three widely
used algorithms, each with different approaches to solving the maze. Therefore, the project aims
to implement these algorithms in a user-friendly interface, allowing users to select the best option
for their maze-solving needs. During the development of this project, we faced issues related to
algorithm optimization, managing memory usage for large mazes, and ensuring smooth
integration of all algorithms within the same system.
5
Department of CSSE
TWISTS & TRACKS
CHAPTER – 3
SYSTEM DESIGN
4.1 Requirements:
The maze solver application is designed with an intuitive interface for ease of use. The
following sections describe the key features and structure of the system:
HOME PAGE: The home page features an interactive maze creation tool, allowing users to
easily design custom mazes. It provides a simple navigation menu to select between different
algorithms (DFS, BFS, A-star) and view step-by-step visualizations of the maze-solving
process.
MAZE SOLVING PAGE: This page displays the generated maze and the selected algorithm’s
progress. It includes interactive controls to pause, resume, or restart the solving process, as well
as adjust maze difficulty and size.
RESPONSIVE DESIGN: The system is optimized for various screen sizes, ensuring a smooth
experience across desktops, tablets, and mobile devices. Layouts adapt to different devices,
allowing users to access features with ease.
6
Department of CSSE
TWISTS & TRACKS
The maze solver application is developed using core technologies to provide an interactive and
efficient experience. The key technologies employed are:
JAVA: The main programming language used for implementing the maze-solving algorithms
(DFS, BFS, A-star), ensuring efficient and scalable performance.
JAVA 2D GRAPHICS: Java's 2D graphics library is employed for rendering the maze and
displaying the step-by-step algorithm execution, providing a clear visual representation.
THREADING: Java's threading capabilities are utilized to handle real-time algorithm execution,
allowing for smooth, stepwise solving of the maze without freezing the UI.
7
Department of CSSE
TWISTS & TRACKS
CHAPTER - 4
IMPLEMENTATION
The implementation of the project involves multiple stages to create a simple maze solver using
DFS, BFS, and A-star algorithms.
First, a thorough needs analysis was conducted to understand the requirements of the maze-
solving tool, its target audience, and the necessary algorithms. This analysis helped define the
objectives for providing efficient, optimal solutions to mazes. Once the requirements were clear,
the design phase began, focusing on creating an easy-to-use interface with clear visual elements,
a dynamic maze generator, and algorithm selector.
After finalizing the design, the development phase began using Java for implementing the
algorithms. The user interface was built using Swing, allowing for the visualization of the maze
and step-by-step solving process. The algorithms were optimized for performance, ensuring
quick and accurate results. Testing was performed to validate the algorithm implementations,
optimize execution time, and ensure the system works smoothly with varying maze sizes and
complexities.
8
Department of CSSE
TWISTS & TRACKS
CHAPTER-5
PROPOSED SYSTEM ARCHITECTURE
The system architecture for the maze solver follows a modular, layered approach. At the
presentation layer, the user interface is developed using Java Swing, providing a graphical
interface to display the maze and the solving process. The application layer handles the business
logic, which includes implementing the DFS, BFS, and A-star algorithms to solve the maze. The
algorithm logic is separated from the UI, ensuring better maintainability. The data access layer,
while minimal, handles maze data generation and manipulation, storing maze configurations
temporarily in memory. The proposed system architecture is designed to be efficient, easy to
expand, and capable of integrating new algorithms or features in the future.
9
Department of CSSE
TWISTS & TRACKS
CHAPTER-6
CODING ANALYSIS AND RESULTS
6.1 Code:
i. Main.java :
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferStrategy;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
10
Department of CSSE
TWISTS & TRACKS
import javax.swing.JTextField;
}
11
Department of CSSE
TWISTS & TRACKS
openMaze.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
runTimeMain.openMaze();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
saveMaze.addActionListener(new ActionListener() {
12
Department of CSSE
TWISTS & TRACKS
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
newGrid.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
runTimeMain.createNodes(true);
}
});
clearSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
runTimeMain.clearSearchResults();
}
});
bfsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (runTimeMain.isMazeValid()) {
algorithm.bfs(runTimeMain.start, runTimeMain.target, runTimeMain.NODES_WIDTH,
runTimeMain.NODES_HEIGHT);
} else {
System.out.println("DIDNT LAUNCH");
}
}
13
Department of CSSE
TWISTS & TRACKS
});
dfsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (runTimeMain.isMazeValid()) {
algorithm.dfs(runTimeMain.getStart());
} else {
System.out.println("DIDNT LAUNCH");
}
});
astarItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (runTimeMain.isMazeValid()) {
algorithm.Astar(runTimeMain.start, runTimeMain.target,
runTimeMain.NODES_WIDTH,
runTimeMain.NODES_HEIGHT);
} else {
System.out.println("DIDNT LAUNCH");
}
});
searchTime.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String input = JOptionPane.showInputDialog(null, "Enter a time it takes to search each
node in miliseconds(default = 100ms) ", "Search Time", JOptionPane.QUESTION_MESSAGE);
algorithm.setSearchTime(Integer.parseInt(input));
}
});
fileMenu.add(exit);
fileMenu.add(saveMaze);
fileMenu.add(openMaze);
14
Department of CSSE
TWISTS & TRACKS
boardMenu.add(newGrid);
boardMenu.add(clearSearch);
algorithmsMenu.add(dfsItem);
algorithmsMenu.add(bfsItem);
algorithmsMenu.add(astarItem);
algorithmsMenu.add(searchTime);
createNodes(false);
setMazeDirections();
}
public void setMazeDirections() {
for (int i = 0; i < nodeList.length; i++) {
for (int j = 0; j < nodeList[i].length; j++) {
Node up = null,down = null,left = null,right = null;
int u = j - 1;
int d = j + 1;
int l = i - 1;
int r = i + 1;
ext));
for (int i = 0; i < nodeList.length; i++) {
for (int j = 0; j < nodeList[i].length; j++) {
if (nodeList[i][j].isWall()) {
outputWriter.write("1");
} else if (nodeList[i][j].isStart()) {
outputWriter.write("2");
} else if (nodeList[i][j].isEnd()) {
outputWriter.write("3");
} else {
outputWriter.write("0");
}
}
outputWriter.newLine();
}
outputWriter.flush();
outputWriter.close();
}
//nodeList[i][j].setColor(Color.BLACK);
int nodeType = Character.getNumericValue(line.charAt(j));
System.out.println("node is " + nodeType);
switch (nodeType) {
case 0:
17
Department of CSSE
TWISTS & TRACKS
nodeList[i][j].setColor(Color.LIGHT_GRAY);
break;
case 1:
nodeList[i][j].setColor(Color.BLACK);
break;
case 2:
nodeList[i][j].setColor(Color.GREEN);
start = nodeList[i][j];
break;
case 3:
nodeList[i][j].setColor(Color.RED);
target = nodeList[i][j];
break;
}
}
}
reader.close();
// System.out.println(stringMaze);
}
}
18
Department of CSSE
TWISTS & TRACKS
if (clickedNode.isWall()) {
clickedNode.clearNode();
return;
}
clickedNode.Clicked(e.getButton());
if (clickedNode.isEnd()) {
if (target != null) {
target.clearNode();
}
target = clickedNode;
} else if (clickedNode.isStart()) {
if (start != null) {
start.clearNode();
}
19
Department of CSSE
TWISTS & TRACKS
start = clickedNode;
}
@Override
public void mouseClicked(MouseEvent arg0) {
}
20
Department of CSSE
TWISTS & TRACKS
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
}
21
Department of CSSE
TWISTS & TRACKS
ii. Algorithm.java :
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Stack;
while (!nodes.empty()) {
curNode.setColor(Color.ORANGE);
try {
Thread.sleep(searchtime);
} catch (Exception e) {
22
Department of CSSE
TWISTS & TRACKS
e.printStackTrace();
}
curNode.setColor(Color.BLUE);
for (Node adjacent : curNode.getNeighbours()) {
nodes.push(adjacent);
}
} else {
curNode.setColor(Color.MAGENTA);
break;
}
}
public void bfs(Node start, Node end, int graphWidth, int graphHeight) {
Queue<Node> queue = new LinkedList<>();
Node[][] prev = new Node[graphWidth][graphHeight];
queue.add(start);
while (!queue.isEmpty()) {
if (!curNode.isSearched()) {
curNode.setColor(Color.ORANGE);
try {
Thread.sleep(searchtime);
} catch (Exception e) {
e.printStackTrace();
}
curNode.setColor(Color.BLUE);
for (Node adjacent : curNode.getNeighbours()) {
23
Department of CSSE
TWISTS & TRACKS
queue.add(adjacent);
prev[adjacent.getX()][adjacent.getY()] = curNode;
}
}
}
shortpath(prev, end);
}
if(pathConstructor != null) {
pathConstructor.setColor(Color.ORANGE);
}
24
Department of CSSE
TWISTS & TRACKS
try {
Thread.sleep(searchtime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void Astar(Node start, Node targetNode, int graphWidth, int graphHeight) {
List<Node> openList = new ArrayList<Node>();
Node[][] prev = new Node[graphWidth][graphHeight];
openList.add(start);
while(!openList.isEmpty()) {
if(curNode.isEnd()) {
curNode.setColor(Color.MAGENTA);
break;
}
curNode.setColor(Color.ORANGE);
try {
Thread.sleep(searchtime);
} catch (Exception e) {
e.printStackTrace();
}
curNode.setColor(Color.BLUE);
for (Node adjacent : curNode.getNeighbours()) {
if(adjacent.isSearched()) {
continue;
}
double f1 = Node.distance(adjacent, targetNode);
double h1 = Node.distance(curNode, start);
}
shortpath(prev, targetNode);
26
Department of CSSE
TWISTS & TRACKS
iii. Node.java :
import java.util.ArrayList;
import java.util.List;
import java.lang.Math;
import java.awt.Color;
import java.awt.Graphics2D;
public Node() {
}
}
if (buttonCode == 2) {
// START
nodeColor = Color.GREEN;
}
if (buttonCode == 3) {
// END
nodeColor = Color.RED;
}
if (buttonCode == 4) {
// CLEAR
clearNode();
}
}
public double getFCost() {
return this.fcost;
}
nodeColor = c;
}
return neighbours;
}
30
Department of CSSE
TWISTS & TRACKS
6.2 Result:
31
Department of CSSE
TWISTS & TRACKS
32
TWISTS & TRACKS
CHAPTER-7
CONCLUSION AND
FUTUREWORK
7.1 Conclusion:
The maze solver built using Depth-First Search, Breadth-First Search, and A-star algorithms
provides an efficient platform to solve mazes with varying complexities. Its interactive design and
multiple algorithm options allow users to understand different solving techniques, offering a
comprehensive and engaging experience for maze-solving enthusiasts.
This project offers several opportunities for future work and improvements. Potential areas include
optimizing the algorithms for faster performance, supporting more complex maze structures, and
adding visualization tools to track the search process. Implementing additional algorithms like
Dijkstra’s or Greedy Best-First Search could broaden the solution options. User customization
features, such as selecting grid sizes or maze difficulty levels, can improve the experience.
Additionally, integrating a mobile app or web interface for easy access, along with real-time maze
generation, can enhance user engagement. Introducing AI-based maze generation for more dynamic
and unpredictable puzzles would further enrich the project. Continuous testing and refining will
ensure optimal performance and accuracy.
33