-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
328 lines (313 loc) · 14 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html>
<html>
<head>
<title>Simple Maze Solver in Javascript and HTML5</title>
<meta name="description" content="A simple maze solver in javascript and HTML5. Traverses a maze using depth-first search, also called Tremaux's algorithm or by using A* Search." />
<meta name="keywords" content="maze,maze solver,maze algorithm,javascript maze,html5 maze,maze solving,maze heuristic,traverse maze,programming,software,A*,pathfinding,A* search" />
<link rel='stylesheet' href='css/bootstrap.min.css' />
<link rel='stylesheet' href='css/bootstrap-responsive.min.css' />
<link rel='stylesheet' href='css/style.css' />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-843113-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class='container' style='margin-left: 30px;'>
<h1>Javascript Maze Solver</h1>
<div class="pull-left" style='margin: 0 0 25px 0;'>
<p>A simple <a href="http://en.wikipedia.org/wiki/Maze_solving_algorithm" target="_blank">maze solver</a>, created with Javascript and HTML5. Traverses a maze and uses either a depth-first search (<a href='http://en.wikipedia.org/wiki/Maze_solving_algorithm#Tr.C3.A9maux.27s_algorithm' target='_blank'>Tremaux</a> algorithm) or a smart search (<a href='http://en.wikipedia.org/wiki/A*_search_algorithm' target='_blank'>A* search</a> algorithm) to find its way through. Oh, did I mention you can make your own maze with JSON, right in the url?</p>
<div class="addthis_toolbox addthis_default_style "><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>
<div id='detailsDiv' class='pull-left' style='cursor: pointer;'>
<div class='pull-left'>
<i id='detailsDivIcon' class='icon-plus-sign'></i>
</div>
<div class='pull-left' style='margin: 0 0 0 5px;'>
Nerdy Details
</div>
</div>
<div id='customDiv' class='pull-left' style='cursor: pointer; margin: 0 0 0 10px;'>
<div class='pull-left'>
<i id='customDivIcon' class='icon-plus-sign'></i>
</div>
<div class='pull-left' style='margin: 0 0 0 5px;'>
Build a Maze
</div>
</div>
<div style='clear: both;'></div>
<div id='details' class='well' style='display: none; margin: 8px 0 0 0;'>
<h4>Tremaux Algorithm</h4>
<p>The Tremaux algorithm is similar to actually walking through the maze. Only the immediate tiles visible to you can be followed.</p>
<p>It begins in a random direction and continues until it hits a wall. It then turns right, until a path is available to walk. Each time the algorithm takes a step, it marks the tile as visited.</p>
<p>The algorithm always tries to first visit an un-visited tile. However, if no new tiles are found, it will backtrack over a visited tile.</p>
<p>It will never visit the same tile more than twice (with the only exception being if the algorithm is stuck in a dead-end, in which case it will re-visit a tile it's already backtracked over, in order to exit the trap).</p>
<p>The maze solution is all tiles that have been visited once.</p>
<h4>A* Search Algorithm</h4>
<p>A* search is similar to having an aerial view of the maze before walking through it. It uses the maze end point to calculate a score from each neighboring tile. It intelligently walks down multiple paths, seemingly at the same time, until it reaches the end.</p>
<p>You would not be able to use this algorithm if you were physically traversing the maze. At least, not easily.</p>
</div>
<div id='custom' class='well' style='display: none; margin: 8px 0 0 0;'>
<p>
<div class='pull-left'>
<a href='?maze={"start": {"x": 3, "y": 0}, "end": {"x": 6, "y": 0}, "width": 20, "height": 10, "map": "
***.**.*************
***....*************
**..****.........***
*..****..*******.***
*.****..********...*
*.****.***********.*
*.****........***..*
*.**************..**
*................***
********************"}'>'G' Maze</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='?maze={"start": {"x": 2, "y": 0}, "end": {"x": 19, "y": 3}, "width": 20, "height": 10, "map": "
**.*****************
**.****............*
**......*****.******
**.*********........
*..*********.*******
**....******.***.***
*****......*.***.***
**....****.*.....***
**.***.....*****...*
********************"}'>Little Maze</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='?maze={"start": {"x": 23, "y": 0}, "end": {"x": 22, "y": 19}, "width": 50, "height": 20, "map": "
***********************.**************************
***********************..*************************
************************..************************
*************************..***********************
**************************..............**********
***************************************..*********
****************...................*****..********
*************....*****************...****..*******
**********....****............******..****..******
********...****....**********....****....**..*****
********.******.*******....*****....****.***..****
********.******.....******.....****.****.****..***
********...********.....******......****.*****.***
**********.....********.....**********...*****.***
**************.....********.....***....*****...***
******************....*********.....******...*****
*********************.....*************....*******
**********************.**....*******....**********
**********************.*****.........*************
**********************.***************************"}'>Vortex</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='?maze={"start": {"x": 1, "y": 51}, "end": {"x": 27, "y": 51}, "width": 30, "height": 52, "map": "
******************************
*******....********....***...*
******..**.*******..**..*..***
*****..*****..***..****...****
*****.**....*..**.*******.****
*****.**.**.**.**.*******.****
****..**.**.**.**.*******.****
****.***.**.**.**.*******...**
****.***.**.**.**.*******.*.**
****.***.**.**.**.*******.*.**
****.***.**.**.**...*****.*.**
****.***.**.**.**.*..****.*.**
****.***.**.**.**.**.****.*.**
****.***.**.**.**.**.****.*.**
****.***.**.**.**.**.****.*.**
****.***.**.**.**.**.****.*..*
****.***.**.**.**.**.****.**.*
***..**..**.**.**.**.****.**.*
***.***.***.**.**.**.****.**.*
***.***.***.**.**.**.****.**.*
***.***.***.**....**.****.**.*
***.***.***.*****.**.****.**.*
***.***.***.**....**..***.****
***.***.***.**.**.***.***.**.*
***.***.***.**.**.***.***.**.*
***.***.***.**.**.***.***.**.*
***.***.***.**.**.***.***.**.*
***.**..***.**.**.***.***.**.*
***.*..****.**.**.***.***.**.*
***...*****.**.**.***.***.**.*
***.*******.**.**.*******.**.*
***.*******.*..**.***.***.**.*
***.*******...***.**..***.**.*
***.**....*.***.*.**.****.**.*
**..**.**.*.***.*.**.****.**.*
**.***.**.*.***.*.**.****.**.*
**.***.**.*.***.*.**.****.**.*
**.***.**.*.***.*.*..****.**.*
**.***.**.*.***.*.*.*****.*..*
**.***.**.*.***.*.*.*****...**
**.***.**.*.***.*.*.*****.****
**.***.**.*..*..*.*.*****.****
*..***.**.**...**.*.*****.****
*.**...**.**.****.*.*****.****
*....****.**.****...*****.****
*.*******.**.****.*******.****
*.*******..*.**.....*****.****
*.********.***..***...***..***
*.********.*...******...**..**
*.......**********************
*.*****.....................**
*.*************************.**
"}'>Bird's Eye View</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='?maze={"start": {"x": 12, "y": 0}, "end": {"x": 9, "y": 19}, "width": 30, "height": 20, "map":"
************.*****************
***********..*****************
***********.******************
*********.....****************
*******...****..**************
*****...*******...************
*****.***.***.***.************
*****.***********.************
*.***..***...***..************
*..***...*****...*******.*****
**.*****...**..****......*****
**..******.**.****..**********
***.****...**...**.***********
***.*....******....***********
***...************...*********
***.****************.*********
***..**************..*********
****...**********...**********
******....*.......************
*********.********************
"}'>Alien</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='#' class='loadMaze' data-file='scripts/mazes/61x61.js'>Classic Maze I</a>
</div>
<div class='pull-left' style='margin: 0 5px 0 5px;'>|</div>
<div class='pull-left'>
<a href='#' class='loadMaze' data-file='scripts/mazes/201x201.js'>Classic Maze II</a>
</div>
<div style='clear: both;'></div>
</p>
<p>Build your own maze! This app supports query string url parameters! That means, with a little whizbang JSON, you can change the url and provide your very own maze for the algorithm to run through! Cool?</p>
<p>Examine the urls of the above example mazes to see how it works. Read below for the details.</p>
<p>Edit the url and append a string similar to the following:
<br/>
<span class='text-success'>
?maze={"start": {"x": 1, "y": 0}, "end": {"x": 3, "y": 0}, "width": 5, "height": 6, "map": "*.*.**.*.**.*.**...******"}
</span>
</p>
<table class="table table-condensed">
<thead>
<tr>
<th style='width:80px;'>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>start (x, y)</td>
<td>Starting x,y coordinate to begin traversing the map</td>
</tr>
<tr>
<td>end (x, y)</td>
<td>Exit x,y coordinate to indicate when you have exited the map</td>
</tr>
<tr>
<td>width</td>
<td>Width of the map (dependent on the height). For example: *** equals a width of 3</td>
</tr>
<tr>
<td>height</td>
<td>Height of the map (dependent on the width). For example: **.*** with a width of 3, has a height of 2</td>
</tr>
<tr>
<td>map</td>
<td>Content of the maze. Use an asterik * to denote a wall. Use any other character to denote a walkable tile.</td>
</tr>
</tbody>
</table>
<div id='jsonExample' class='bs-docs-example'>
<p><em>Remove all linebreaks from the map when sending in url</em></p>
<pre>
{"start": {"x": 3, "y": 0},
"end": {"x": 6, "y": 0},
"width": 20,
"height": 10,
"map": "
***.**.*************
***....*************
**..****.........***
*..****..*******.***
*.****..********...*
*.****.***********.*
*.****........***..*
*.**************..**
*................***
********************"}
</pre>
</div>
</div>
</div>
<div id='canvasStatus'></div>
<div id='canvasDiv' style='float: left;'>
<canvas id='imageView'>
<p>No HTML5? Seriously?</p>
</canvas>
</div>
<div style='clear: both;'></div>
<div style='margin: 25px 0 0 0;'>
<div class='pull-left'>
<button id='btnGo' class='btn btn-primary btn-large'>Go!</button>
</div>
<div class='pull-left' style='margin:7px 0 0 25px;'>
<div class="btn-group" data-toggle-name="algorithmType" data-toggle="buttons-radio">
<button type="button" value="scripts/tremauxAlgorithm.js" class="btn active" data-toggle="button">Tremaux Algorithm</button>
<button type="button" value="scripts/aStarAlgorithm.js" class="btn" data-toggle="button">A* Search</button>
</div>
<input type="hidden" id="algorithmType" name="algorithmType" value="scripts/tremauxAlgorithm.js" />
</div>
</div>
<div style='clear: both;'></div>
<div id='footer' style='margin: 25px 0 0 0; padding: 6px 0 0 0; border-top: 1px solid #a0a0a0;'>
<p class='muted'>
Created by <a href='http://www.primaryobjects.com/kory-becker.aspx' target='_blank' rel='author'>Kory Becker</a> 2013
<br/>
Source code @ <a href='http://www.github.com/primaryobjects/maze' target='_blank'>GitHub</a>
</p>
</div>
<div id='comments' style='margin: 10px 0 0 0;'>
<div id="disqus_thread"></div>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
</div>
<script type='text/javascript' src='scripts/tremauxAlgorithm.js'></script>
<script type='text/javascript' src='scripts/walker.js'></script>
<script type='text/javascript' src='scripts/maze.js'></script>
<script type='text/javascript' src='scripts/controller.js'></script>
<script type='text/javascript' src='scripts/mazes/big.js'></script>
<script type='text/javascript' src='scripts/commonManager.js'></script>
<script type='text/javascript' src='scripts/init.js'></script>
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=surfer6"></script>
<script type="text/javascript">
var disqus_shortname = 'primaryobjects';
var disqus_identifier = 'maze';
var disqus_url = 'http://www.primaryobjects.com/maze';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</body>
</html>