Тёмный

Maze Generation Algorithm - Recursive Backtracker 

Easy Learn Tutorial
Подписаться 18 тыс.
Просмотров 73 тыс.
50% 1

How to generate random mazes using the Recursive Backtracker algorithm. This tutorial describes the simplest maze generator algorithm using a stack and depth-first searching. I show an implementation using JavaScript.
Keep in mind that this algorithm, although it is very easy to code and understand, results in very complex mazes (the maze will be more difficult to solve as it gets bigger), you can create much more complicated labyrinths using other algorithms. Depending on your requirements, this should be enough, however.
LIVE DEMO: easylearntutorial.com/live-dem...
The algorithm (source: WikiPedia)
The depth-first search algorithm of maze generation is frequently implemented using backtracking:
1. Make the initial cell the current cell and mark it as visited
2. While there are unvisited cells
2.1. If the current cell has any neighbors which have not been visited
2.1.1. Choose randomly one of the unvisited neighbors
2.1.2. Push the current cell to the stack
2.1.3. Remove the wall between the current cell and the chosen cell
2.1.4. Make the chosen cell the current cell and mark it as visited
2.2. Else if stack is not empty
2.2.1. Pop a cell from the stack
2.2.2. Make it the current cell
2.3. Else
2.3.1. Pick a random unvisited cell, make it the current cell and mark it as visited
Programming tutorials by Easy Learn Tutorial - because anyone can learn how to become an expert software and web developer!
Copyright (c) 2013 Rodrigo Silveira - www.easylearntutorial.com

Опубликовано:

 

12 июл 2014

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@Tgwizman
@Tgwizman 8 лет назад
Besides how you left many gaps in the code, it was a decent video. I'm sure you did it on purpose, however I'll state it, you made that music 10x louder than you. I have to turn my volumn up to 80% just to hear you, then at the end of the video, the music starts blasting throughout my house. Why would you do this?
@insightfulgarbage
@insightfulgarbage 7 лет назад
because he probably didn't even think to level the sounds
@therealvortex100
@therealvortex100 4 года назад
very nice explanation . Thank you
@HoloDoctor90
@HoloDoctor90 4 года назад
thanks, that helps me a lot :)
@nz881
@nz881 6 лет назад
Hey man, nice video. Can you tell me what the time and space complexities are for this algorithm?
@popcorntimes5183
@popcorntimes5183 5 лет назад
The time complexity is 2^n because it has to explore all the path
@nimrod7690
@nimrod7690 8 лет назад
Thank you! very helpful. how can I determine where is the and end of the maze?
@CodingKiwi
@CodingKiwi 8 лет назад
+NoReturn86 When you start the generation, and the algorithm runs until it ends up at a cell with no free neighbors for the first time. Then, before the algorithm sets the cell as visited and goes back the path, you save the coordinates of this cell and you have a path from the start cell to this cell which has the longest path (I guess). Hope that helped :)
@vyorkin
@vyorkin 8 лет назад
there will be a screamer at the end of this video, careful (:
@israamousa6587
@israamousa6587 7 лет назад
Can you write the c language of the mazes game plz
@HickoreyMuffins
@HickoreyMuffins 10 лет назад
amazing!/
@witsqafa
@witsqafa 8 лет назад
I wonder where I can found this case solver by using Python.. thanks
@sujitroy4236
@sujitroy4236 7 лет назад
do it yourself if u understood the logic then its not hard to implement
@robinhood1238
@robinhood1238 8 лет назад
Isn't this just depth first search?
@CJBurkey
@CJBurkey 9 лет назад
What is the intro song?
@Sexyallouette
@Sexyallouette 8 лет назад
+James Burkey Michael Curtis - No
@CJBurkey
@CJBurkey 8 лет назад
thnx
@screamingfox5666
@screamingfox5666 8 лет назад
NICE
@Luis-Torres
@Luis-Torres 6 лет назад
this video is sooo quite -_- lol
Далее
Programming Mazes
27:11
Просмотров 190 тыс.
Maze Solving - Computerphile
17:15
Просмотров 1,1 млн
Nurse's dream !! 😂😂
00:17
Просмотров 2,3 млн
A Comparison of Pathfinding Algorithms
7:54
Просмотров 710 тыс.
MarI/O - Machine Learning for Video Games
5:58
Просмотров 11 млн
Dependency Injection, The Best Pattern
13:16
Просмотров 762 тыс.
The Fastest Maze-Solving Competition On Earth
25:22
Просмотров 19 млн
Event Bus: GWT Tutorial (Google Web Toolkit)
16:33
Просмотров 16 тыс.
8 Maze Generating Algorithms in 3 Minutes
2:47
Просмотров 52 тыс.