Create a simple web application using React that implements a novel way to visualize the famous Rat in a Maze Problem which can be solved using backtracking.
Create a simple web application using React that implements a novel way to visualize the famous Rat in a Maze Problem which can be solved using backtracking.
The Rat in a maze is a famous problem in which we have a N x N matrix (the maze) which consists of two types of cells - one the rat can pass through and the other that the rat cannot pass through.
The objective of this problem is that the rat will be at a particular cell and we have to find all the possible paths that the rat can take to reach the destination cell from the given source cell.
Now you will be building a simple react application that will visualize all the possible paths on the web page.
While building this simple react app you will learn ES6 Javascript techniques, how to create react components and apply the Data Structures' and Algorithms' concepts such as Recursion and Backtracking.
The project consists of the following stages:
Maze.js
and Cell.js
for the project. These components will be simple functional componentsProject demo -
Create a simple web application using React that implements a novel way to visualize the famous Rat in a Maze Problem which can be solved using backtracking.
The Rat in a maze is a famous problem in which we have a N x N matrix (the maze) which consists of two types of cells - one the rat can pass through and the other that the rat cannot pass through.
The objective of this problem is that the rat will be at a particular cell and we have to find all the possible paths that the rat can take to reach the destination cell from the given source cell.
Now you will be building a simple react application that will visualize all the possible paths on the web page.
While building this simple react app you will learn ES6 Javascript techniques, how to create react components and apply the Data Structures' and Algorithms' concepts such as Recursion and Backtracking.
The project consists of the following stages:
Maze.js
and Cell.js
for the project. These components will be simple functional componentsProject demo -
First validate the idea by doing a low level implementation (Proof of Concept) of the components involved in the project.This helps you to -
Explore various aspects of the terms mentioned in the preceding sections and also understand the preference to use React over Angular or Vue, all possible ways to solve the Rat in a Maze problem and challenge yourself by implementing other algorithmic problems in a similar illustrative method.
This task includes the setup you may follow to get started with this project.
Search for React dev tools in Chrome extensions and add them for your own testing purpose.
Use react developer tools throughout the project to debug your code better. If new to it refer this to understand how to use it. Also check this out!
npm start
in the terminal and you will get a live server started (on localhost). Explore about this hereIn this task the basic structure of the web application is built (excluding the core functionality) using mainly React alongside HTML, CSS (optional).
Maze
(preferably) which will be used to render cells as containers.function Maze() {
return (
<div >
// Write here the logic to create a N*N grid (maze) UI
// Hint : You can use Material UI Grid and Box Components
</div>
);
}
function Cell(props) {
return (
<div >
// Write here the logic to create a cell UI
// Hint : You can use Material UI Grid and Paper Components
</div>
);
}
export default Cell;
cell.js
file to create components for the cells.maze.js
file to create the components for the maze and inside it itself implement the algorithm (else create another file and import the functions, which may cause unnecessary cluttering ).The basic UI of the app should look like this -
Implement the core functionality of the problem's solution into the app, i.e. basically finding the paths. Here the paths will be from top left to bottom right for a maze with obstacles.
The constraints of the problem are :
calculatePath
function to calculate all the paths from top left to bottom right cell of the maze. This function is solely responsible for the computation of the paths.loadCells
function to load all cells of the maze. This function will be responsible for assigning the cells' roles.maze.js
will be used for the visualisation. So inside this main function (say function Maze()
) you should be assigning the obstacle cells it's boolean value (i.e. 0) so that computation of green cells (paths) can be done.calculatePath
function to get the computation done and return the visualisations using loadCells
function.
/**
* Calculate all possible Maze paths
* @param {Array} matrix - row * column grid(Maze)
* @param {int} i - source initial row index
* @param {int} j - source initial column index
* @param {int} rows - total number of rows in grid
* @param {int} columns - total number of columns in grid
* @return {Array} path - total possible paths
*/
function calculatePaths(matrix, i, j, rows, columns) {
let paths = [];
// Write here the logic to calculate all possible paths from top left of a grid (maze) to bottom right
return paths;
}
/**
* Create all cells for a given maze
* @param {Array} mat - row * column grid(Maze)
* @param {int} rows - total number of rows in grid
* @param {int} columns - total number of columns in grid
* @param {int} gindex - a unique value for each maze
* @return {Array} path - a single valid path
* @return {Array} cells - all the cell components for a given maze.
*/
function loadCells(mat, rows, columns, gindex, path) {
let cells = [];
// Write here the logic to push cell to a grid with type(red = to indicate obstacle ,green = to indicate a possible path ,while = to indicate a possible passage)
return cells;
}
"@material-ui/core": "^4.11.2",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
Now that the core functionalities are implemented the web app is ready. So the web app rendered should look something like this.
Finish your work in complete style.
Publish your work on GitHub with proper folder structure and a good README for people to get to know of your work. Make sure you add a .gitignore file and mention all dependency folders like node_modules in it.
Since this is a React application, go one step further by using a hosting service like Heroku, Firebase or Netlify to host your app and get a live URL.
Share this link among your peers and add this project (with the link and proper documentation) to your resume and voila, you have just boosted your resume.