Exemple #1
0
 /**
  * Defines next generation
  *
  * @return array
  */
 public function nextGeneration()
 {
     $next = [];
     for ($i = 1; $i <= $this->neighborhood->getMatrixSize(); $i++) {
         for ($j = 1; $j <= $this->neighborhood->getMatrixSize(); $j++) {
             $member = "{$i},{$j}";
             if ($this->constitution->willLive($member)) {
                 $next[] = $member;
             }
         }
     }
     return $next;
 }
Exemple #2
0
 public function it_generates_another_generation_next(\Constitution $constitution, \Neighborhood $neighborhood)
 {
     $constitution->willLive('2,3')->willReturn(true);
     $constitution->willLive('2,4')->willReturn(true);
     $constitution->willLive('3,4')->willReturn(true);
     $constitution->willLive('3,5')->willReturn(true);
     $constitution->willLive('4,3')->willReturn(true);
     $neighborhood->getMatrixSize()->willReturn(5);
     $this->nextGeneration()->shouldBe(['2,3', '2,4', '3,4', '3,5', '4,3']);
 }