<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Step by step perfect maze generation with php</title>
	<atom:link href="http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Sat, 11 Feb 2012 05:27:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Louigi Verona</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-1006769</link>
		<dc:creator>Louigi Verona</dc:creator>
		<pubDate>Sat, 26 Nov 2011 19:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-1006769</guid>
		<description>I did maze generation using a database. Try it out here:

http://www.louigiverona.ru/mw</description>
		<content:encoded><![CDATA[<p>I did maze generation using a database. Try it out here:</p>
<p><a href="http://www.louigiverona.ru/mw" rel="nofollow">http://www.louigiverona.ru/mw</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-941337</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 22 Sep 2011 12:53:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-941337</guid>
		<description>Hello,
Loved your maze example, I had the same issue as [T Munk] with firefox. Did my own generator a while ago but will improve it using tricks from your example.

Mine was as follows:

&lt;?php

////////////////////////////////////////////////////////////////////////////////////////////

class grid {

	function gen($x,$y) {
		session_start();
		$_SESSION[&#039;grid0&#039;] = 0;
		$current = 1;
		$max = $x * $y;
		while ($current &lt;= $max):
			$_SESSION[&#039;grid&#039;.$current] = 0;
			$_SESSION[&#039;completed&#039;.$current] = 0;
			$current = $current + 1;
		endwhile;
	}
	
	function valid($excludeRef,$ref,$x,$y) {
		
		$result = 0;
		
		// Start and End Of Grid
		$end_result = $ref / $x;
		$start_result = ($ref - 1) / $x;
		
		if(($ref - $x)  ($x * $y)) { $down_ref = 0; }else{ $down_ref = $ref + $x; }
		
		if(strpos($start_result, &#039;.&#039;) == &#039;&#039;) {
			$left_ref = 0;
		}else{
			if(($ref - 1)  ($x * $y)) { $right_ref = 0; }else{ $right_ref = $ref + 1; }
		}
		
		// 0 Out the Exclusion
		if($up_ref == $excludeRef){$up_ref = 0;}
		if($down_ref == $excludeRef){$down_ref = 0;}
		if($left_ref == $excludeRef){$left_ref = 0;}
		if($right_ref == $excludeRef){$right_ref = 0;}
				
		// Gen Result
		if($_SESSION[&#039;grid&#039;.$ref] == 0 AND $_SESSION[&#039;grid&#039;.$up_ref] == 0 AND $_SESSION[&#039;grid&#039;.$down_ref] == 0 AND $_SESSION[&#039;grid&#039;.$left_ref] == 0 AND $_SESSION[&#039;grid&#039;.$right_ref] == 0  ) {
			$result = $ref;
		}
		
		return $result;
		
	}

}
////////////////////////////////////////////////////////////////////////////////////////////

class maze {

	function fill($ref) {
	
		$_SESSION[&#039;grid&#039;.$ref] = 1;
	
	}
	
	function setstart($ref) {
	
		$_SESSION[&#039;grid&#039;.$ref] = 2;
	
	}
	
	function setend($ref) {
	
		$_SESSION[&#039;grid&#039;.$ref] = 3;
	
	}
	
	function comp($ref) {
	
		$_SESSION[&#039;completed&#039;.$ref] = 1;
	
	}
	
	function gen($start_ref,$x,$y) {
		
		$grid = new grid;
		$maze = new maze;
		
		$grid-&gt;gen($x,$y);
		$loop_create = 1;
		$ref = $start_ref;
		$path = $start_ref;
		$maze-&gt;setstart($ref);
		
		while($loop_create &gt; 0):
			
			// Start and End Of Grid
			$end_result = $ref / $x;
			$start_result = ($ref - 1) / $x;
			
			// Gen Next Refs
			if(($ref - $x) valid($ref,($ref - $x),$x,$y); }
			if(($ref + $x) &gt; ($x * $y)) { $down_ref = 0; }else{ $down_ref = $grid-&gt;valid($ref,($ref + $x),$x,$y); }
			
			if(strpos($start_result, &#039;.&#039;) == &#039;&#039;) {
				$left_ref = 0;
			}else{
				if(($ref - 1) valid($ref,($ref - 1),$x,$y); }
			}
			
			if(strpos($end_result, &#039;.&#039;) == &#039;&#039;) {
				$right_ref = 0;
			}else{
				if(($ref + 1) &gt; ($x * $y)) { $right_ref = 0; }else{ $right_ref = $grid-&gt;valid($ref,($ref + 1),$x,$y); }
			}
			
			// All Done for This Path?
			$path_open = $up_ref + $down_ref + $left_ref + $right_ref;
			if($path_open == 0) {
			
				// Mark Cell; Finished
				$maze-&gt;comp($ref);
				
				// Try and Find Another
				$find_cell_current = 1;
				$find_cell_max = $x * $y;
				$last_cell = $ref;
				
				while($find_cell_current  0):
				
					$rand = rand(1,4);
					
					if($rand ==1){$next_cell=$up_ref;}
					if($rand ==2){$next_cell=$down_ref;}
					if($rand ==3){$next_cell=$left_ref;}
					if($rand ==4){$next_cell=$right_ref;}
					
					if($next_cell &gt; 0){
						$maze-&gt;fill($next_cell);
						$loop_rand = 0;
						$ref = $next_cell;
						$path = $path . &quot;-&quot; . $next_cell;
					}

				endwhile;
			
			}
			
		endwhile;
		
		// Choose an end point
		
		
		
		//Draw
			
		$maze-&gt;draw($x,$y);
	
	}
	
	
	function draw($x,$y) {
	
		$current = 1;
		$row = 1;
		$max = $x * $y;
		
		echo &quot;&quot;;
		
		while ($current &lt;= $max):
			$value = $_SESSION[&#039;grid&#039;.$current];
			if($value == 0){ echo &quot;&quot;; }
			if($value == 1){ echo &quot;&quot;; }
			if($value == 2){ echo &quot;&quot;; }
			if($value == 3){ echo &quot;&quot;; }
			if($row == $x){ echo &quot;&quot;; $row = 0;}
			$current = $current + 1;
			$row = $row + 1;
		endwhile;
		
		echo &quot;&quot;;
		echo &quot;&quot;;
		
		$current = 1;
		$row = 1;
		$max = $x * $y;
		
		echo &quot;&quot;;
		
		while ($current &lt;= $max):
			$value = $_SESSION[&#039;grid&#039;.$current];
			if($value == 0){ echo 0; }
			if($value == 1){ echo 1; }
			if($value == 2){ echo 2; }
			if($value == 3){ echo 3; }
			if($row == $x){ echo &#039;&#039;; $row = 0;}
			$current = $current + 1;
			$row = $row + 1;
		endwhile;
		
		echo &quot;&quot;;
		echo &quot;&quot;;
	
	}

}

////////////////////////////////////////////////////////////////////////////////////////////

$maze = new maze;

////////////////////////////////////////////////////////////////////////////////////////////

$x = 40;
$y = 30;

////////////////////////////////////////////////////////////////////////////////////////////
?&gt;
Marks Maze Bullshit


  .contain {
	border-width:2px;
	border-color:black;
	border-style:solid;
	display:block;
	float:left;
  }
  .clear {
	clear:both;
  }
  .black {
    color: black;
    background-color: black; 
	width:20px;
	height:20px;
	display:block;
	float:left;
	}
	.white {
    color: white;
    background-color: white; 
	width:20px;
	height:20px;
	display:block;
	float:left;
	}
	.green {
    color: green;
    background-color: green; 
	width:20px;
	height:20px;
	display:block;
	float:left;
	}
	.red {
    color: red;
    background-color: red; 
	width:20px;
	height:20px;
	display:block;
	float:left;
	}
  




Your Random Mark Maze! 

gen(1,$x,$y);
?&gt;




&lt;a href=&quot;index.php&quot; rel=&quot;nofollow&quot;&gt;Refresh&lt;/a&gt; 

</description>
		<content:encoded><![CDATA[<p>Hello,<br />
Loved your maze example, I had the same issue as [T Munk] with firefox. Did my own generator a while ago but will improve it using tricks from your example.</p>
<p>Mine was as follows:</p>
<p>&lt;?php</p>
<p>////////////////////////////////////////////////////////////////////////////////////////////</p>
<p>class grid {</p>
<p>	function gen($x,$y) {<br />
		session_start();<br />
		$_SESSION[&#039;grid0&#039;] = 0;<br />
		$current = 1;<br />
		$max = $x * $y;<br />
		while ($current &lt;= $max):<br />
			$_SESSION[&#039;grid&#039;.$current] = 0;<br />
			$_SESSION[&#039;completed&#039;.$current] = 0;<br />
			$current = $current + 1;<br />
		endwhile;<br />
	}</p>
<p>	function valid($excludeRef,$ref,$x,$y) {</p>
<p>		$result = 0;</p>
<p>		// Start and End Of Grid<br />
		$end_result = $ref / $x;<br />
		$start_result = ($ref &#8211; 1) / $x;</p>
<p>		if(($ref &#8211; $x)  ($x * $y)) { $down_ref = 0; }else{ $down_ref = $ref + $x; }</p>
<p>		if(strpos($start_result, &#8216;.&#8217;) == &#8221;) {<br />
			$left_ref = 0;<br />
		}else{<br />
			if(($ref &#8211; 1)  ($x * $y)) { $right_ref = 0; }else{ $right_ref = $ref + 1; }<br />
		}</p>
<p>		// 0 Out the Exclusion<br />
		if($up_ref == $excludeRef){$up_ref = 0;}<br />
		if($down_ref == $excludeRef){$down_ref = 0;}<br />
		if($left_ref == $excludeRef){$left_ref = 0;}<br />
		if($right_ref == $excludeRef){$right_ref = 0;}</p>
<p>		// Gen Result<br />
		if($_SESSION['grid'.$ref] == 0 AND $_SESSION['grid'.$up_ref] == 0 AND $_SESSION['grid'.$down_ref] == 0 AND $_SESSION['grid'.$left_ref] == 0 AND $_SESSION['grid'.$right_ref] == 0  ) {<br />
			$result = $ref;<br />
		}</p>
<p>		return $result;</p>
<p>	}</p>
<p>}<br />
////////////////////////////////////////////////////////////////////////////////////////////</p>
<p>class maze {</p>
<p>	function fill($ref) {</p>
<p>		$_SESSION['grid'.$ref] = 1;</p>
<p>	}</p>
<p>	function setstart($ref) {</p>
<p>		$_SESSION['grid'.$ref] = 2;</p>
<p>	}</p>
<p>	function setend($ref) {</p>
<p>		$_SESSION['grid'.$ref] = 3;</p>
<p>	}</p>
<p>	function comp($ref) {</p>
<p>		$_SESSION['completed'.$ref] = 1;</p>
<p>	}</p>
<p>	function gen($start_ref,$x,$y) {</p>
<p>		$grid = new grid;<br />
		$maze = new maze;</p>
<p>		$grid-&gt;gen($x,$y);<br />
		$loop_create = 1;<br />
		$ref = $start_ref;<br />
		$path = $start_ref;<br />
		$maze-&gt;setstart($ref);</p>
<p>		while($loop_create &gt; 0):</p>
<p>			// Start and End Of Grid<br />
			$end_result = $ref / $x;<br />
			$start_result = ($ref &#8211; 1) / $x;</p>
<p>			// Gen Next Refs<br />
			if(($ref &#8211; $x) valid($ref,($ref &#8211; $x),$x,$y); }<br />
			if(($ref + $x) &gt; ($x * $y)) { $down_ref = 0; }else{ $down_ref = $grid-&gt;valid($ref,($ref + $x),$x,$y); }</p>
<p>			if(strpos($start_result, &#8216;.&#8217;) == &#8221;) {<br />
				$left_ref = 0;<br />
			}else{<br />
				if(($ref &#8211; 1) valid($ref,($ref &#8211; 1),$x,$y); }<br />
			}</p>
<p>			if(strpos($end_result, &#8216;.&#8217;) == &#8221;) {<br />
				$right_ref = 0;<br />
			}else{<br />
				if(($ref + 1) &gt; ($x * $y)) { $right_ref = 0; }else{ $right_ref = $grid-&gt;valid($ref,($ref + 1),$x,$y); }<br />
			}</p>
<p>			// All Done for This Path?<br />
			$path_open = $up_ref + $down_ref + $left_ref + $right_ref;<br />
			if($path_open == 0) {</p>
<p>				// Mark Cell; Finished<br />
				$maze-&gt;comp($ref);</p>
<p>				// Try and Find Another<br />
				$find_cell_current = 1;<br />
				$find_cell_max = $x * $y;<br />
				$last_cell = $ref;</p>
<p>				while($find_cell_current  0):</p>
<p>					$rand = rand(1,4);</p>
<p>					if($rand ==1){$next_cell=$up_ref;}<br />
					if($rand ==2){$next_cell=$down_ref;}<br />
					if($rand ==3){$next_cell=$left_ref;}<br />
					if($rand ==4){$next_cell=$right_ref;}</p>
<p>					if($next_cell &gt; 0){<br />
						$maze-&gt;fill($next_cell);<br />
						$loop_rand = 0;<br />
						$ref = $next_cell;<br />
						$path = $path . &#8220;-&#8221; . $next_cell;<br />
					}</p>
<p>				endwhile;</p>
<p>			}</p>
<p>		endwhile;</p>
<p>		// Choose an end point</p>
<p>		//Draw</p>
<p>		$maze-&gt;draw($x,$y);</p>
<p>	}</p>
<p>	function draw($x,$y) {</p>
<p>		$current = 1;<br />
		$row = 1;<br />
		$max = $x * $y;</p>
<p>		echo &#8220;&#8221;;</p>
<p>		while ($current &lt;= $max):<br />
			$value = $_SESSION[&#039;grid&#039;.$current];<br />
			if($value == 0){ echo &quot;&#8221;; }<br />
			if($value == 1){ echo &#8220;&#8221;; }<br />
			if($value == 2){ echo &#8220;&#8221;; }<br />
			if($value == 3){ echo &#8220;&#8221;; }<br />
			if($row == $x){ echo &#8220;&#8221;; $row = 0;}<br />
			$current = $current + 1;<br />
			$row = $row + 1;<br />
		endwhile;</p>
<p>		echo &#8220;&#8221;;<br />
		echo &#8220;&#8221;;</p>
<p>		$current = 1;<br />
		$row = 1;<br />
		$max = $x * $y;</p>
<p>		echo &#8220;&#8221;;</p>
<p>		while ($current &lt;= $max):<br />
			$value = $_SESSION[&#039;grid&#039;.$current];<br />
			if($value == 0){ echo 0; }<br />
			if($value == 1){ echo 1; }<br />
			if($value == 2){ echo 2; }<br />
			if($value == 3){ echo 3; }<br />
			if($row == $x){ echo &#039;&#8217;; $row = 0;}<br />
			$current = $current + 1;<br />
			$row = $row + 1;<br />
		endwhile;</p>
<p>		echo &#8220;&#8221;;<br />
		echo &#8220;&#8221;;</p>
<p>	}</p>
<p>}</p>
<p>////////////////////////////////////////////////////////////////////////////////////////////</p>
<p>$maze = new maze;</p>
<p>////////////////////////////////////////////////////////////////////////////////////////////</p>
<p>$x = 40;<br />
$y = 30;</p>
<p>////////////////////////////////////////////////////////////////////////////////////////////<br />
?&gt;<br />
Marks Maze Bullshit</p>
<p>  .contain {<br />
	border-width:2px;<br />
	border-color:black;<br />
	border-style:solid;<br />
	display:block;<br />
	float:left;<br />
  }<br />
  .clear {<br />
	clear:both;<br />
  }<br />
  .black {<br />
    color: black;<br />
    background-color: black;<br />
	width:20px;<br />
	height:20px;<br />
	display:block;<br />
	float:left;<br />
	}<br />
	.white {<br />
    color: white;<br />
    background-color: white;<br />
	width:20px;<br />
	height:20px;<br />
	display:block;<br />
	float:left;<br />
	}<br />
	.green {<br />
    color: green;<br />
    background-color: green;<br />
	width:20px;<br />
	height:20px;<br />
	display:block;<br />
	float:left;<br />
	}<br />
	.red {<br />
    color: red;<br />
    background-color: red;<br />
	width:20px;<br />
	height:20px;<br />
	display:block;<br />
	float:left;<br />
	}</p>
<p>Your Random Mark Maze! </p>
<p>gen(1,$x,$y);<br />
?&gt;</p>
<p><a href="index.php" rel="nofollow">Refresh</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darty</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-487336</link>
		<dc:creator>Darty</dc:creator>
		<pubDate>Wed, 19 Aug 2009 01:46:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-487336</guid>
		<description>Nice tutorial, takes me back to my second year of university where we had to do the exact same thing in c++</description>
		<content:encoded><![CDATA[<p>Nice tutorial, takes me back to my second year of university where we had to do the exact same thing in c++</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Perfect maze generation with AS3 : Emanuele Feronato</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-344952</link>
		<dc:creator>Perfect maze generation with AS3 : Emanuele Feronato</dc:creator>
		<pubDate>Fri, 28 Nov 2008 14:38:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-344952</guid>
		<description>[...] already talked about perfect mazes a couple of years ago with Step by step perfect maze generation with php and Perfect maze generation with Flash actionscript, but now it&#039;s time to make it with AS3 and [...]</description>
		<content:encoded><![CDATA[<p>[...] already talked about perfect mazes a couple of years ago with Step by step perfect maze generation with php and Perfect maze generation with Flash actionscript, but now it&#8217;s time to make it with AS3 and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jahn</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-2967</link>
		<dc:creator>Jahn</dc:creator>
		<pubDate>Sun, 28 Jan 2007 00:43:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-2967</guid>
		<description>$maze is the variable.
[$pos] is the area of the array
{2} designates one character versus the whole string at postition 2.</description>
		<content:encoded><![CDATA[<p>$maze is the variable.<br />
[$pos] is the area of the array<br />
{2} designates one character versus the whole string at postition 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-368</link>
		<dc:creator>Leo</dc:creator>
		<pubDate>Thu, 02 Nov 2006 16:18:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-368</guid>
		<description>Hey... im not a expert in PHP, but i wanna ask:

Whats does $maze[$pos]{0} = 1; do?
and $maze[$pos]{2} = 0;?
and $maze[$pos+1]{4} = 0;?
etc...

i dont catch those lines!

please, help!</description>
		<content:encoded><![CDATA[<p>Hey&#8230; im not a expert in PHP, but i wanna ask:</p>
<p>Whats does $maze[$pos]{0} = 1; do?<br />
and $maze[$pos]{2} = 0;?<br />
and $maze[$pos+1]{4} = 0;?<br />
etc&#8230;</p>
<p>i dont catch those lines!</p>
<p>please, help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T Munk</title>
		<link>http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-52</link>
		<dc:creator>T Munk</dc:creator>
		<pubDate>Fri, 01 Sep 2006 19:10:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/08/20/step-by-step-perfect-maze-generation-with-php/#comment-52</guid>
		<description>Excellent bit of work! I was looking for something to randomly generate a dungeon for each user for one of the quests in my game, and your code turns out to be a really nice jumping-off point. (:

Note: firefox doesn&#039;t like class names that start with a number in stylesheets, and thus doesn&#039;t render your pretty maze correctly. You can fix this in your code by adding a letter to the class name:

Line 78: 
Line 81: 
Line 98: .c00{width:50px;
ditto with line 99,100,101.

Thanks!</description>
		<content:encoded><![CDATA[<p>Excellent bit of work! I was looking for something to randomly generate a dungeon for each user for one of the quests in my game, and your code turns out to be a really nice jumping-off point. (:</p>
<p>Note: firefox doesn&#8217;t like class names that start with a number in stylesheets, and thus doesn&#8217;t render your pretty maze correctly. You can fix this in your code by adding a letter to the class name:</p>
<p>Line 78:<br />
Line 81:<br />
Line 98: .c00{width:50px;<br />
ditto with line 99,100,101.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 5/11 queries in 0.094 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-11 12:55:14 -->
