mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 06:48:41 +00:00
Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop
This commit is contained in:
commit
b38ebb92c0
1
Algorithm/PathFinding/AStar.php
Normal file
1
Algorithm/PathFinding/AStar.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
Algorithm/PathFinding/BestFirstSearch.php
Normal file
1
Algorithm/PathFinding/BestFirstSearch.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
Algorithm/PathFinding/BreadthFirstSearch.php
Normal file
1
Algorithm/PathFinding/BreadthFirstSearch.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
Algorithm/PathFinding/Dijkstra.php
Normal file
1
Algorithm/PathFinding/Dijkstra.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
123
Algorithm/PathFinding/Grid.php
Normal file
123
Algorithm/PathFinding/Grid.php
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grid of nodes.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Grid
|
||||||
|
{
|
||||||
|
private array $nodes = [[]];
|
||||||
|
private ?Node $nullNode = null;
|
||||||
|
|
||||||
|
public function __construct(Node $nullNode)
|
||||||
|
{
|
||||||
|
$this->nullNode = $nullNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNullNode() : Node
|
||||||
|
{
|
||||||
|
return $this->nullNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNode(int $x, int $y) : Node
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
$neighbors = [];
|
||||||
|
$s0 = false;
|
||||||
|
$s1 = false;
|
||||||
|
$s2 = false;
|
||||||
|
$s3 = false;
|
||||||
|
$d0 = false;
|
||||||
|
$d1 = false;
|
||||||
|
$d2 = false;
|
||||||
|
$d3 = false;
|
||||||
|
|
||||||
|
if ($this->getNode($x, $y - 1)->isWalkable()) {
|
||||||
|
$neighbors[$x][$y - 1];
|
||||||
|
$s0 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getNode($x + 1, $y)->isWalkable()) {
|
||||||
|
$neighbors[$x + 1][$y];
|
||||||
|
$s1 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getNode($x, $y + 1)->isWalkable()) {
|
||||||
|
$neighbors[$x][$y + 1];
|
||||||
|
$s2 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getNode($x - 1, $y)->isWalkable()) {
|
||||||
|
$neighbors[$x - 1][$y];
|
||||||
|
$s3 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($movement === MovementType::STRAIGHT) {
|
||||||
|
return $neighbors;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Algorithm/PathFinding/Heuristic.php
Normal file
1
Algorithm/PathFinding/Heuristic.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
33
Algorithm/PathFinding/HeuristicType.php
Normal file
33
Algorithm/PathFinding/HeuristicType.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Heuristic type enum.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class HeuristicType extends Enum
|
||||||
|
{
|
||||||
|
public const MANHATTAN = 1;
|
||||||
|
public const EUCLIDEAN = 2;
|
||||||
|
public const OCTILE = 4;
|
||||||
|
public const CHEBYSHEV = 8;
|
||||||
|
}
|
||||||
1
Algorithm/PathFinding/IDAStar.php
Normal file
1
Algorithm/PathFinding/IDAStar.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
1
Algorithm/PathFinding/JumpPointSearch.php
Normal file
1
Algorithm/PathFinding/JumpPointSearch.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
33
Algorithm/PathFinding/MovementType.php
Normal file
33
Algorithm/PathFinding/MovementType.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Movement type enum.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class MovementType extends Enum
|
||||||
|
{
|
||||||
|
public const DIAGONAL = 1;
|
||||||
|
public const STRAIGHT = 2;
|
||||||
|
public const DIAGONAL_ONE_OBSTACLE = 4;
|
||||||
|
public const DIAGONAL_NO_OBSTACLE = 8;
|
||||||
|
}
|
||||||
59
Algorithm/PathFinding/Node.php
Normal file
59
Algorithm/PathFinding/Node.php
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node on grid.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Node
|
||||||
|
{
|
||||||
|
private int $x = 0;
|
||||||
|
private int $y = 0;
|
||||||
|
private float $weight = 1.0;
|
||||||
|
private bool $isWalkable = true;
|
||||||
|
|
||||||
|
public function __construct(int $x, int $y, float $weight = 1.0, bool $isWalkable = true)
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getX() : int
|
||||||
|
{
|
||||||
|
return $this->x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getY() : int
|
||||||
|
{
|
||||||
|
return $this->y;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
Algorithm/PathFinding/Path.php
Normal file
30
Algorithm/PathFinding/Path.php
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path in grids.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Algorithm\PathFinding
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Path
|
||||||
|
{
|
||||||
|
private array $nodes = [];
|
||||||
|
private float $weight = 0.0;
|
||||||
|
private float $distance = 0.0;
|
||||||
|
}
|
||||||
9
Algorithm/PathFinding/PathFinderInterface.php
Normal file
9
Algorithm/PathFinding/PathFinderInterface.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
interface PathFinderInterface {
|
||||||
|
public static function findPath(
|
||||||
|
int $startX, int $startY,
|
||||||
|
int $endX, int $endY,
|
||||||
|
Grid $grid,
|
||||||
|
int $heuristic, int $movement,
|
||||||
|
) : array;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user