/**
  * @param $char
  * @return \Nonogram\Cell\CellBox|\Nonogram\Cell\CellEmpty
  */
 protected function convertRawToCell($char)
 {
     $this->cellFactory->setStatusHidden(false);
     if ($this->getBoxChar() === $char) {
         $cell = $this->cellFactory->getBox();
     } else {
         $cell = $this->cellFactory->getEmpty();
     }
     return $cell;
 }
 protected function convertRowRawToActual($rowString)
 {
     $field = array();
     for ($i = 0; $i < strlen($rowString); $i++) {
         switch ($rowString[$i]) {
             case 'U':
                 $cell = $this->cellFactory->getUnknown();
                 break;
             case 'B':
                 $cell = $this->cellFactory->getBox();
                 break;
             case 'E':
                 $cell = $this->cellFactory->getEmpty();
                 break;
         }
         $field[] = $cell;
     }
     return $field;
 }
 /**
  * @param $i
  * @param $type
  */
 protected function determineCell($i, $type)
 {
     if (!array_key_exists($i, $this->row)) {
         throw new \OutOfBoundsException(sprintf('invalid cell identifier %d', $i));
     }
     if ($this->row[$i]->getType() !== $type && $type !== AnyCell::TYPE_UNKNOWN) {
         if ($this->row[$i]->getType() !== AnyCell::TYPE_UNKNOWN) {
             throw new \RuntimeException('puzzle has no solution');
         }
         $this->row[$i] = $this->cellFactory->getByType($type);
         $this->updateCounter++;
     }
 }
Exemple #4
0
 /**
  * Inits the field with all cells set to "unknown"
  * @param array $fieldOverride option to inject a pre-defined state, only useful for unittests
  */
 private function initField(array $fieldOverride = array())
 {
     if (!empty($fieldOverride)) {
         $this->field = $fieldOverride;
         return;
     }
     $sizeX = $this->labels->getSizeX();
     $sizeY = $this->labels->getSizeY();
     $this->field = array();
     for ($indexX = 0; $indexX < $sizeX; $indexX++) {
         for ($indexY = 0; $indexY < $sizeY; $indexY++) {
             $this->field[$indexY][$indexX] = $this->cellFactory->getUnknown();
         }
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->labelFactory = new \Nonogram\Label\Factory(new \Nonogram\Label\LabelProviderCells());
     $this->labelFactory->setContainer($this->container);
 }