parent = $parent; } /** * @return Node|bool */ public function getParent() { return $this->parent; } public function getParentAndCleanSelf(){ try{ return $this->parent; }finally{ $this->parent = null; } } /** * @return int|float */ public function getGCost() { if(is_null($this->gCost)) { $this->gCost = $this->parent ? $this->parent->getGCost() + $this->getOwnCost() : $this->getOwnCost(); } return $this->gCost; } /** * @param Node $target * @return float|int */ public function getFCost(Node $target) { return $this->getGCost() + $this->getHCost($target); } /** * @return int|float */ abstract public function getOwnCost(); /** * @param Node $target * @return int|float */ abstract public function getHCost(Node $target); /** * @param AStar $pf * @return Node[] */ abstract public function getAdjacentNodes(AStar $pf); /** * @param Node $compareTo * @return bool */ abstract public function equals(Node $compareTo); /** * Check can this point be used * @param AStar $pf * @return bool */ abstract public function canMoveHere(AStar $pf); /** * should return a unique string for this * * @return string */ public function __toString(){ return parent::__toString(); } /** * this method should allow a node * to get the data from the target node getHostCost requires for its heuristic (if needed) * * @return array */ public function getDataForH() { return []; } }