Ejemplo n.º 1
0
 /**
  * Renvoie les frontières entre 2 territoires différents de la carte
  * @return FrontiereCollection
  */
 public function getFrontieresTerritoires()
 {
     $ret = new FrontiereCollection();
     foreach ($this->getHexas()->getFrontieres() as $frontiere) {
         /** @var Frontiere $frontiere */
         if (!is_null($frontiere->getHexa1()) && !is_null($frontiere->getHexa2()) && ($frontiere->getHexa1()->getIdTerritoire() || $frontiere->getHexa2()->getIdTerritoire()) && $frontiere->getHexa1()->getIdTerritoire() != $frontiere->getHexa2()->getIdTerritoire()) {
             if ($frontiere->getHexa1()->getIdTerritoire()) {
                 $frontiere->setCouleur1($frontiere->getHexa1()->getJoueurTerritoire()->getCouleur());
             }
             if ($frontiere->getHexa2()->getIdTerritoire()) {
                 $frontiere->setCouleur2($frontiere->getHexa2()->getJoueurTerritoire()->getCouleur());
             }
             $ret->append($frontiere);
         }
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Renvoie la frontière meilleure candidate pour faire couler la riviere
  * @return Frontiere
  */
 public function prochainCoulage()
 {
     // Se jeter dans une autre rivière
     foreach ($this->getVoisins() as $voisin) {
         /** @var Frontiere $voisin */
         if (!is_null($voisin->getRiviere()) && $voisin->getRiviere()->getSource() != $this->getRiviere()->getSource()) {
             return $voisin;
         }
     }
     // Trouver l'endroit libre le plus loin de la riviere en cours
     $nbInluencesMin = 3;
     $selection = new FrontiereCollection();
     foreach ($this->getVoisins() as $voisin) {
         /** @var Frontiere $voisin */
         if (is_null($voisin->getRiviere())) {
             $nbInluences = 0;
             foreach ($voisin->getVoisins() as $voisin2) {
                 /** @var Frontiere $voisin2 */
                 if (!is_null($voisin2->getRiviere()) && $voisin2->getRiviere()->getSource() == $this->getRiviere()->getSource()) {
                     $nbInluences++;
                 }
             }
             if ($nbInluences < $nbInluencesMin) {
                 $selection = new FrontiereCollection();
                 $selection->append($voisin);
                 $nbInluencesMin = $nbInluences;
             } elseif ($nbInluences == $nbInluencesMin) {
                 $selection->append($voisin);
             }
         }
     }
     if ($selection->count() == 0) {
         return null;
     }
     if ($selection->count() > 1) {
         $selection->uasort('fr\\gilman\\nj\\common\\bb\\collection\\FrontiereCollection::triParHauteurASC');
     }
     return $selection->getFirst();
 }