PHP Code:
/**
* Neopets constellation finder (altador plot).
* Originally written in Javascript by Andy Nguyen, ported to PHP by Zachafer.
*/
error_reporting(-1);
class ConstellationFinder
{
private $data;
public function ConstellationFinder($starData)
{
$this->data = $starData;
}
private $dxArray = array(array(40, 80, 120, 160, 200), array(60, 120, 130, 190,
110), array(20, 80, 160, 140, 80), array(140, 10, 120, 160, 80), array(60, 120,
0, 60, 120), array(50, 170, 200, 190, 140), array(70, 140, 40, 70, 100), array(10,
100, 100, 190, 200), array(40, 20, 40, -50, -60), array(40, -30, 10, 110, 120),
array(-70, 70, 0, 0, -130), array(10, 120, 160, 170, 200));
private $dyArray = array(array(-30, -60, -60, -30, 0), array(-20, 0, 40, 60, -
90), array(60, 80, 0, -60, -80), array(-30, -80, -60, -70, 60), array(-30, 0,
140, 170, 140), array(70, 40, 0, -90, -10), array(30, 0, -120, -140, -120),
array(-50, -130, 10, -50, 0), array(40, -40, -80, -10, 120), array(-70, -140, -
200, -170, -90), array(0, 0, -70, 70, 90), array(-140, -60, -190, -20, 0));
public static $constNames = array(1 => 'Dreamer', 2 => 'First to Rise', 4 =>
'Dancer', 7 => 'Collector', 11 => 'Hunter', 8 => 'Thief', 3 => 'Farmer', 0 =>
'Sleeper', 5 => 'Wave', 6 => 'Gladiator', 9 => 'Gatherer', 10 => 'Protector');
public function findPoints($name)
{
$j = array_search($name, self::$constNames);
if ($j === false)
return "Invalid name";
$data = $this->data;
$data = substr($data, 0, strpos($data, ':'));
$starArray = array();
while (($linePos = strpos($data, '|')) !== false) {
$starCoords = substr($data, 0, $linePos);
$starArray[substr($starCoords, 0, strlen($starCoords) - 2)] = $starCoords;
$data = substr($data, strpos($data, '|') + 1);
}
$starCoords = $data;
$starArray[substr($starCoords, 0, strlen($starCoords) - 2)] = $starCoords;
foreach ($starArray as $i) {
$x = intval(substr($i, 0, strpos($i, ',')));
$y = intval(substr($i, strpos($i, ',') + 1));
if (array_key_exists(($x + $this->dxArray[$j][0]) . "," . ($y + $this->dyArray[$j][0]),
$starArray) && array_key_exists(($x + $this->dxArray[$j][1]) . "," . ($y + $this->
dyArray[$j][1]), $starArray) && array_key_exists(($x + $this->dxArray[$j][2]) .
"," . ($y + $this->dyArray[$j][2]), $starArray) && array_key_exists(($x + $this->
dxArray[$j][3]) . "," . ($y + $this->dyArray[$j][3]), $starArray) &&
array_key_exists(($x + $this->dxArray[$j][4]) . "," . ($y + $this->dyArray[$j][4]),
$starArray)) {
return array("(" . substr_replace($i, '', -2) . ")", "(" . ($x + $this->dxArray[$j][0]) .
"," . ($y + $this->dyArray[$j][0]) . ")", "(" . ($x + $this->dxArray[$j][1]) .
"," . ($y + $this->dyArray[$j][1]) . ")", "(" . ($x + $this->dxArray[$j][2]) .
"," . ($y + $this->dyArray[$j][2]) . ")", "(" . ($x + $this->dxArray[$j][3]) .
"," . ($y + $this->dyArray[$j][3]) . ")", "(" . ($x + $this->dxArray[$j][4]) .
"," . ($y + $this->dyArray[$j][4]) . ")");
}
}
return array();
}
public function findAll()
{
$retVal = array();
foreach (self::$constNames as $name) {
$retVal[$name] = $this->findPoints($name);
}
return $retVal;
}
public function makeURL($name)
{
$points = $this->findPoints($name);
foreach ($points as & $point)
$point = str_replace(array('(', ')'), '', $point);
return "star_submit=" . $this->joinPoints($points, $name);
}
private $pointsOrder = array('Sleeper' => array(0, 1, 1, 0, 1, 2, 2, 1, 3, 4, 4,
3, 4, 5, 5, 4), 'Dreamer' => array(0, 1, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4),
'First to Rise' => array(0, 1, 1, 0, 1, 2, 2, 1, 3, 4, 4, 5, 4, 3, 5, 4),
'Farmer' => array(0, 1, 1, 4, 1, 5, 1, 0, 2, 3, 3, 2, 3, 4, 4, 3, 4, 1, 5, 1),
'Dancer' => array(0, 1, 1, 2, 1, 0, 2, 1, 3, 4, 4, 3, 4, 5, 5, 4), 'Wave' =>
array(0, 1, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5, 5, 4), 'Gladiator' =>
array(0, 3, 0, 1, 1, 2, 1, 0, 2, 5, 2, 1, 3, 0, 3, 4, 4, 3, 4, 5, 5, 4, 5, 2),
'Collector' => array(0, 3, 0, 1, 1, 0, 2, 3, 3, 5, 3, 2, 3, 0, 5, 3, 5, 4, 4, 5),
'Thief' => array(0, 4, 0, 2, 0, 1, 1, 0, 1, 5, 2, 0, 2, 3, 3, 2, 4, 5, 4, 0, 5,
4, 5, 1), 'Gatherer' => array(0, 1, 1, 0, 2, 5, 2, 3, 3, 4, 3, 2, 4, 5, 4, 3, 5,
2, 5, 4), 'Protector' => array(0, 4, 0, 3, 0, 1, 0, 2, 1, 0, 1, 3, 1, 4, 2, 0, 2,
3, 2, 4, 3, 0, 3, 2, 3, 1, 4, 0, 4, 1, 4, 2), 'Hunter' => array(0, 1, 0, 4, 1, 2,
1, 3, 1, 0, 2, 4, 2, 1, 3, 4, 3, 1, 4, 5, 4, 2, 4, 3, 4, 0, 5, 4));
private function joinPoints($points, $name)
{
if (array_key_exists($name, $this->pointsOrder)) {
$submit = '';
$semiColon = false;
$order = $this->pointsOrder[$name];
$loopMax = count($order);
$x = 0;
while ($x < $loopMax) {
$submit .= $points[$order[$x]];
if (++$x < count($order))
if ($semiColon = !$semiColon)
$submit .= ';';
else
$submit .= '|';
}
}
if ($name == 'Dreamer') {
$submit .= '|' . $points[5] . '|' . $points[4] . ';' . $points[3];
} elseif ($name == 'Protector') {
$submit .= '|' . $points[5];
}
return $submit;
}
}
Usage: