diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2011-11-15 00:17:46 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2011-11-15 00:17:46 -0800 |
commit | 147d60865d5fdbd9a867c645c6bbde4c1256a93f (patch) | |
tree | 7961a92dddbb32e057ce4e64179c720ddbbe9b97 | |
parent | ef017f8eae478270a925e0fc264f8a1982bad14e (diff) | |
download | pathery-147d60865d5fdbd9a867c645c6bbde4c1256a93f.tar.xz |
Tutorial, Map Position:'s, Solver.
-rw-r--r-- | includes/maps.php | 44 | ||||
-rw-r--r-- | pages/gallery.php | 315 | ||||
-rw-r--r-- | pages/tutorial.php | 55 |
3 files changed, 367 insertions, 47 deletions
diff --git a/includes/maps.php b/includes/maps.php index ef1d6e0..1c51f6d 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -28,45 +28,43 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) $maptable .= "<tr>";
for($j = 0; $j < count($mapMatrix[$i]); $j++)
{
- //==
- $index++;
$handle = "$idprefix,$i,$j";
switch($mapMatrix[$i][$j])
{
- case 's': $maptable .= "<td class='grid_td_start' id='$handle' ></td>"; break;
- case 'f': $maptable .= "<td class='grid_td_finish' id='$handle' ></td>"; break;
+ case 's': $maptable .= "<td title='Start tile. Position: $i,$j' class='grid_td_start' id='$handle' ></td>"; break;
+ case 'f': $maptable .= "<td title='Finish tile. Position: $i,$j' class='grid_td_finish' id='$handle' ></td>"; break;
//TP1
- case 't': $maptable .= "<td title='Teleport 1 in' class='grid_td_tp1_in' id='$handle' ></td>"; break;
- case 'u': $maptable .= "<td title='Teleport 1 out' class='grid_td_tp1_out' id='$handle' ></td>"; break;
+ case 't': $maptable .= "<td title='Teleport 1 in. Position: $i,$j' class='grid_td_tp1_in' id='$handle' ></td>"; break;
+ case 'u': $maptable .= "<td title='Teleport 1 out. Position: $i,$j' class='grid_td_tp1_out' id='$handle' ></td>"; break;
//TP2
- case 'm': $maptable .= "<td title='Teleport 2 in' class='grid_td_tp2_in' id='$handle' ></td>"; break;
- case 'n': $maptable .= "<td title='Teleport 2 out'class='grid_td_tp2_out' id='$handle' ></td>"; break;
+ case 'm': $maptable .= "<td title='Teleport 2 in. Position: $i,$j' class='grid_td_tp2_in' id='$handle' ></td>"; break;
+ case 'n': $maptable .= "<td title='Teleport 2 out. Position: $i,$j'class='grid_td_tp2_out' id='$handle' ></td>"; break;
//TP3
- case 'g': $maptable .= "<td title='Teleport 3 in' class='grid_td_tp3_in' id='$handle' ></td>"; break;
- case 'h': $maptable .= "<td title='Teleport 3 out'class='grid_td_tp3_out' id='$handle' ></td>"; break;
+ case 'g': $maptable .= "<td title='Teleport 3 in. Position: $i,$j' class='grid_td_tp3_in' id='$handle' ></td>"; break;
+ case 'h': $maptable .= "<td title='Teleport 3 out. Position: $i,$j'class='grid_td_tp3_out' id='$handle' ></td>"; break;
//TP4
- case 'i': $maptable .= "<td title='Teleport 4 in' class='grid_td_tp4_in' id='$handle' ></td>"; break;
- case 'j': $maptable .= "<td title='Teleport 4 out'class='grid_td_tp4_out' id='$handle' ></td>"; break;
+ case 'i': $maptable .= "<td title='Teleport 4 in. Position: $i,$j' class='grid_td_tp4_in' id='$handle' ></td>"; break;
+ case 'j': $maptable .= "<td title='Teleport 4 out. Position: $i,$j'class='grid_td_tp4_out' id='$handle' ></td>"; break;
//TP5
- case 'k': $maptable .= "<td title='Teleport 5 in' class='grid_td_tp5_in' id='$handle' ></td>"; break;
- case 'l': $maptable .= "<td title='Teleport 5 out'class='grid_td_tp5_out' id='$handle' ></td>"; break;
+ case 'k': $maptable .= "<td title='Teleport 5 in. Position: $i,$j' class='grid_td_tp5_in' id='$handle' ></td>"; break;
+ case 'l': $maptable .= "<td title='Teleport 5 out. Position: $i,$j'class='grid_td_tp5_out' id='$handle' ></td>"; break;
- case 'a': $maptable .= "<td class='grid_td_cpa' id='$handle' ></td>"; break;
- case 'b': $maptable .= "<td class='grid_td_cpb' id='$handle' ></td>"; break;
- case 'c': $maptable .= "<td class='grid_td_cpc' id='$handle' ></td>"; break;
- case 'd': $maptable .= "<td class='grid_td_cpd' id='$handle' ></td>"; break;
- case 'e': $maptable .= "<td class='grid_td_cpe' id='$handle' ></td>"; break;
-
- case 'r': $maptable .= "<td class='grid_td_rocks' id='$handle' ></td>"; break; //rock
- case 'R': $maptable .= "<td class='grid_td_gray' id='$handle' ></td>"; break; //metalic looking rock
+ case 'a': $maptable .= "<td title='Checkpoint A. Position: $i,$j' class='grid_td_cpa' id='$handle' ></td>"; break;
+ case 'b': $maptable .= "<td title='Checkpoint B. Position: $i,$j' class='grid_td_cpb' id='$handle' ></td>"; break;
+ case 'c': $maptable .= "<td title='Checkpoint C. Position: $i,$j' class='grid_td_cpc' id='$handle' ></td>"; break;
+ case 'd': $maptable .= "<td title='Checkpoint D. Position: $i,$j' class='grid_td_cpd' id='$handle' ></td>"; break;
+ case 'e': $maptable .= "<td title='Checkpoint E. Position: $i,$j' class='grid_td_cpe' id='$handle' ></td>"; break;
+
+ case 'r': $maptable .= "<td title='Rock. Position: $i,$j' class='grid_td_rocks' id='$handle' ></td>"; break; //rock
+ case 'R': $maptable .= "<td title='Silver rock. Position: $i,$j' class='grid_td_gray' id='$handle' ></td>"; break; //metalic looking rock
case 'p': $maptable .= "<td class='grid_td_path' id='$handle' ></td>"; break; //path.
case 'q': $maptable .= "<td class='grid_td_blanks' id='$handle' ></td>"; break; //transparent
case 'w': $maptable .= "<td class='grid_td_walls' id='$handle' name='true' onClick='grid_click(this)' ></td>"; break; //wall
- //default: $maptable .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$index."</td>";
+ // default; normally 'o'.
default: $maptable .= "<td title='Position: $i,$j' class='grid_td' id='$handle' onClick='grid_click(this)' ></td>";
//default: $maptable .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$mapMatrix[$i][$j]."</td>";
}
diff --git a/pages/gallery.php b/pages/gallery.php index 259ac2a..4bcdc05 100644 --- a/pages/gallery.php +++ b/pages/gallery.php @@ -1,26 +1,15 @@ <?PHP -htmlHeader(); +set_time_limit(45); +htmlHeader(array()); ?> <body> <?php topbar($Links); - include('../mazetd/includes/maps.php'); include('../mazetd/includes/mapoftheday.php'); - -echo "<br />"; -echo "<br />"; -echo ""; - -echo rand(0,1); -echo rand(0,1); -echo rand(0,1); -echo rand(0,1); -echo rand(0,1); - //15x9.c3.r28.w12.t2.:0s.8r.4f.0s.9r.3f.0s.12r.0f.0s.8r.0r.3f.0s.5r.5r.1f.0s.1r.11f.0s.0r.8r.1r.1f.0s.8r.4f.0s.4r.3r.4f. $map = GenerateMap( @@ -128,6 +117,306 @@ $a[1] = 't'; $a['1'] = 'hi'; echo $a[1]; + + +$myshape[] = "qqqqqfffffqqqqq"; +$myshape[] = "qqqqq?????qqqqq"; +$myshape[] = "qqooo??b??oooqq"; +$myshape[] = "qqoRR?????RRoqq"; +$myshape[] = "qqoRR?????RRoqq"; +$myshape[] = "f?????????????f"; +$myshape[] = "f?????????????f"; +$myshape[] = "f?a????s????c?f"; +$myshape[] = "f?????????????f"; +$myshape[] = "f?p???????????f"; +$myshape[] = "qqpRR?????RRoqq"; +$myshape[] = "qqpRR?????RRoqq"; +$myshape[] = "qqpppp?d??oooqq"; +$myshape[] = "qqqqq?????qqqqq"; +$myshape[] = "qqqqqfffffqqqqq"; + +$basic[] = "soooooooootoof"; +$basic[] = "soooooooooooof"; +$basic[] = "soooooooooooof"; +$basic[] = "soobooooroooof"; +$basic[] = "sooroooooaooof"; +$basic[] = "srorooooorroof"; +$basic[] = "soooooooorooof"; +$basic[] = "soooooocodooof"; +$basic[] = "soorooorroooof"; +$basic[] = "soooeoooooooof"; +$basic[] = "suooooooooooof"; + + +$basic2[] = "soooooooorotof"; +$basic2[] = "soooooooodooof"; +$basic2[] = "soorooooooooof"; +$basic2[] = "soooooooooooof"; +$basic2[] = "soooaoooooooof"; +$basic2[] = "suocooooooobof"; + + +$basic3[] = "soooooooooof"; +$basic3[] = "soooooooooof"; +$basic3[] = "sooooaooooof"; +$basic3[] = "soooooooooof"; +$basic3[] = "soooooooooof"; + + +$myparams['checkpoints'] = 1; +$myparams['teleports'] = 0; +$myparams['rockchance'] = 100; +$myparams['walls'] = 10; +//$map = GenerateShapedMap($basic3, $myparams); + +$motd = MapOfTheDay(2); +$map = $motd['map']; + + +//Benchmark +$time_start = microtime(true); + + +$newmap = executeTryMaze($map); +echo DisplayMap($newmap, 2); + + +$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) { + //Determin starting location. + $start = explode(",", $route['start']); + $x=$start[0]; + $y=$start[1]; + + //Run through the path + $pathary = str_split($route['path']); + foreach ($pathary as $position => $char) { + switch($char) { + case 1: $y--; break; //up + case 2: $x++; break; //right + case 3: $y++; break; //down + case 4: $x--; break; //left + default: continue 2; + } + //add the positions + $effected["$y,$x"]++; + } + //arsort($effected); + return $effected; +} +// http://awesomescreenshot.com/0d7nyx9b2 + +function executeTryMaze($mapMatrix, $intensity = 1) { + $mapdata['height'] = $mapMatrix[0][0]; + $mapdata['width'] = $mapMatrix[0][1]; + $mapdata['points'] = $mapMatrix[0][2]; + $mapdata['rocks'] = $mapMatrix[0][3]; + $mapdata['walls'] = $mapMatrix[0][4]; + //Override hack. + //$mapdata['walls'] = 12; + $mapdata['teleports'] = $mapMatrix[0][5]; + + + //PROCSES BEGIN + $wallcount = 0; + $iterations = 0; + $lastRefresh = 0; + do { + $iterations++; + $done = false; + $path = routePath($mapMatrix); + $effected = getEffected($path); + + $curcount = 1000; + $bestmoves = $path['moves'] - 1; + + foreach ($effected as $position => $count) { + //Find location + $loc = explode(",", $position); + $x=$loc[0]; + $y=$loc[1]; + //Is it open? + if ($mapMatrix[$x][$y] != "o") { + continue; + } + + + //Set a wall and calculate the new path + $mapMatrix[$x][$y] = 'R'; + $curpath = routePath($mapMatrix); + $trymoves = $curpath['moves']; + + //echo "T($x,$y)\n:"; + + //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); + + //Get location of wall to remove. + $nwallposition = key($walllist); + + echo "*$nwallposition vs $x,$y*\n"; + + $nloc = explode(",", $nwallposition); + $x=$nloc[0]; + $y=$nloc[1]; + //Remove that wall instead. + $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) { + $bestmoves = $trymoves; + $bestx = $x; + $besty = $y; + $mapMatrix[$x][$y] = 'o'; + break; + } + $mapMatrix[$x][$y] = 'o'; + } + //Place the wall in the best spot we found; + $arrayWalls[$bestx][$besty] = true; + echo $mapMatrix[$bestx][$besty]; + $mapMatrix[$bestx][$besty] = 'R'; + $wallcount++; + echo "B($bestx,$besty)\n:"; + + //Refresh walls (Remove obsolete walls) + if ($iterations % 4 == 0 AND $wallcount > ($mapdata['walls'] * .6)) + { + echo "RW"; + $walllist = wallvalues($mapMatrix, $arrayWalls); + //Remove low valued wall; + $lowvaluewall = true; + $nullwalls = 0; + foreach ($walllist as $nwallposition => $wallvalue) { + if ($wallvalue == 0 OR ($lowvaluewall == true AND $wallvalue == 1)) + { + $nloc = explode(",", $nwallposition); + $x=$nloc[0]; + $y=$nloc[1]; + $mapMatrix[$x][$y] = 'o'; + unset($arrayWalls[$x][$y]); + $wallcount--; + + $nullwalls++; + if ($nullwalls >= 2) { + break; + } + if ($lowvaluewall == true AND $wallvalue == 1) { + $lowvaluewall = false; + } + } + } + } + + //Refresh walls if we hit the wall count limit, once. + if($wallcount >= $mapdata['walls'] && $lastRefresh == 0) + { + $lastRefresh = 1; + $walllist = wallvalue($mapMatrix, "R"); + foreach ($walllist as $nwallposition => $wallvalue) { + if ($wallvalue <= 1) { + $nloc = explode(",", $nwallposition); + $i=$nloc[0]; + $j=$nloc[1]; + $mapMatrix[$i][$j] = 'o'; + $wallcount--; + } + } + echo "End Refresh walls to:[$wallcount]"; + } + + //If all walls are placed even after refresh, we're done + if ($wallcount >= $mapdata['walls']) { + echo "END;($wallcount)"; + break; + } + } while ($done == false); + + echo "print"; + print_r(wallvalue($mapMatrix, "R")); + echo "endprint"; + return $mapMatrix; +} + + +//Returns the essential 'move value' of individual walls in an array. +function wallValues($mapMatrix, $arrayWalls) { + $curpath = routePath($mapMatrix); + $curmoves = $curpath['moves']; + //Prepare to return an array. + $r = Array(); + foreach ($arrayWalls as $x => $a) { + foreach ($a as $y => $v) { + //echo "{O".$mapMatrix[$x][$y]."O}"; + if ($mapMatrix[$x][$y] <> 'R') { + continue; + } + //Imagine the maze without the wall. + $mapMatrix[$x][$y] = 'o'; + $newpath = routePath($mapMatrix); + $newmoves = $newpath['moves']; + //Great; so the value of that wall is: + $r["$x,$y"] = $curmoves - $newmoves; + //Okay, you can have your wall back. + $mapMatrix[$x][$y] = 'R'; + } + } + return $r; +} + + +//Returns the essential 'move value' of a wall. +function wallvalue($mapMatrix, $wall) { + $curpath = routePath($mapMatrix); + $curmoves = $curpath['moves']; + for( $i = 1; $i <= $mapMatrix[0][1]; $i++) { //Number of Rows + for( $j = 0; $j < $mapMatrix[0][0]; $j++) { //Number of Columns + if ($mapMatrix[$i][$j] == $wall) { + $mapMatrix[$i][$j] = 'o'; + $newpath = routePath($mapMatrix); + $mapMatrix[$i][$j] = 'r'; + $newmoves = $newpath['moves']; + + $r["$i,$j"] = $curmoves - $newmoves; + + } + } + } + return $r; +} + + + + + +echo "<br >Path: "; +echo $bla['moves']; +echo "<br >"; $mapdisplay = DisplayMap($map); $code = GenerateMapCode($map); diff --git a/pages/tutorial.php b/pages/tutorial.php index ba8d21b..d7d4b24 100644 --- a/pages/tutorial.php +++ b/pages/tutorial.php @@ -25,10 +25,10 @@ function challengeGo(mapid) { case '2':
if (moves >= 18) {
flashelement('nextbtn', 15, null, 400);
- updateDsp(1, 'instructions', 'Great Job, 18 moves!<br />Lets move on to the next shall we?');
+ updateDsp(1, 'instructions', "Great, that's 18 moves!<br />Lets move on to the next shall we?");
//Unlock next button.
} else {
- updateDsp(1, 'instructions', 'As you can see, the path travels from the Start to A to Finish.<hr />Place 2 walls where it\'s flashing to make the path longer');
+ updateDsp(1, 'instructions', "The goal for this map is 18 moves.<br />Place 2 walls to make the path longer");
var tiles = ["2,3,5","2,4,6"];
markTiles(tiles);
}
@@ -37,10 +37,10 @@ function challengeGo(mapid) { case '3':
if (moves >= 64) {
flashelement('nextbtn', 15, null, 400);
- updateDsp(1, 'instructions', 'I almost confused you! hehe.<br />Next?');
+ updateDsp(1, 'instructions', '<p>I almost confused you! hehe.</p><p>Next?</p>');
//Unlock next button.
} else {
- updateDsp(1, 'instructions', 'The path can travel over the start and end tiles too.<br />');
+ updateDsp(1, 'instructions', '<p>The path can travel over the start and end tiles too.</p><br>');
var tiles = ["3,3,6","3,4,7","3,3,2","3,2,1"];
markTiles(tiles);
}
@@ -73,6 +73,8 @@ function challengeGo(mapid) { }
}
+
+
function markTiles(tiles) {
for(var i in tiles) {
var tmp = tiles[i];
@@ -93,15 +95,45 @@ function challengeWall(mapid) { return;
}
}
- updateDsp(1, 'instructions', 'Excellent; those wall placements look good!<hr />Press Go and see the path it takes')
+ updateDsp(1, 'instructions', 'Excellent; those wall placements look good!<br>Press "Go!" and see the path it takes')
}
-function challengeLoad() {
+function challengeLoad() {}
+
+function challenge() {}
+challenge.prototype.unlock = function(id) {
}
+//var ch = new challenge();
+
+
+
function highlightElement(Eid) {
}
+
+function startChallenge(mapid) {
+ console.log("start challenge", mapid);
+ switch (mapid) {
+ case 1:
+ updateDsp(1, 'instructions', '<p>The point of this game is to create the longest <i>path</i> between the start and the finish.</p><p>Press Go!</p>');
+ flashelement('1,btn', 10, null, 400);
+ break;
+ case 2:
+ updateDsp(1, 'instructions', "<p>Let's start off simple;</p><p>Start by pressing 'Go!' first.</p>");
+ break;
+ case 3:
+ updateDsp(1, 'instructions', "The goal for this map is 64 moves<br />Press 'Go!'");
+ break;
+ case 4:
+ updateDsp(1, 'instructions', "Teleports are traps. See if you can use the teleport to reach 45 moves!<br />Press 'Go!'");
+ break;
+ case 5:
+ updateDsp(1, 'instructions', "Now for a difficult one. The goal for this one is 75 moves.<br />Press 'Go!' for help");
+ break;
+ }
+}
+
function TutorialView(low, high) {
this.low = low;
this.high = high;
@@ -117,6 +149,7 @@ TutorialView.prototype.showTutorial = function(num) { }
var elem = document.getElementById("tut-" + num);
elem.className = elem.className.replace('hidden', '');
+ startChallenge(num);
}
TutorialView.prototype.next = function() {
this.showTutorial(++this.cur);
@@ -227,20 +260,20 @@ $map5 = GenerateShapedMap($challenge5, $myparams); //Display maps.
echo '<div id="tut-1" class="hidden">';
echo DisplayMap($map1, 1, 'puzzle');
-echo '</div><div id="tut-2" class="hidden">Target: 18 moves';
+echo '</div><div id="tut-2" class="hidden">';
echo DisplayMap($map2, 2, 'puzzle');
-echo '</div><div id="tut-3" class="hidden">Target: 64 moves';
+echo '</div><div id="tut-3" class="hidden">';
echo DisplayMap($map3, 3, 'puzzle');
-echo '</div><div id="tut-4" class="hidden">Target: 45 moves';
+echo '</div><div id="tut-4" class="hidden">';
echo DisplayMap($map4, 4, 'puzzle');
-echo '</div><div id="tut-5" class="hidden">Target: 75 moves';
+echo '</div><div id="tut-5" class="hidden">';
echo DisplayMap($map5, 5, 'puzzle');
echo '</div>';
?>
<div class="wrapper">
- <a href="javascript:tv.next()" id="nextbtn" class="next">Next</a>
+ <a href="javascript:tv.next()" id="nextbtn" class="next ">Next</a>
<a href="javascript:tv.prev()" id="prevbtn" class="next hidden">Previous</a>
</div>
</div>
|