@@ -9,8 +9,8 @@ |
||
| 9 | 9 | |
| 10 | 10 | public function compare(Node $node, Node $goal) |
| 11 | 11 | { |
| 12 | - $deltaX = abs($node->getX() - $goal->getX()); |
|
| 13 | - $deltaY = abs($node->getY() - $goal->getY()); |
|
| 14 | - return $deltaX + $deltaY; |
|
| 12 | + $deltaX = abs($node->getX()-$goal->getX()); |
|
| 13 | + $deltaY = abs($node->getY()-$goal->getY()); |
|
| 14 | + return $deltaX+$deltaY; |
|
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | public function compare(Node $node, Node $goal) |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - $deltaX = abs($node->getX() - $goal->getX()); |
|
| 13 | - $deltaY = abs($node->getY() - $goal->getY()); |
|
| 14 | - return sqrt($deltaX * $deltaX + $deltaY * $deltaY); |
|
| 12 | + $deltaX = abs($node->getX()-$goal->getX()); |
|
| 13 | + $deltaY = abs($node->getY()-$goal->getY()); |
|
| 14 | + return sqrt($deltaX * $deltaX+$deltaY * $deltaY); |
|
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | public function compare(Node $node, Node $goal) |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - $deltaX = abs($node->getX() - $goal->getX()); |
|
| 13 | - $deltaY = abs($node->getY() - $goal->getY()); |
|
| 12 | + $deltaX = abs($node->getX()-$goal->getX()); |
|
| 13 | + $deltaY = abs($node->getY()-$goal->getY()); |
|
| 14 | 14 | return max($deltaX, $deltaY); |
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -36,16 +36,16 @@ |
||
| 36 | 36 | $y = $node->getY(); |
| 37 | 37 | |
| 38 | 38 | $neighbourLocations = [ |
| 39 | - [$y - 1, $x], |
|
| 40 | - [$y + 1, $x], |
|
| 41 | - [$y, $x - 1], |
|
| 42 | - [$y, $x + 1] |
|
| 39 | + [$y-1, $x], |
|
| 40 | + [$y+1, $x], |
|
| 41 | + [$y, $x-1], |
|
| 42 | + [$y, $x+1] |
|
| 43 | 43 | ]; |
| 44 | 44 | if ($diagonal) { |
| 45 | - $neighbourLocations[] = [$y - 1, $x - 1]; |
|
| 46 | - $neighbourLocations[] = [$y + 1, $x - 1]; |
|
| 47 | - $neighbourLocations[] = [$y - 1, $x + 1]; |
|
| 48 | - $neighbourLocations[] = [$y + 1, $x + 1]; |
|
| 45 | + $neighbourLocations[] = [$y-1, $x-1]; |
|
| 46 | + $neighbourLocations[] = [$y+1, $x-1]; |
|
| 47 | + $neighbourLocations[] = [$y-1, $x+1]; |
|
| 48 | + $neighbourLocations[] = [$y+1, $x+1]; |
|
| 49 | 49 | } |
| 50 | 50 | foreach ($neighbourLocations as $location) { |
| 51 | 51 | list($y, $x) = $location; |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | if ($neighbor->isClosed() || in_array($neighbor->getCosts(), $this->blocked)) { |
| 80 | 80 | continue; |
| 81 | 81 | } |
| 82 | - $score = $current->getScore() + $neighbor->getCosts(); |
|
| 82 | + $score = $current->getScore()+$neighbor->getCosts(); |
|
| 83 | 83 | $visited = $neighbor->isVisited(); |
| 84 | 84 | if (!$visited || $score < $neighbor->getScore()) { |
| 85 | 85 | $neighbor->visit(); |
| 86 | 86 | $neighbor->setParent($current); |
| 87 | 87 | $neighbor->setGuessedScore($this->heuristic->compare($neighbor, $end)); |
| 88 | 88 | $neighbor->setScore($score); |
| 89 | - $neighbor->setTotalScore($neighbor->getScore() + $neighbor->getGuessedScore()); |
|
| 89 | + $neighbor->setTotalScore($neighbor->getScore()+$neighbor->getGuessedScore()); |
|
| 90 | 90 | if (!$visited) { |
| 91 | 91 | $heap->insert($neighbor); |
| 92 | 92 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $result[] = $current; |
| 109 | 109 | $current = $current->getParent(); |
| 110 | 110 | } |
| 111 | - $result[]=$current; |
|
| 111 | + $result[] = $current; |
|
| 112 | 112 | return array_reverse($result); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | \ No newline at end of file |