From f9333b70547ae514ecc848fb195011a11897ee68 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Mon, 2 May 2011 22:52:56 -0700 Subject: Improved map validation. --- includes/maps.php | 40 +++++++++++------------ pages/home.php | 94 +++++++++++++++++++++++++++++++------------------------ 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 = 'Normal'; break; case "hard": case "3": $maptype = 3; + $hard = 'Complex'; break; case "day": case "4": $maptype = 4; + $special = "$special"; break; case "easy": case "1": default: $maptype = 1; + $easy = 'Simple'; } //$motd = getMapOfTheDay(); @@ -58,15 +102,14 @@ $mergesolution = $map;
- I'm testing letting the path go over the START and FINISH tiles. -
Have an opinion about this? Let me know! + Some very exciting changes to be expected April 23rd!

New maps are generated daily at 9:00 PM Pacific Time.
Maps for : -
Simple -
Normal -
Complex -
Today's Special +
+
+
+

@@ -85,42 +128,11 @@ if ($_SESSION['accepted'] != 1) { echo "
"; -//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 "
$date
Simple | "; -echo "Normal | "; -echo "Complex | "; -$today = date('l'); -//if ($today == 'Sunday' OR $today == 'Saturday') - //$today = 'Weekend Map'; -//else - $today .= "'s"; -echo " NEW: $today $mapstyle"; +echo "
$date
$easy | "; +echo "$normal | "; +echo "$hard | "; +echo "$special"; echo DisplayMap($mergesolution, $mapID); -- cgit v1.2.3