{"id":22120246,"url":"https://github.com/joshbrew/js-maze-generator-with-a-star-solver","last_synced_at":"2025-03-24T06:27:29.607Z","repository":{"id":204783285,"uuid":"712653589","full_name":"joshbrew/JS-Maze-Generator-with-A-Star-Solver","owner":"joshbrew","description":"Pure JS Maze Generator and A* with game template for racing AI. Comes w/ hunt \u0026 kill and depth-first generator templates","archived":false,"fork":false,"pushed_at":"2024-03-16T23:18:36.000Z","size":10613,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T12:15:12.171Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshbrew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-31T22:55:57.000Z","updated_at":"2024-03-21T21:41:01.000Z","dependencies_parsed_at":"2024-12-02T08:03:08.682Z","dependency_job_id":"c14ee454-a8fb-4c70-946f-ec9fc13bd6a4","html_url":"https://github.com/joshbrew/JS-Maze-Generator-with-A-Star-Solver","commit_stats":null,"previous_names":["joshbrew/js-maze-generator-with-a-star-solver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbrew%2FJS-Maze-Generator-with-A-Star-Solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbrew%2FJS-Maze-Generator-with-A-Star-Solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbrew%2FJS-Maze-Generator-with-A-Star-Solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbrew%2FJS-Maze-Generator-with-A-Star-Solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshbrew","download_url":"https://codeload.github.com/joshbrew/JS-Maze-Generator-with-A-Star-Solver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245220247,"owners_count":20579731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T14:21:50.146Z","updated_at":"2025-03-24T06:27:29.528Z","avatar_url":"https://github.com/joshbrew.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Maze generator and game template with A* solver\n\nInteractive maze generator with start/end goals, multiple players, an A* solver for pathfinding. Includes octagonal coordinates with a simple boolean, works in all maze solvers and the A* solver too.\n\n### [Live Demo](https://astarmazesolver.netlify.app/)\n\nMaze examples:\n- Depth First Search\n- Hunt \u0026 Kill\n- Depth First with random path joining (easy mode)\n- Sidewinder\n- Ellers\n- Hunt \u0026 Kill with Braids (set to octagonal/diagonal mode), with octagonal solving.\n- Remove random dead ends till no more 3 or 4 sided cells.\n- Remove random dead ends in a spiral from the center (always solvable).\n\n\nAlso a simple BabylonJS render with instanced static meshes. Needs to be threaded with better culling for actual use. \n\nLots of comments in the code for explaining.\n\n- A* does single and multiagent pathfinding, multiagent allows e.g. for setting avoidance/wait rules for each other on each pass.\n- Also a funky IDA* implementation (see maze 3), it only keeps a self-trimming open set that helps keep memory overhead low. \n- Includes a search visualization, note the canvas stuff is not efficient but it's plenty fast for demoing.\n\n# Run Example\n\nWith latest NodeJS LTS installed. Open this folder in the command line (e.g. via VS Code).\n\nRun: `npm i -g tinybuild` the `npm start` or `tinybuild`\n\nhttps://github.com/joshbrew/JS-Maze-Generator-with-A-Star-Solver/assets/18196383/0b6cb3a5-4140-44a4-8340-25947b93904f\n\n![cap](./screenshots/Capture.PNG)\n![cap2](./screenshots/Capture2.PNG)\n![cap3](./screenshots/Capture3.PNG)\n![cap4](./screenshots/Capture4.PNG)\n![cap5](./screenshots/Capture5.PNG)\n![cap6](./screenshots/Capture6.PNG)\n![cap7](./screenshots/Cap7.PNG)\n\n\n# Usage\n\nJust pull the source and follow along with the example, there's no npm distribution.\n\n```html\n\nClick on a maze then use arrow keys to control.\n  \u003cdiv id=\"game1\"\u003e\n    \u003cdiv\u003eDepth First Maze\u003c/div\u003e\n    \u003chr/\u003e\n    \u003cbutton id='depthfirstsolve'\u003eShow Path\u003c/button\u003e\n    \u003cbutton id='depthfirstrace'\u003eRace AI\u003c/button\u003e\n    AI Move Step (seconds): \u003cinput id='depthfirstintv' value='0.3' type='number'/\u003e\n    \u003cdiv\u003e\n        \u003chr/\u003e\n        Maze Dimensions:\u003cbr/\u003e\n        x: \u003cinput id='depthfirstX' type='number' value='20'/\u003e\n        Y: \u003cinput id='depthfirstY' type='number' value='20'/\u003e\n        \u003cbutton id=\"gendepthfirst\"\u003eGenerate Maze\u003c/button\u003e\n    \u003c/div\u003e\n    \u003ccanvas id=\"canvas1\" style=\"width: 50%;\" width=\"500\" height=\"500\"\u003e\u003c/canvas\u003e\n  \u003c/div\u003e\n\n  \u003chr/\u003e\n  \u003cdiv id=\"game2\"\u003e\n    \u003cdiv\u003eHunt and Kill Maze\u003c/div\u003e\n    \u003chr/\u003e\n    \u003cbutton id='huntkillsolve'\u003eShow Path\u003c/button\u003e\n    \u003cbutton id='huntkillrace'\u003eRace AI\u003c/button\u003e\n    AI Move Step (seconds): \u003cinput id='huntkillintv' value='0.3' type='number'/\u003e\n    \u003cdiv\u003e\n        \u003chr/\u003e\n        Maze Dimensions:\u003cbr/\u003e\n        x: \u003cinput id='huntkillX' type='number' value='20'/\u003e\n        Y: \u003cinput id='huntkillY' type='number' value='20'/\u003e\n        \u003cbutton id=\"genhuntkill\"\u003eGenerate Maze\u003c/button\u003e\n    \u003c/div\u003e\n    \u003ccanvas id=\"canvas2\" style=\"width: 50%;\" width=\"500\" height=\"500\"\u003e\u003c/canvas\u003e\n  \u003c/div\u003e\n\u003cscript src=\"dist/index.js\"\u003e\u003c/script\u003e\n```\nAssuming the built script template in this repo, else you can add `type=\"module\"` to serve the unbuilt script frp, `src=\"index.js\"`.\n\n```js\n\nimport { Maze } from \"./src/maze\";\nimport { AStarSolver } from \"./src/astar\";\nimport { MazeGame } from \"./src/mazegame\";\nimport { generateDepthFirstMaze, generateHuntAndKillMaze } from \"./src/generators\";\n\nlet nCellsPerRow = 20;\nlet nRows = 20;\n\nconst maze1 = new Maze(nCellsPerRow, nRows, generateDepthFirstMaze);\nconst maze2 = new Maze(nCellsPerRow, nRows, generateHuntAndKillMaze);\n\nconst aStarSolver1 = new AStarSolver(maze1);\nconst aStarSolver2 = new AStarSolver(maze2);\n\nconst mazeGame1 = new MazeGame(maze1, 'canvas1', aStarSolver1, 'darkred');\nconst mazeGame2 = new MazeGame(maze2, 'canvas2', aStarSolver2);\n\n//setup UI\ndocument.addEventListener('keydown', MazeGame.keyDownHandler);\n\nmazeGame1.setAIInputEvents('depthfirstintv', 'depthfirstsolve', 'depthfirstrace');\nmazeGame2.setAIInputEvents('huntkillintv', 'huntkillsolve', 'huntkillrace');\n\nmazeGame1.setGeneratorInputEvents('gendepthfirst','depthfirstX','depthfirstY');\nmazeGame2.setGeneratorInputEvents('genhuntkill','huntkillX','huntkillY');\n\n```\n\nAdd CSS to your liking:\n\n```css\nbody {\n    background-color: darkslategray;\n    color:white;\n    font-family: Arial, sans-serif;\n    line-height: 1.6;\n    margin: 0;\n    padding: 20px;\n  }\n\n  #game1,\n  #game2 {\n    max-width: 600px;\n    margin: 20px auto;\n    padding: 15px;\n    border-radius: 10px;\n    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n  }\n\n  #game1 div,\n  #game2 div {\n    margin-bottom: 15px;\n  }\n\n  button {\n    padding: 8px 15px;\n    font-size: 16px;\n    color:white;\n    cursor: pointer;\n    background-color: royalblue;\n    border: 0;\n    border-radius: 5px;\n    margin-right: 10px;\n  }\n\n  button:hover {\n    background-color: #4cae4c;\n  }\n\n  input[type=\"number\"] {\n    padding: 8px;\n    width: 60px;\n    border: 1px solid #ddd;\n    border-radius: 5px;\n    margin-right: 10px;\n  }\n\n  canvas {\n    display: block;\n    margin: 0 auto;\n    border: 1px solid #ddd;\n    background-color: ghostwhite;\n  }\n\n  div {\n    font-size: 18px;\n  }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshbrew%2Fjs-maze-generator-with-a-star-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshbrew%2Fjs-maze-generator-with-a-star-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshbrew%2Fjs-maze-generator-with-a-star-solver/lists"}