diff options
Diffstat (limited to 'pages/gallery.php')
-rw-r--r-- | pages/gallery.php | 143 |
1 files changed, 98 insertions, 45 deletions
diff --git a/pages/gallery.php b/pages/gallery.php index 4bcdc05..8468365 100644 --- a/pages/gallery.php +++ b/pages/gallery.php @@ -1,5 +1,4 @@ <?PHP -set_time_limit(45); htmlHeader(array()); ?> @@ -166,17 +165,21 @@ $basic3[] = "soooooooooof"; $myparams['checkpoints'] = 1; $myparams['teleports'] = 0; $myparams['rockchance'] = 100; -$myparams['walls'] = 10; -//$map = GenerateShapedMap($basic3, $myparams); +$myparams['walls'] = 3; -$motd = MapOfTheDay(2); +$map = GenerateShapedMap($basic3, $myparams); + +$motd = MapOfTheDay(4); $map = $motd['map']; +if ($_GET['walls']) { + $map[0][4] = ($_GET['walls'] * 1); +} //Benchmark $time_start = microtime(true); - +set_time_limit(1120); $newmap = executeTryMaze($map); echo DisplayMap($newmap, 2); @@ -185,8 +188,8 @@ $time_end = microtime(true); $time = round($time_end - $time_start, 4); echo "<br />Solution created in $time seconds\n<br />"; -//Return an array of effected tiles. -function getEffected($route) { +//Return an array of affected tiles. +function getAffected($route) { //Determin starting location. $start = explode(",", $route['start']); $x=$start[0]; @@ -194,7 +197,30 @@ function getEffected($route) { //Run through the path $pathary = str_split($route['path']); + //echo "path:".$route['path']; foreach ($pathary as $position => $char) { + + switch($char) { + case 'u': //tp1 + case 'n': //tp2 + case 'h': //tp3 + case 'j': //tp4 + case 'l': //tp5 + if ($tog == true) { + $tog = false; + continue; + } + $tog = true; + //Get teleport coords + $tmp = split($char, $route['path']); + $loc = split(',', $tmp[1]); + $x = $loc[0]; + $y = $loc[1]; + //echo "....$x,$y...."; + } + if ($tog == true) + continue; + switch($char) { case 1: $y--; break; //up case 2: $x++; break; //right @@ -203,10 +229,10 @@ function getEffected($route) { default: continue 2; } //add the positions - $effected["$y,$x"]++; + $affected["$y,$x"]++; } - //arsort($effected); - return $effected; + //arsort($affected); + return $affected; } // http://awesomescreenshot.com/0d7nyx9b2 @@ -221,6 +247,8 @@ function executeTryMaze($mapMatrix, $intensity = 1) { $mapdata['teleports'] = $mapMatrix[0][5]; + $routes = 0; + //PROCSES BEGIN $wallcount = 0; $iterations = 0; @@ -229,12 +257,14 @@ function executeTryMaze($mapMatrix, $intensity = 1) { $iterations++; $done = false; $path = routePath($mapMatrix); - $effected = getEffected($path); + $routes++; + $affected = getAffected($path); $curcount = 1000; - $bestmoves = $path['moves'] - 1; + $bestmoves = 0; + $bestcount = 0; - foreach ($effected as $position => $count) { + foreach ($affected as $position => $count) { //Find location $loc = explode(",", $position); $x=$loc[0]; @@ -248,52 +278,66 @@ function executeTryMaze($mapMatrix, $intensity = 1) { //Set a wall and calculate the new path $mapMatrix[$x][$y] = 'R'; $curpath = routePath($mapMatrix); + $routes++; $trymoves = $curpath['moves']; - //echo "T($x,$y)\n:"; - + //if ("$x,$y" == "3,17") { + //echo "T($x,$y)\n:"; + //print_r($affected); + //return; + //} //path blocked? if ($curpath['blocked'] == true) { //Sometimes it's better to remove a different wall; //Put a wall here. - $arrayWalls[$x][$y] = true; - - //determin wall values. - $walllist = wallvalues($mapMatrix, $arrayWalls); - - //Put the best wall to remove on top; - A mono directional bubble sort would be better here. - $walllist["$x,$y"]++; - asort($walllist); + //if ($iterations % 8 == 4) { + if (1 == 12) { + $arrayWalls[$x][$y] = true; + + //determin wall values. + $walllist = wallvalues($mapMatrix, $arrayWalls); + $routes++; + + //Put the best wall to remove on top; - A mono directional bubble sort would be better here. + $walllist["$x,$y"]--; + asort($walllist); - //Get location of wall to remove. - $nwallposition = key($walllist); + //Get location of wall to remove. + $nwallposition = key($walllist); - echo "*$nwallposition vs $x,$y*\n"; + echo "*$nwallposition vs $x,$y*\n"; - $nloc = explode(",", $nwallposition); - $x=$nloc[0]; - $y=$nloc[1]; - //Remove that wall instead. + $nloc = explode(",", $nwallposition); + $bx=$nloc[0]; + $by=$nloc[1]; + + + $mapMatrix[$bx][$by] = 'R'; + $mapMatrix[$x][$y] = 'o'; + // $tmp = routePath($mapMatrix); + // if ($tmp['blocked']) { + // $mapMatrix[$bx][$by] = 'R'; + // $mapMatrix[$x][$y] = 'o'; + // echo "Unblocked"; + // continue; + // } + unset($arrayWalls[$bx][$by]); + continue; + } $mapMatrix[$x][$y] = 'o'; - - //echo "Rem[$x,$y]"; - - //$curpath = routePath($mapMatrix); - //echo $curpath['blocked']; - //echo "]"; - - unset($arrayWalls[$x][$y]); continue; } //The last choice, or first choice? //if ($trymoves >= $bestmoves) { - if ($trymoves >= $bestmoves) { + //echo "[$x, $y: $trymoves]"; + if ($trymoves > $bestmoves OR ($trymoves >= $bestmoves AND $bestcount <= $count) ) { + $bestcount = $count; $bestmoves = $trymoves; $bestx = $x; $besty = $y; $mapMatrix[$x][$y] = 'o'; - break; + //break; } $mapMatrix[$x][$y] = 'o'; } @@ -305,10 +349,11 @@ function executeTryMaze($mapMatrix, $intensity = 1) { echo "B($bestx,$besty)\n:"; //Refresh walls (Remove obsolete walls) - if ($iterations % 4 == 0 AND $wallcount > ($mapdata['walls'] * .6)) + if ($iterations % 2 == 0 AND $wallcount > ($mapdata['walls'] * .6)) { echo "RW"; $walllist = wallvalues($mapMatrix, $arrayWalls); + $routes++; //Remove low valued wall; $lowvaluewall = true; $nullwalls = 0; @@ -318,9 +363,12 @@ function executeTryMaze($mapMatrix, $intensity = 1) { $nloc = explode(",", $nwallposition); $x=$nloc[0]; $y=$nloc[1]; + if ($x == $bestx AND $y == $besty) + continue; $mapMatrix[$x][$y] = 'o'; unset($arrayWalls[$x][$y]); $wallcount--; + echo "RM($x, $y)"; $nullwalls++; if ($nullwalls >= 2) { @@ -338,13 +386,16 @@ function executeTryMaze($mapMatrix, $intensity = 1) { { $lastRefresh = 1; $walllist = wallvalue($mapMatrix, "R"); + $routes++; foreach ($walllist as $nwallposition => $wallvalue) { if ($wallvalue <= 1) { $nloc = explode(",", $nwallposition); $i=$nloc[0]; $j=$nloc[1]; $mapMatrix[$i][$j] = 'o'; + unset($arrayWalls[$x][$y]); $wallcount--; + echo "RM($x, $y)"; } } echo "End Refresh walls to:[$wallcount]"; @@ -352,14 +403,14 @@ function executeTryMaze($mapMatrix, $intensity = 1) { //If all walls are placed even after refresh, we're done if ($wallcount >= $mapdata['walls']) { - echo "END;($wallcount)"; + echo "END;($wallcount) <b>Solution routed the path $routes times.</b>"; break; } } while ($done == false); - echo "print"; - print_r(wallvalue($mapMatrix, "R")); - echo "endprint"; + //echo "print"; + //print_r(wallvalue($mapMatrix, "R")); + //echo "endprint"; return $mapMatrix; } @@ -368,6 +419,8 @@ function executeTryMaze($mapMatrix, $intensity = 1) { function wallValues($mapMatrix, $arrayWalls) { $curpath = routePath($mapMatrix); $curmoves = $curpath['moves']; + if ($curpath['blocked']) + $curmoves = 0; //Prepare to return an array. $r = Array(); foreach ($arrayWalls as $x => $a) { |