public function setNewPuzzlePiece( puzzlePieceObserver $observer , $seed = false ) { $requiredBridges = $observer->getRequiredBridges(); $possiblePatterns = array(); // TODO loop through patterns with appropriate bridge count // add viable patterns to $possiblePatterns // randomly choose viable pattern from $possiblePatterns // create new puzzlePiece from chosen viable pattern // insert puzzlePiece into $observer return $observer; }
protected function setRandomPuzzlePiece(puzzlePieceObserver $observer) { if ($observer->getPieceType() === 'nullPuzzlePiece') { $requiredBridges = $observer->getRequiredBridges(); $possiblePatterns = array(); for ($a = $requiredBridges['required']; $a <= $requiredBridges['optional']; $a += 1) { if (isset($this->bridgePatterns[$a])) { if ($count($this->bridgePatterns[$a]) === 1) { if ($this->bridgePatterns[$a][0]->isUsable($requiredBridges['bridges'])) { $possiblePatterns[] = $this->bridgePatterns[$a][0]; } } } else { foreach ($this->bridgePatterns[$a] as $pattern) { if ($pattern->isUsable($requiredBridges['bridges'])) { $possiblePatterns[] = $pattern; } } } } if (count($possiblePatterns) === 0) { $usePattern = $possiblePatterns[0]; } else { $key = mt_rand(0, count($possiblePatterns) - 1); $usePattern = $possiblePatterns[$key]; } if ($usePattern->getBridgeCount() === 0) { $piece = $this->blankPuzzlePiece; } else { $piece = new puzzlePiece($usePattern); } $observer->setPuzzlePiece($piece); $this->{$this->mode}($observer); } }