diff --git a/src/module/Application/src/Model/Manager/LevelManager.php b/src/module/Application/src/Model/Manager/LevelManager.php index a68dcd7..141be5b 100755 --- a/src/module/Application/src/Model/Manager/LevelManager.php +++ b/src/module/Application/src/Model/Manager/LevelManager.php @@ -118,7 +118,7 @@ class LevelManager extends StandardManager "numWords" => 4, "numPositions" => 15, "renderer" => 160, - "difficulty" => function(){ + "difficulty" => function () { return 160; }, ], @@ -128,7 +128,7 @@ class LevelManager extends StandardManager "numPositions" => 10, "renderer" => 120, "difficulty" => function () { - return ((rand(1,100) <= 5)?140:120); + return ((rand(1, 100) <= 5) ? 140 : 120); }, ], [ @@ -137,7 +137,7 @@ class LevelManager extends StandardManager "numPositions" => 21, "renderer" => 140, "difficulty" => function () { - return ((rand(1,100) <= 5)?160:140); + return ((rand(1, 100) <= 5) ? 160 : 140); }, ], [ @@ -146,7 +146,7 @@ class LevelManager extends StandardManager "numPositions" => 14, "renderer" => 100, "difficulty" => function () { - return ((rand(1,100) <= 5)?120:100); + return ((rand(1, 100) <= 5) ? 120 : 100); }, ], // [ @@ -198,9 +198,13 @@ class LevelManager extends StandardManager } $words[$levelsToGenerate[$currentIndex]["wordLength"]] = $currentWords; $positions = []; - for ($i = 0; $i < $levelsToGenerate[$currentIndex]["numPositions"]; $i++) { - $positions[] = rand(0, 3); - } + do { + for ($i = 0; $i < $levelsToGenerate[$currentIndex]["numPositions"]; $i++) { + $positions[] = rand(0, 3); + } + } while (count(array_filter($positions, function($position) { + return $position == 0; + }))/$levelsToGenerate[$currentIndex]["numPositions"] >= 0.67); $level = new Level(); $level->setWords(json_encode($selectedWords)); @@ -217,7 +221,7 @@ class LevelManager extends StandardManager array_splice($levelsToGenerate, $currentIndex, 1); } - } while (count($levelsToGenerate) > 0 ); + } while (count($levelsToGenerate) > 0); $this->emFlush(); $this->wordManager->emFlush();