summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--css/page.css24
-rw-r--r--includes/maps.php1
-rw-r--r--pages/gallery.php143
-rw-r--r--pages/leaderboard.php67
4 files changed, 174 insertions, 61 deletions
diff --git a/css/page.css b/css/page.css
index 31c0647..3421113 100644
--- a/css/page.css
+++ b/css/page.css
@@ -2,6 +2,7 @@ html {
font-family: Helvetica, Arial, sans-serif;
}
html.wf-active {
+ /* font-family: "Comic Sans MS", sans-serif; */
font-family: Cantarell, Helvetica, Arial, sans-serif;
}
@@ -99,6 +100,29 @@ a:hover {
border: 1px solid #223;
}
+#daynav {
+ width: 100%;
+ text-align: center;
+ margin-bottom: 10px;
+ padding-bottom: 15px;
+}
+#daynav a {
+ margin: 0 35px;
+ color: #ddd;
+ background-color: #223;
+ padding: 3px 10px;
+ border-radius: 5px;
+ text-decoration: none;
+ border: 1px solid #332;
+ box-shadow: 0 0 1px #445;
+}
+#daynav a.selected, #daynav a:hover {
+ background-color: #336;
+ border: 1px solid #112;
+}
+
+
+
table.score {
border: 1px solid #777;
background-color: #252530;
diff --git a/includes/maps.php b/includes/maps.php
index 1c51f6d..f3ac29c 100644
--- a/includes/maps.php
+++ b/includes/maps.php
@@ -733,6 +733,7 @@ function findTiles ($mapMatrix, $search) {
// Returns: ARRAY( blocked, path, start, end )
+//!! X and Y are reversed here...
function findPath($mapMatrix, $start = '0,1.', $target = 'f') {
$seed = explode(".", $start);
foreach ($seed as &$v) {
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) {
diff --git a/pages/leaderboard.php b/pages/leaderboard.php
index 290f23b..13f5518 100644
--- a/pages/leaderboard.php
+++ b/pages/leaderboard.php
@@ -13,14 +13,22 @@ include('./includes/datas.php');
include_once ('./includes/db.inc.php');
-$tStats = getStat(1);
-$yStats = getStat(2);
+//Display stats for how many days ago?
+$daysago = 1;
+if (($_GET['daysago'] * 1) > 1) {
+ $daysago = ($_GET['daysago'] * 1);
+}
+
+
+
+$tStats = getStat(1, $daysago);
+$yStats = getStat(2, $daysago);
-$wStats = getStat(3);
-$mStats = getStat(4);
+$wStats = getStat(3, $daysago);
+$mStats = getStat(4, $daysago);
-function getStat ($type) {
+function getStat ($type, $daysago = 1) {
switch ($type) {
//Todays
@@ -36,12 +44,15 @@ function getStat ($type) {
//Yesterdays
case 2:
$where = "
- DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
+ DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
- AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
+ AND DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
";
$statname = "Yesterday's Best Overall:";
+ if ($daysago > 1) {
+ $statname = "$daysago days ago's Best Overall.";
+ }
break;
case 3:
$where = "
@@ -78,6 +89,19 @@ function getStat ($type) {
<div class="wrapper">
+
+<div id="daynav">
+<?
+if ($daysago > 1) {
+ $nextday = $daysago - 1;
+ echo "<a href='?page=leaderboard&daysago=1' title='Now'>Current Day</a>";
+ echo "<a href='?page=leaderboard&daysago=$nextday' title='Newer'>Next Day</a>";
+}
+ $prevday = $daysago + 1;
+ echo "<a href='?page=leaderboard&daysago=$prevday' title='Older'>Previous Day</a>";
+?>
+</div>
+
<div id="difficulties">
<a href="javascript:showStats(0)" id="dl-0">Overall</a>
<a href="javascript:showStats(1)" id="dl-1">Simple</a>
@@ -97,7 +121,11 @@ function getStat ($type) {
</div>
<?
-function yesterdayMaze($mapType, $name) {
+function displayPastMaze($mapType, $name, $daysago = 1) {
+ //Ensure no cheating
+ if ($daysago < 1)
+ return;
+
$sql = "SELECT
maps.ID as mapID,
solution,
@@ -111,19 +139,24 @@ function yesterdayMaze($mapType, $name) {
ON solutions.userID = users.ID
JOIN `mapOfTheDay`
ON maps.ID = mapOfTheDay.mapID
- WHERE DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
+ WHERE DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
- AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
+ AND DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
AND `mapType` = '$mapType'
GROUP BY solutions.userID
ORDER BY Moves DESC, `dateModified` ASC
";
$result = mysql_query($sql);
- $stats = displayStats($result, "Yesterday's Best $name:");
+
+ $statname = "Yesterday's Best $name:";
+ if ($daysago > 1) {
+ $statname = "$daysago days ago's Best $name:";
+ }
+ $stats = displayStats($result, $statname);
- $pastMap = pastMap($mapType, 1);
+ $pastMap = pastMap($mapType, $daysago);
$mapID = $pastMap;
$mapcode = getMapCode($mapID);
$map = GenerateMapByCode($mapcode);
@@ -199,10 +232,12 @@ function mysql_field_array( $query ) {
// $data[1]['columnname'] == 'my data';
-yesterdayMaze(1, 'Simple');
-yesterdayMaze(2, 'Normal');
-yesterdayMaze(3, 'Complex');
-yesterdayMaze(4, 'Special');
+
+
+displayPastMaze(1, 'Simple', $daysago);
+displayPastMaze(2, 'Normal', $daysago);
+displayPastMaze(3, 'Complex', $daysago);
+displayPastMaze(4, 'Special', $daysago);
?>