summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2011-05-02 22:52:56 -0700
committerPatrick Davison <snapwilliam@gmail.com>2011-05-02 22:52:56 -0700
commitf9333b70547ae514ecc848fb195011a11897ee68 (patch)
tree5ea7abc10c215c2a4ca837f1fa90ebef874b9490
parent6554ac5bcacd25b6062d298a0e0b7ed6982282ba (diff)
downloadpathery-f9333b70547ae514ecc848fb195011a11897ee68.tar.xz
Improved map validation.
-rw-r--r--includes/maps.php40
-rw-r--r--pages/home.php94
2 files changed, 72 insertions, 62 deletions
diff --git a/includes/maps.php b/includes/maps.php
index 8cee2b3..0f6dfd8 100644
--- a/includes/maps.php
+++ b/includes/maps.php
@@ -291,8 +291,8 @@ function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp =
$grid[0][4] = $numBlocks;
$grid[0][5] = count($teleport);
- //Confirm the map isn't broken to start-out.
- $path = routePath($grid);
+ //Validate map
+ $path = routePath($grid, '', true);
//Only repeat if it's blocked.
} while ($path['blocked'] == true);
@@ -367,7 +367,7 @@ function GenerateShapedMap($shape, $params) {
}
//echo "\n";
}
- $path = routePath($mapMatrix);
+ $path = routePath($mapMatrix, '', true);
//echo $path['blocked']."\n";
//Only repeat if it's blocked.
} while ($path['blocked'] == true);
@@ -768,7 +768,7 @@ function GetTile($mapMatrix, $id)
//Routes a path through all checkpoints and teleports, returning an array.
// [path] path-string. [blocked] boolean, [moves] int.
-function routePath($mygrid, $start = '') {
+function routePath($mygrid, $start = '', $validate = false) {
//Locate the start locations.
$start = findTiles($mygrid, "s");
@@ -776,16 +776,12 @@ function routePath($mygrid, $start = '') {
//Checkpoint names
$cpnames = Array("a", "b", "c", "d", "e");
- //Get the amount of checkpoints on this map.
- $cpcount = 0;
+
+ //Add the existing checkpoints to target array.
foreach ($cpnames as $cpt)
if (findTiles($mygrid, $cpt))
- $cpcount++;
+ $target[] = $cpt;
- //Add the existing checkpoints to target array.
- for($p = 0; $p < $cpcount; $p++) {
- $target[] = $cpnames[$p];
- }
//Our last target is the finish line.
$target[] = 'f';
@@ -794,16 +790,6 @@ function routePath($mygrid, $start = '') {
//All possible teleports in play.
$tpnames = Array('t', 'm', 'g', 'i', 'k');
- //Find all the existing teleports.
- $tpcount = 0;
- foreach ($tpnames as $tpt)
- if (findTiles($mygrid, $tpt))
- $tpcount++;
-
- //Save the existing teleports, to check for them later.
- for($p = 0; $p < $tpcount; $p++) {
- $teleport[] = $tpnames[$p];
- }
//Where there's an in, there's an out.
$teleout['t'] = 'u';
@@ -812,6 +798,18 @@ function routePath($mygrid, $start = '') {
$teleout['i'] = 'j';
$teleout['k'] = 'l';
+ //Find all the existing teleports.
+ foreach ($tpnames as $tpt)
+ if (findTiles($mygrid, $tpt))
+ $teleport[] = $tpt;
+
+ //If validate, add teleport in/out's.
+ if ($validate) {
+ $target = array_merge($target, $teleport);
+ foreach ($teleport as $tin)
+ $target[] = $teleout[$tin];
+ }
+
//Loop through all the targets.
foreach($target as $t) {
//Path from where we are, to the target.
diff --git a/pages/home.php b/pages/home.php
index a6d73d6..d905476 100644
--- a/pages/home.php
+++ b/pages/home.php
@@ -11,26 +11,70 @@ include('./includes/mapoftheday.php');
include('./includes/datas.php');
+
+
+//Get the current day as int.
+$numday = date('w');
+$numday = intval($numday);
+switch ($numday) {
+ case 0:
+ $mapstyle = 'Thirty';
+ break;
+ case 1:
+ $mapstyle = 'Simple';
+ break;
+ case 2:
+ $mapstyle = "ABC's";
+ break;
+ case 3:
+ $mapstyle = 'Teleport Madness';
+ break;
+ case 4:
+ $mapstyle = 'Rocky Maze';
+ break;
+ case 5: //Friday
+ $mapstyle = 'Side to Side';
+ break;
+ case 6: //Saturday
+ $mapstyle = "Seeing Double";
+ break;
+}
+
+$normal = 'Normal';
+$easy = 'Simple';
+$hard = 'Complex';
+
+$today = date('l');
+//if ($today == 'Sunday' OR $today == 'Saturday')
+ //$today = 'Weekend Map';
+//else
+ $today .= "'s";
+$special = "$today $mapstyle";
+
switch ($_GET['maptype']) {
case "normal":
case "2":
$maptype = 2;
+ $normal = '<b>Normal</b>';
break;
case "hard":
case "3":
$maptype = 3;
+ $hard = '<b>Complex</b>';
break;
case "day":
case "4":
$maptype = 4;
+ $special = "<b>$special</b>";
break;
case "easy":
case "1":
default:
$maptype = 1;
+ $easy = '<b>Simple</b>';
}
//$motd = getMapOfTheDay();
@@ -58,15 +102,14 @@ $mergesolution = $map;
<br />
<div class="col1">
- <b>I'm testing letting the path go over the START and FINISH tiles.</b>
- <br /> Have an opinion about this? Let me know!
+ <b>Some very exciting changes to be expected April 23rd!</b>
<p>
New maps are generated daily at 9:00 PM Pacific Time.
<br />Maps for <?php echo "$date" ?>:
- <br /><a href='?page=home&amp;maptype=easy'>Simple</a>
- <br /><a href='?page=home&amp;maptype=normal'>Normal</a>
- <br /><a href='?page=home&amp;maptype=hard'>Complex</a>
- <br /><a href='?page=home&amp;maptype=day'>Today's Special</a>
+ <br /><a href='?page=home&amp;maptype=easy'><? echo $easy; ?></a>
+ <br /><a href='?page=home&amp;maptype=normal'><? echo $normal; ?></a>
+ <br /><a href='?page=home&amp;maptype=hard'><? echo $hard; ?></a>
+ <br /><a href='?page=home&amp;maptype=day'><? echo $special; ?></a>
</p>
<? echo $topscorediv; ?>
@@ -85,42 +128,11 @@ if ($_SESSION['accepted'] != 1) {
echo "<br />";
-//Get the current day as int.
-$numday = date('w');
-$numday = intval($numday);
-switch ($numday) {
- case 0:
- $mapstyle = 'Thirty';
- break;
- case 1:
- $mapstyle = 'Simple';
- break;
- case 2:
- $mapstyle = "ABC's";
- break;
- case 3:
- $mapstyle = 'Teleport Madness';
- break;
- case 4:
- $mapstyle = 'Rocky Maze';
- break;
- case 5: //Friday
- $mapstyle = 'Side to Side';
- break;
- case 6: //Saturday
- $mapstyle = "Seeing Double";
- break;
-}
-echo "<br />$date<br /><a href='?page=home&amp;maptype=easy'>Simple</a> | ";
-echo "<a href='?page=home&amp;maptype=normal'>Normal</a> | ";
-echo "<a href='?page=home&amp;maptype=hard'>Complex</a> | ";
-$today = date('l');
-//if ($today == 'Sunday' OR $today == 'Saturday')
- //$today = 'Weekend Map';
-//else
- $today .= "'s";
-echo "<i><b> NEW: </b></i> <a href='?page=home&amp;maptype=day'>$today $mapstyle</a>";
+echo "<br />$date<br /><a href='?page=home&amp;maptype=easy'>$easy</a> | ";
+echo "<a href='?page=home&amp;maptype=normal'>$normal</a> | ";
+echo "<a href='?page=home&amp;maptype=hard'>$hard</a> | ";
+echo "<a href='?page=home&amp;maptype=day'>$special</a>";
echo DisplayMap($mergesolution, $mapID);