Beispiel #1
0
 /**
  * @param Node $end
  * @param $heap
  * @param $current
  * @return Node
  */
 private function fillHeap(\SplHeap $heap, Node $current, Node $end)
 {
     while ($heap->valid() && $current !== $end) {
         /**
          * @var Node $current
          */
         $current = $heap->extract();
         $current->close();
         $neighbors = $this->grid->getNeighbors($current, $this->diagonal);
         foreach ($neighbors as $neighbor) {
             if ($neighbor->isClosed() || in_array($neighbor->getCosts(), $this->blocked)) {
                 continue;
             }
             $score = $current->getScore() + $neighbor->getCosts();
             $visited = $neighbor->isVisited();
             if (!$visited || $score < $neighbor->getScore()) {
                 $neighbor->visit();
                 $neighbor->setParent($current);
                 $neighbor->setGuessedScore($this->heuristic->compare($neighbor, $end));
                 $neighbor->setScore($score);
                 $neighbor->setTotalScore($neighbor->getScore() + $neighbor->getGuessedScore());
                 if (!$visited) {
                     $heap->insert($neighbor);
                 }
             }
         }
     }
     return $current;
 }
Beispiel #2
0
 public function dump($var)
 {
     return parent::dump($var);
 }
Beispiel #3
0
 public function count()
 {
     throw new Exception('Cause count to fail');
     return parent::count();
 }
 public function compare()
 {
     return -parent::compare();
 }
 public function insert($value)
 {
     $value->setOrder($this->elements++);
     parent::insert($value);
 }