/** * Renvoie les hexagones dans l'ordre d'un balayage * @return HexaCollection */ public function buildHexas() { $this->hexas = new HexaCollection(); $debutLigne = $this->coinSupGauche(); $rivieres = array(); for ($y = 1; $y <= $this->hauteur; $y++) { $current = $debutLigne; for ($x = 0; $x < $this->largeur; $x++) { $this->hexas->ajout($current); // Rivères foreach ($current->getRivieres() as $riviere) { /** @var Riviere $riviere */ if (!isset($rivieres[$riviere->getId()])) { $this->rivieres->ajout($riviere); $rivieres[$riviere->getId()] = true; } } // Visibles $this->ajoutVisiblesHexa($current); $current = $current->getVoisin(0); } if (fmod($debutLigne->getY(), 2) == 1) { // Y impair $debutLigne = $debutLigne->getVoisin(5); } else { // Y pair $debutLigne = $debutLigne->getVoisin(4); } } }
/** * Choisit un Hexa dans les cases voisines pour un recul forcé * @return Hexa */ public function choixHexaReculForce() { $destPossibles = new HexaCollection(); foreach ($this->getPosition()->voisins() as $hexa) { /** @var Hexa $hexa */ if ($this->getQg()->canPass($this->getPosition(), $hexa)) { $destPossibles->ajout($hexa); } } $destPossibles->uasort('fr\\gilman\\nj\\common\\bb\\business\\HexaBusiness::choixReculForce'); return $destPossibles->getFirstElement(); }
/** * 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); } }
/** * Renvoie les hexas dans la couronne à la distance $rayon de la case et tous ceux à l'intérieur * @param $rayon * @return HexaCollection|Hexa[] */ public function getCouronnePleine($rayon) { $ret = new HexaCollection(); $ret->ajout($this); for ($i = 1; $i <= $rayon; $i++) { foreach ($this->getCouronne($i) as $hexa) { $ret->ajout($hexa); } } return $ret; }