Exemplo n.º 1
0
 public function __construct($last_gen = null)
 {
     $this->_humans = array();
     // Init
     if (!isset($last_gen) || !is_array($last_gen)) {
         for ($i = 0; $i < self::INIT_NUMBER; $i++) {
             $gender = Random::gender();
             $iQ = Random::iQ(self::IQ_INIT_BASE, self::IQ_INIT_VAR, self::IQ_INIT_SD);
             $this->_humans[] = new Human($gender, $iQ);
         }
         // Based on last generation
     } else {
         while (($mother = array_shift($last_gen[Human::$genders[Human::FEMALE]])) && ($father = array_shift($last_gen[Human::$genders[Human::MALE]]))) {
             $childNum = Random::childNum();
             for ($i = 0; $i < $childNum; $i++) {
                 $gender = Random::gender();
                 $iQ = self::childIQ($gender, $father, $mother);
                 $this->_humans[] = new Human($gender, $iQ);
             }
         }
     }
 }