Esempio n. 1
0
 /**
  * Calcule la trajectoire de ravitaillement
  * @return void
  */
 protected function setTrajectoireRavitaillement()
 {
     if (is_null($this->trajectoireRavitaillement)) {
         $trajectoire = new Trajectoire($this->getPartie(), $this->getPosition(), $this->getJoueur());
         $trajectoire->setQg($this);
         $trajectoire->setFakeQg(Trajectoire::BUT_RAVITAILLEMENT);
         $trajectoire->initExploratoireRavitaillement();
         $trajectoire->make();
         $this->trajectoireRavitaillement = $trajectoire;
     }
     Debug::w(array('msg' => 'trajectoire ravitaillement', 'qg' => $this->getId(), 'hexas' => $this->trajectoireRavitaillement->__toString()));
 }
Esempio n. 2
0
 /**
  * Cherche la trajectoire la plus courte
  * @return void
  */
 public function make()
 {
     $noeud = new Noeud($this->getOrigine());
     $noeud->setNoPassageDebordement(0);
     $this->noeuds[] = $noeud;
     $pas = 0;
     /*
      * Trouvage chemin le plus court
      */
     while (!$this->termine) {
         if ($this->getOrigine()->getId() == 904) {
             Debug::w(array('pas' => $pas));
         }
         $auMoinsUnNoeud = false;
         foreach ($this->noeuds as $noeud) {
             Debug::w(__LINE__);
             foreach ($noeud->getHexa()->voisins() as $voisin) {
                 /** @var Hexa $voisin */
                 $canPass = $this->fakeQg->canPass($noeud->getHexa(), $voisin, true);
                 $coutDep = $this->fakeQg->getCoutDeplacement($noeud->getHexa(), $voisin);
                 if ($canPass && (!is_null($voisin->getNoeud()) && $coutDep + $noeud->getNoPassageDebordement() < $voisin->getNoeud()->getNoPassageDebordement() || is_null($voisin->getNoeud()))) {
                     $auMoinsUnNoeud = true;
                     if (is_null($voisin->getNoeud())) {
                         $noeudCible = new Noeud($voisin);
                     } else {
                         $noeudCible = $voisin->getNoeud();
                     }
                     $noeudCible->setNoPassageDebordement($coutDep + $noeud->getNoPassageDebordement());
                     $noeudCible->setProvenance($noeud->getHexa());
                     $this->noeuds[] = $noeudCible;
                     if ($this->objectifAtteint($voisin->getNoeud())) {
                         $this->termine = true;
                         $this->possible = true;
                         $this->destination = $voisin;
                         break 3;
                     }
                 }
             }
         }
         if (!$auMoinsUnNoeud) {
             $this->termine = true;
             $this->possible = false;
         }
         $pas++;
     }
     /*
      * Traçage du chemin
      */
     if ($this->possible) {
         $enCours = true;
         $this->hexas->ajout($this->destination);
         $noeud = $this->destination->getNoeud();
         while ($enCours) {
             if (!is_null($noeud->getProvenance())) {
                 $this->hexas->ajout($noeud->getProvenance());
                 $noeud = $noeud->getProvenance()->getNoeud();
             } else {
                 $enCours = false;
             }
         }
         $this->hexas->reverse();
     }
     /*
      * Vidage des noeuds des hexas
      */
     foreach ($this->noeuds as $noeud) {
         $noeud->getHexa()->setNoeud(null);
     }
 }