From 3bb09081d42d60511f1e517c48b134a659d99ed1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:22:06 +0200 Subject: [PATCH 01/26] Create Heuristic.php --- Algorithm/PathFinding/Heuristic.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/Heuristic.php diff --git a/Algorithm/PathFinding/Heuristic.php b/Algorithm/PathFinding/Heuristic.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/Heuristic.php @@ -0,0 +1 @@ + From 2059f85800ac27867262a9e45c32af016f6260d5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:22:17 +0200 Subject: [PATCH 02/26] Create Grid.php --- Algorithm/PathFinding/Grid.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/Grid.php diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/Grid.php @@ -0,0 +1 @@ + From 0878f9498d5d3b2f2bf05edcaf58134a279d7155 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:22:26 +0200 Subject: [PATCH 03/26] Create Node.php --- Algorithm/PathFinding/Node.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/Node.php diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/Node.php @@ -0,0 +1 @@ + From 071c6a010eb0c4ac7a0cfa337929fe4737ae6038 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:23:00 +0200 Subject: [PATCH 04/26] Create HeuristicType.php --- Algorithm/PathFinding/HeuristicType.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/HeuristicType.php diff --git a/Algorithm/PathFinding/HeuristicType.php b/Algorithm/PathFinding/HeuristicType.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/HeuristicType.php @@ -0,0 +1 @@ + From 8c9c5c192e5aa492f0030dec51efaaf31d18c6af Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:23:11 +0200 Subject: [PATCH 05/26] Create JPS.php --- Algorithm/PathFinding/JPS.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/JPS.php diff --git a/Algorithm/PathFinding/JPS.php b/Algorithm/PathFinding/JPS.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/JPS.php @@ -0,0 +1 @@ + From 87a5577721cb696c38b8d8d4aae7748b3986fdec Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:24:29 +0200 Subject: [PATCH 06/26] Create MovementType.php --- Algorithm/PathFinding/MovementType.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/MovementType.php diff --git a/Algorithm/PathFinding/MovementType.php b/Algorithm/PathFinding/MovementType.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/MovementType.php @@ -0,0 +1 @@ + From 5eb3881b2861881a5cd0aeb04a0b1aa6ebca23be Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:25:49 +0200 Subject: [PATCH 07/26] Create AStar.php --- Algorithm/PathFinding/AStar.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/AStar.php diff --git a/Algorithm/PathFinding/AStar.php b/Algorithm/PathFinding/AStar.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/AStar.php @@ -0,0 +1 @@ + From 324ab2d21f502fcf63bea2be2d61ec93759ffa56 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:26:37 +0200 Subject: [PATCH 08/26] Create IDAStar.php --- Algorithm/PathFinding/IDAStar.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/IDAStar.php diff --git a/Algorithm/PathFinding/IDAStar.php b/Algorithm/PathFinding/IDAStar.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/IDAStar.php @@ -0,0 +1 @@ + From 5c2ca9cc83f5131596cee171bf285f2cf4b76c8b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:27:01 +0200 Subject: [PATCH 09/26] Create BreadthFirstSearch.php --- Algorithm/PathFinding/BreadthFirstSearch.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/BreadthFirstSearch.php diff --git a/Algorithm/PathFinding/BreadthFirstSearch.php b/Algorithm/PathFinding/BreadthFirstSearch.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/BreadthFirstSearch.php @@ -0,0 +1 @@ + From 3e2805b1404a9e58fd2694ef66c25cb06863640e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:27:22 +0200 Subject: [PATCH 10/26] Rename JPS.php to JumpPointSearch.php --- Algorithm/PathFinding/{JPS.php => JumpPointSearch.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Algorithm/PathFinding/{JPS.php => JumpPointSearch.php} (100%) diff --git a/Algorithm/PathFinding/JPS.php b/Algorithm/PathFinding/JumpPointSearch.php similarity index 100% rename from Algorithm/PathFinding/JPS.php rename to Algorithm/PathFinding/JumpPointSearch.php From f12d1834aa23d4fa70733fbaa713de6df2caa403 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:27:37 +0200 Subject: [PATCH 11/26] Create BestFirstSearch.php --- Algorithm/PathFinding/BestFirstSearch.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/BestFirstSearch.php diff --git a/Algorithm/PathFinding/BestFirstSearch.php b/Algorithm/PathFinding/BestFirstSearch.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/BestFirstSearch.php @@ -0,0 +1 @@ + From a3abbbb9e19163349fcad49dd603272815a5774c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:27:54 +0200 Subject: [PATCH 12/26] Create Dijkstra.php --- Algorithm/PathFinding/Dijkstra.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/Dijkstra.php diff --git a/Algorithm/PathFinding/Dijkstra.php b/Algorithm/PathFinding/Dijkstra.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/Dijkstra.php @@ -0,0 +1 @@ + From b604abfdaeb7c9ea97df2ef85008e8c5800510aa Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 15:59:56 +0200 Subject: [PATCH 13/26] Update HeuristicType.php --- Algorithm/PathFinding/HeuristicType.php | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Algorithm/PathFinding/HeuristicType.php b/Algorithm/PathFinding/HeuristicType.php index 8b1378917..f648112c0 100644 --- a/Algorithm/PathFinding/HeuristicType.php +++ b/Algorithm/PathFinding/HeuristicType.php @@ -1 +1,33 @@ + Date: Tue, 20 Aug 2019 16:00:34 +0200 Subject: [PATCH 14/26] Update HeuristicType.php --- Algorithm/PathFinding/HeuristicType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithm/PathFinding/HeuristicType.php b/Algorithm/PathFinding/HeuristicType.php index f648112c0..73aaf483a 100644 --- a/Algorithm/PathFinding/HeuristicType.php +++ b/Algorithm/PathFinding/HeuristicType.php @@ -4,7 +4,7 @@ * * PHP Version 7.4 * - * @package phpOMS\Account + * @package phpOMS\Algorithm\PathFinding * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ use phpOMS\Stdlib\Base\Enum; /** * Heuristic type enum. * - * @package phpOMS\Account + * @package phpOMS\Algorithm\PathFinding * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 From 463ff29c192e767ef3e05dc66128b2299f40ecbe Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:02:46 +0200 Subject: [PATCH 15/26] Update MovementType.php --- Algorithm/PathFinding/MovementType.php | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Algorithm/PathFinding/MovementType.php b/Algorithm/PathFinding/MovementType.php index 8b1378917..4c8a89338 100644 --- a/Algorithm/PathFinding/MovementType.php +++ b/Algorithm/PathFinding/MovementType.php @@ -1 +1,33 @@ + Date: Tue, 20 Aug 2019 16:03:41 +0200 Subject: [PATCH 16/26] Update MovementType.php --- Algorithm/PathFinding/MovementType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Algorithm/PathFinding/MovementType.php b/Algorithm/PathFinding/MovementType.php index 4c8a89338..647d7b0eb 100644 --- a/Algorithm/PathFinding/MovementType.php +++ b/Algorithm/PathFinding/MovementType.php @@ -17,7 +17,7 @@ namespace phpOMS\Algorithm\PathFinding; use phpOMS\Stdlib\Base\Enum; /** - * Heuristic type enum. + * Movement type enum. * * @package phpOMS\Algorithm\PathFinding * @license OMS License 1.0 From 5aad7af88f8546cb4be686fe90b31a1e69815486 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:08:31 +0200 Subject: [PATCH 17/26] Update Node.php --- Algorithm/PathFinding/Node.php | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php index 8b1378917..965186111 100644 --- a/Algorithm/PathFinding/Node.php +++ b/Algorithm/PathFinding/Node.php @@ -1 +1,51 @@ +x = $x; + $this->y = $y; + $this->weight = $weight; + $this->isWalkable = $isWalkable; + } + + public function isWalkable() : bool + { + return $this->isWalkable; + } + + public function getWeight() : float + { + return $this->weight; + } +} From cdbfa4e1b088cccd2bbb6133b8ee8d53381c426f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:10:20 +0200 Subject: [PATCH 18/26] Update Node.php --- Algorithm/PathFinding/Node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php index 965186111..b28216743 100644 --- a/Algorithm/PathFinding/Node.php +++ b/Algorithm/PathFinding/Node.php @@ -17,7 +17,7 @@ namespace phpOMS\Algorithm\PathFinding; use phpOMS\Stdlib\Base\Enum; /** - * Node on map. + * Node on grid. * * @package phpOMS\Algorithm\PathFinding * @license OMS License 1.0 From 8f3eeac9872faf93adf73d11af0891f761083a86 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:10:39 +0200 Subject: [PATCH 19/26] Update Node.php --- Algorithm/PathFinding/Node.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php index b28216743..96bf5a3bb 100644 --- a/Algorithm/PathFinding/Node.php +++ b/Algorithm/PathFinding/Node.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace phpOMS\Algorithm\PathFinding; -use phpOMS\Stdlib\Base\Enum; - /** * Node on grid. * From ea85dd5f258bdbf61169b38a5107c378e9563a88 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:13:05 +0200 Subject: [PATCH 20/26] Update Grid.php --- Algorithm/PathFinding/Grid.php | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php index 8b1378917..7b9110e9e 100644 --- a/Algorithm/PathFinding/Grid.php +++ b/Algorithm/PathFinding/Grid.php @@ -1 +1,39 @@ +nullNode; + } + + public function setNullNode(Node $nullNode) : void + { + $this->nullNode = $nullNode; + } +} From aec62e3eb2c00ea9a4554fa4be15679248db6455 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:20:38 +0200 Subject: [PATCH 21/26] Update Node.php --- Algorithm/PathFinding/Node.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php index 96bf5a3bb..147fdd1e9 100644 --- a/Algorithm/PathFinding/Node.php +++ b/Algorithm/PathFinding/Node.php @@ -46,4 +46,14 @@ class Node { return $this->weight; } + + public function getX() : int + { + return $this->x; + } + + public function getY() : int + { + return $this->y; + } } From 095fd1560764f45c244586da256a5e37b0505720 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:28:38 +0200 Subject: [PATCH 22/26] Update Grid.php --- Algorithm/PathFinding/Grid.php | 74 ++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php index 7b9110e9e..09e69a8d1 100644 --- a/Algorithm/PathFinding/Grid.php +++ b/Algorithm/PathFinding/Grid.php @@ -24,16 +24,84 @@ namespace phpOMS\Algorithm\PathFinding; */ class Grid { - private array $nodes = []; + private array $nodes = [[]]; private ?Node $nullNode = null; + public function __construct(Node $nullNode) + { + $this->nullNode = $nullNode; + } + public function getNullNode() : Node { return $this->nullNode; } - public function setNullNode(Node $nullNode) : void + public function getNode(int $x, int $y) : Node { - $this->nullNode = $nullNode; + if (!isset($this->nodes[$x]) || $this->nodes[$x][$y]) { + return $this->nullNode; + } + + return $this->nodes[$x][$y]; + } + + public function getNeighbors(Node $node, int $movement) : array + { + $x = $node->getX(); + $y = $node->getY(); + + $neighbours = []; + $s0 = false; + $s1 = false; + $s2 = false; + $s3 = false; + $d0 = false; + $d1 = false; + $d2 = false; + $d3 = false; + + $nodes = $this->nodes; + + if ($this->getNode($x, $y - 1)->isWalkable()) { + $neighbours[$x][$y - 1]; + $s0 = true; + } + + if ($this->getNode($x + 1, $y)->isWalkable()) { + $neighbours[$x + 1][$y]; + $s1 = true; + } + + if ($this->getNode($x, $y + 1)->isWalkable()) { + $neighbours[$x][$y + 1]; + $s2 = true; + } + + if ($this->getNode($x - 1, $y)->isWalkable()) { + $neighbours[$x - 1][$y]; + $s3 = true; + } + + if ($movement === MovementType::STRAIGHT) { + return $neighbours; + } + + if ($movement === MovementType::DIAGONAL_NO_OBSTACLE) { + $d0 = $s3 && $s0; + $d1 = $s0 && $s1; + $d2 = $s1 && $s2; + $d3 = $s2 && $s3; + } elseif ($movement === MovementType::DIAGONAL_ONE_OBSTACLE) { + $d0 = $s3 || $s0; + $d1 = $s0 || $s1; + $d2 = $s1 || $s2; + $d3 = $s2 || $s3; + } else if ($movement === MovementType::DIAGONAL) { + $d0 = true; + $d1 = true; + $d2 = true; + $d3 = true; + } } } From 6efc4e157bcf678bfb7ec2c5b51d659d2391e3ab Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 16:36:14 +0200 Subject: [PATCH 23/26] Update Grid.php --- Algorithm/PathFinding/Grid.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php index 09e69a8d1..717cb188f 100644 --- a/Algorithm/PathFinding/Grid.php +++ b/Algorithm/PathFinding/Grid.php @@ -51,7 +51,7 @@ class Grid $x = $node->getX(); $y = $node->getY(); - $neighbours = []; + $neighbors = []; $s0 = false; $s1 = false; $s2 = false; @@ -61,30 +61,28 @@ class Grid $d2 = false; $d3 = false; - $nodes = $this->nodes; - if ($this->getNode($x, $y - 1)->isWalkable()) { - $neighbours[$x][$y - 1]; + $neighbors[$x][$y - 1]; $s0 = true; } if ($this->getNode($x + 1, $y)->isWalkable()) { - $neighbours[$x + 1][$y]; + $neighbors[$x + 1][$y]; $s1 = true; } if ($this->getNode($x, $y + 1)->isWalkable()) { - $neighbours[$x][$y + 1]; + $neighbors[$x][$y + 1]; $s2 = true; } if ($this->getNode($x - 1, $y)->isWalkable()) { - $neighbours[$x - 1][$y]; + $neighbors[$x - 1][$y]; $s3 = true; } if ($movement === MovementType::STRAIGHT) { - return $neighbours; + return $neighbors; } if ($movement === MovementType::DIAGONAL_NO_OBSTACLE) { @@ -97,11 +95,29 @@ class Grid $d1 = $s0 || $s1; $d2 = $s1 || $s2; $d3 = $s2 || $s3; - } else if ($movement === MovementType::DIAGONAL) { + } elseif ($movement === MovementType::DIAGONAL) { $d0 = true; $d1 = true; $d2 = true; $d3 = true; } + + if ($d0 && $this->getNode($x - 1, $y - 1)->isWalkable()) { + $neighbors[] = $this->getNode($x - 1, $y - 1]); + } + + if ($d1 && $this->getNode($x + 1, $y - 1)->isWalkable()) { + $neighbors[] = $this->getNode($x + 1, $y - 1); + } + + if ($d2 && $this->getNode($x + 1, $y + 1)->isWalkable()) { + $neighbors[] = $this->getNode($x + 1, $y + 1); + } + + if ($d3 && $this->getNode($x - 1, $y + 1)->isWalkable()) { + $neighbors[] = $this->getNode($x - 1, $y + 1); + } + + return $neighbors; } } From 309b661fab9eaffe782437d4282d88b0968dd4f8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 17:21:24 +0200 Subject: [PATCH 24/26] Create PathFinderInterface.php --- Algorithm/PathFinding/PathFinderInterface.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Algorithm/PathFinding/PathFinderInterface.php diff --git a/Algorithm/PathFinding/PathFinderInterface.php b/Algorithm/PathFinding/PathFinderInterface.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Algorithm/PathFinding/PathFinderInterface.php @@ -0,0 +1 @@ + From ce0a98c7a8dc8144a4d6d4764e95550fcd562254 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 17:31:08 +0200 Subject: [PATCH 25/26] Update PathFinderInterface.php --- Algorithm/PathFinding/PathFinderInterface.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Algorithm/PathFinding/PathFinderInterface.php b/Algorithm/PathFinding/PathFinderInterface.php index 8b1378917..bbf315b69 100644 --- a/Algorithm/PathFinding/PathFinderInterface.php +++ b/Algorithm/PathFinding/PathFinderInterface.php @@ -1 +1,9 @@ +interface PathFinderInterface { + public static function findPath( + int $startX, int $startY, + int $endX, int $endY, + Grid $grid, + int $heuristic, int $movement, + ) : array; +} From c8ec18f912159e5167ca5edce765be916519e500 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 20 Aug 2019 17:34:47 +0200 Subject: [PATCH 26/26] Create Path.php --- Algorithm/PathFinding/Path.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Algorithm/PathFinding/Path.php diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php new file mode 100644 index 000000000..8fb952cd6 --- /dev/null +++ b/Algorithm/PathFinding/Path.php @@ -0,0 +1,30 @@ +