Beispiel #1
0
 /**
  * @param int $number
  */
 public function addNumber($number)
 {
     $numberHalfScore = Math::numberToHalfScore($number);
     if (in_array($numberHalfScore, $this->halfScores)) {
         throw new RowException('Cannot add two numbers from the same halfscore');
     }
     if (in_array($number, $this->cells)) {
         throw new RowException('Cannot add the same value twice');
     }
     if ($number <= 0 || $number > 90) {
         throw new RowException('Out of range value');
     }
     $added = false;
     foreach ($this->cells as $index => $cellTofill) {
         if (is_null($cellTofill)) {
             $this->cells[$index] = $number;
             $this->halfScores[] = $numberHalfScore;
             $added = true;
             break;
         }
     }
     if (!$added) {
         throw new RowException('Row is full');
     }
 }
Beispiel #2
0
 public function testFindTriples()
 {
     $array = [1, 1, 1, 2, 2, 3, 3, 2];
     $triples = Math::findTriples($array);
     $this->assertContains(2, $triples);
     $this->assertCount(2, $triples);
 }
Beispiel #3
0
 protected function checkNumbersHistory()
 {
     if (count($this->numbersHistory) !== 15) {
         return;
     }
     $halfScores = [];
     foreach ($this->numbersHistory as $number) {
         $halfScores[] = Math::numberToHalfScore($number);
     }
     $triples = Math::findTriples($halfScores);
     if (count($triples) > 0) {
         throw new FolderException('Folder can\'t contain same halfscore more than twice');
     }
 }
Beispiel #4
0
 /**
  * @param Folder $folder
  * @return array
  */
 protected static function fillEmptySpaces(Folder $folder)
 {
     $formattedFolder = [];
     $rows = $folder->getRows();
     $filledRows = [];
     foreach ($rows as $row) {
         $filledRow = array_fill(0, 9, null);
         $cells = $row->getCells();
         foreach ($cells as $number) {
             $filledRow[Math::numberToHalfScore($number)] = $number;
         }
         $filledRows[] = $filledRow;
     }
     return $filledRows;
 }
Beispiel #5
0
 protected function getUnaivalableHalfScoreIndexes()
 {
     $usedInRow = [];
     foreach ($this->extractionHistory->getRowHistory() as $number) {
         $usedInRow[] = Math::numberToHalfScore($number);
     }
     $usedInFolder = [];
     foreach ($this->extractionHistory->getFolderHistory() as $number) {
         $usedInFolder[] = Math::numberToHalfScore($number);
     }
     $usedTwiceInFolder = Math::findDoubles($usedInFolder);
     $consumed = [];
     foreach ($this->halfScores as $index => $halfScore) {
         if (count($halfScore) === 0) {
             $consumed[] = $index;
         }
     }
     return array_merge($consumed, $usedInRow, $usedTwiceInFolder);
 }