diff --git a/orga/updateOrder.sql b/orga/updateOrder.sql new file mode 100644 index 0000000..5cfb27d --- /dev/null +++ b/orga/updateOrder.sql @@ -0,0 +1,33 @@ +UPDATE Level SET deleted = 0 WHERE renderer in (80,81,82,83); +UPDATE Level SET difficulty = 1000 WHERE deleted = 0 AND difficulty >= 80; + +UPDATE Level SET difficulty = 80 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 80 AND difficulty = 1000 LIMIT 7) temp); +UPDATE Level SET difficulty = 80 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 81 AND difficulty = 1000 LIMIT 7) temp); +UPDATE Level SET difficulty = 80 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 82 AND difficulty = 1000 LIMIT 8) temp); +UPDATE Level SET difficulty = 80 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 83 AND difficulty = 1000 LIMIT 7) temp); + +UPDATE Level SET difficulty = 90 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 83 AND difficulty = 1000 LIMIT 4) temp); +UPDATE Level SET difficulty = 90 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 82 AND difficulty = 1000 LIMIT 3) temp); +UPDATE Level SET difficulty = 90 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 81 AND difficulty = 1000 LIMIT 4) temp); +UPDATE Level SET difficulty = 90 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 80 AND difficulty = 1000 LIMIT 4) temp); +UPDATE Level SET difficulty = 90 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 100 AND difficulty = 1000 LIMIT 5) temp); + +UPDATE Level SET difficulty = 100 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 80 AND difficulty = 1000 LIMIT 2) temp); +UPDATE Level SET difficulty = 100 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 81 AND difficulty = 1000 LIMIT 3) temp); +UPDATE Level SET difficulty = 100 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 82 AND difficulty = 1000 LIMIT 2) temp); +UPDATE Level SET difficulty = 100 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 83 AND difficulty = 1000 LIMIT 3) temp); +UPDATE Level SET difficulty = 100 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 100 AND difficulty = 1000 LIMIT 10) temp); + +UPDATE Level SET difficulty = 110 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 80 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 110 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 81 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 110 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 82 AND difficulty = 1000 LIMIT 2) temp); +UPDATE Level SET difficulty = 110 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 83 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 110 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 100 AND difficulty = 1000 LIMIT 15) temp); + +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 80 AND difficulty = 1000 LIMIT 2) temp); +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 81 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 82 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 83 AND difficulty = 1000 LIMIT 1) temp); +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 100 AND difficulty = 1000 LIMIT 10) temp); +UPDATE Level SET difficulty = 120 WHERE id in ( SELECT * FROM (SELECT id FROM Level WHERE renderer = 110 AND difficulty = 1000 LIMIT 5) temp); + diff --git a/public/js/app.js b/public/js/app.js index d2b5790..3beeb0b 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -6474,11 +6474,11 @@ class ColumnSegment extends RowSegment{ // } } -class SimpleFourWordsLevel extends Level{ - constructor(templateContainer, wordLength, bigSegmentPosition) { +class BigSegmentsLevels extends Level{ + constructor(templateContainer, wordLength, bigSegmentPositions) { super(templateContainer); this.wordLength = wordLength; - this.bigSegmentPosition = bigSegmentPosition; + this.bigSegmentPositions = bigSegmentPositions; } createSegments() { @@ -6512,7 +6512,7 @@ class SimpleFourWordsLevel extends Level{ parents[1].addChild(leafsWords[3][2 * i + 1]); let parentSegment =null; - if (i === this.bigSegmentPosition){ + if (this.bigSegmentPositions.indexOf(i) !== -1){ parents[2] = new ParentSegment(this.templateContainer.copyParentTemplate()); parents[3] = new ParentSegment(this.templateContainer.copyParentTemplate()); @@ -6546,6 +6546,77 @@ class SimpleFourWordsLevel extends Level{ } } +class SimpleFourWordsLevel extends BigSegmentsLevels{ + constructor(templateContainer, wordLength, bigSegmentPosition) { + console.log(bigSegmentPosition, "P"); + super(templateContainer, wordLength, [bigSegmentPosition, 3]); + } + + // createSegments() { + // if (this.words.length >= 4 && + // this.words[0].length >= this.wordLength && + // this.words[1].length >= this.wordLength && + // this.words[2].length >= this.wordLength && + // this.words[3].length >= this.wordLength && + // this.wordLength >= 4 + // ) { + // let leafsWords = []; + // leafsWords[0] = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate()); + // leafsWords[1] = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate()); + // leafsWords[2] = Level._createLeafsForWord(this.words[2], this.templateContainer.copyLeafTemplate()); + // leafsWords[3] = Level._createLeafsForWord(this.words[3], this.templateContainer.copyLeafTemplate()); + // + // let rootSegment = new RowSegment(this.templateContainer.copyRowTemplate()); + // for (let i = 0; i < this.wordLength / 2; i++) { + // let parents = []; + // parents[0] = new ParentSegment(this.templateContainer.copyParentTemplate()); + // parents[1] = new ParentSegment(this.templateContainer.copyParentTemplate()); + // + // parents[0].addChild(leafsWords[0][2 * i]); + // parents[0].addChild(leafsWords[0][2 * i + 1]); + // parents[0].addChild(leafsWords[1][2 * i]); + // parents[0].addChild(leafsWords[1][2 * i + 1]); + // + // parents[1].addChild(leafsWords[2][2 * i]); + // parents[1].addChild(leafsWords[2][2 * i + 1]); + // parents[1].addChild(leafsWords[3][2 * i]); + // parents[1].addChild(leafsWords[3][2 * i + 1]); + // + // let parentSegment =null; + // if (i === this.bigSegmentPosition){ + // parents[2] = new ParentSegment(this.templateContainer.copyParentTemplate()); + // parents[3] = new ParentSegment(this.templateContainer.copyParentTemplate()); + // + // parents[2].addChild(leafsWords[0][2 * i + 2]); + // parents[2].addChild(leafsWords[0][2 * i + 3]); + // parents[2].addChild(leafsWords[1][2 * i + 2]); + // parents[2].addChild(leafsWords[1][2 * i + 3]); + // + // parents[3].addChild(leafsWords[2][2 * i + 2]); + // parents[3].addChild(leafsWords[2][2 * i + 3]); + // parents[3].addChild(leafsWords[3][2 * i + 2]); + // parents[3].addChild(leafsWords[3][2 * i + 3]); + // + // parentSegment = new ParentSegment(this.templateContainer.copyParentTemplate()); + // parentSegment.addChild(parents[0]); + // parentSegment.addChild(parents[2]); + // parentSegment.addChild(parents[1]); + // parentSegment.addChild(parents[3]); + // i++; + // } + // else{ + // parentSegment = new ColumnSegment(this.templateContainer.copyColumnTemplate()); + // parentSegment.addChild(parents[0]); + // parentSegment.addChild(parents[1]); + // } + // + // rootSegment.addChild(parentSegment); + // } + // this.setRootSegment(rootSegment) + // } + // } +} + class SimpleFourWordsLevel10_0 extends SimpleFourWordsLevel{ constructor(templateContainer) { super(templateContainer, 10, 0); diff --git a/src/module/Application/pwa/js/site/LevelSite.js b/src/module/Application/pwa/js/site/LevelSite.js index a0cdf47..f460871 100755 --- a/src/module/Application/pwa/js/site/LevelSite.js +++ b/src/module/Application/pwa/js/site/LevelSite.js @@ -148,7 +148,7 @@ export class LevelSite extends WordRotatorBaseSite { return this.nextLevel(); } - startEndSite(){ + startEndSite() { this.startSite(EndSite); this.finish(); } @@ -161,7 +161,7 @@ export class LevelSite extends WordRotatorBaseSite { const db = await WordRotatorDb.getInstance(); const nextLevelJson = await db.loadNextLevel(LevelSite.RENDERER_TYPES); - console.log("nextLevelJson", nextLevelJson); + console.log("nextLevelJson", nextLevelJson); if (nextLevelJson === null) { this.startEndSite(); return; @@ -391,7 +391,7 @@ export class LevelSite extends WordRotatorBaseSite { break; } - default:{ + default: { this._siteContent.classList.remove("tutorial"); } } @@ -421,7 +421,7 @@ export class LevelSite extends WordRotatorBaseSite { scaleHelper.scaleToFull(textElem, textElem.parentElement, null, true, 1, 2); break; } - default:{ + default: { this._siteContent.classList.remove("tutorial"); } } @@ -461,14 +461,15 @@ export class LevelSite extends WordRotatorBaseSite { break; } - default:{ + default: { this._siteContent.classList.remove("tutorial"); } } } } } -LevelSite.RENDERER_TYPES = [20, 40, 60, 80, 81, 82, 83, 100, 120, 140, 160]; + +LevelSite.RENDERER_TYPES = [20, 40, 60, 80, 81, 82, 83, 100, 110, 111, 112, 120, 140, 160]; LevelSite.TUTORIAL = { FIRST_LEVEL: 67, SECOND_LEVEL: 15, diff --git a/src/module/Application/pwa/js/wordrotator/Level/BigSegmentsLevels.js b/src/module/Application/pwa/js/wordrotator/Level/BigSegmentsLevels.js new file mode 100644 index 0000000..4a8946c --- /dev/null +++ b/src/module/Application/pwa/js/wordrotator/Level/BigSegmentsLevels.js @@ -0,0 +1,76 @@ +import {Level} from "./Level"; +import {RowSegment} from "../Segment/RowSegment"; +import {ParentSegment} from "../Segment/ParentSegment"; +import {ColumnSegment} from "../Segment/ColumnSegment"; + +export class BigSegmentsLevels extends Level{ + constructor(templateContainer, wordLength, bigSegmentPositions) { + super(templateContainer); + this.wordLength = wordLength; + this.bigSegmentPositions = bigSegmentPositions; + } + + createSegments() { + if (this.words.length >= 4 && + this.words[0].length >= this.wordLength && + this.words[1].length >= this.wordLength && + this.words[2].length >= this.wordLength && + this.words[3].length >= this.wordLength && + this.wordLength >= 4 + ) { + let leafsWords = []; + leafsWords[0] = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate()); + leafsWords[1] = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate()); + leafsWords[2] = Level._createLeafsForWord(this.words[2], this.templateContainer.copyLeafTemplate()); + leafsWords[3] = Level._createLeafsForWord(this.words[3], this.templateContainer.copyLeafTemplate()); + + let rootSegment = new RowSegment(this.templateContainer.copyRowTemplate()); + for (let i = 0; i < this.wordLength / 2; i++) { + let parents = []; + parents[0] = new ParentSegment(this.templateContainer.copyParentTemplate()); + parents[1] = new ParentSegment(this.templateContainer.copyParentTemplate()); + + parents[0].addChild(leafsWords[0][2 * i]); + parents[0].addChild(leafsWords[0][2 * i + 1]); + parents[0].addChild(leafsWords[1][2 * i]); + parents[0].addChild(leafsWords[1][2 * i + 1]); + + parents[1].addChild(leafsWords[2][2 * i]); + parents[1].addChild(leafsWords[2][2 * i + 1]); + parents[1].addChild(leafsWords[3][2 * i]); + parents[1].addChild(leafsWords[3][2 * i + 1]); + + let parentSegment =null; + if (this.bigSegmentPositions.indexOf(i) !== -1){ + parents[2] = new ParentSegment(this.templateContainer.copyParentTemplate()); + parents[3] = new ParentSegment(this.templateContainer.copyParentTemplate()); + + parents[2].addChild(leafsWords[0][2 * i + 2]); + parents[2].addChild(leafsWords[0][2 * i + 3]); + parents[2].addChild(leafsWords[1][2 * i + 2]); + parents[2].addChild(leafsWords[1][2 * i + 3]); + + parents[3].addChild(leafsWords[2][2 * i + 2]); + parents[3].addChild(leafsWords[2][2 * i + 3]); + parents[3].addChild(leafsWords[3][2 * i + 2]); + parents[3].addChild(leafsWords[3][2 * i + 3]); + + parentSegment = new ParentSegment(this.templateContainer.copyParentTemplate()); + parentSegment.addChild(parents[0]); + parentSegment.addChild(parents[2]); + parentSegment.addChild(parents[1]); + parentSegment.addChild(parents[3]); + i++; + } + else{ + parentSegment = new ColumnSegment(this.templateContainer.copyColumnTemplate()); + parentSegment.addChild(parents[0]); + parentSegment.addChild(parents[1]); + } + + rootSegment.addChild(parentSegment); + } + this.setRootSegment(rootSegment) + } + } +} \ No newline at end of file diff --git a/src/module/Application/pwa/js/wordrotator/Level/LevelHelper.js b/src/module/Application/pwa/js/wordrotator/Level/LevelHelper.js index fed5863..48b4f3e 100755 --- a/src/module/Application/pwa/js/wordrotator/Level/LevelHelper.js +++ b/src/module/Application/pwa/js/wordrotator/Level/LevelHelper.js @@ -9,6 +9,9 @@ import {SimpleFourWordsLevel10_0} from "./SimpleFourWordsLevel10_0"; import {SimpleFourWordsLevel10_1} from "./SimpleFourWordsLevel10_1"; import {SimpleFourWordsLevel10_2} from "./SimpleFourWordsLevel10_2"; import {SimpleFourWordsLevel10_3} from "./SimpleFourWordsLevel10_3"; +import {TwoSegmentFourWordsLevel10_0_3} from "./TwoSegmentFourWordsLevel10_0_3"; +import {TwoSegmentFourWordsLevel10_1_3} from "./TwoSegmentFourWordsLevel10_1_3"; +import {TwoSegmentFourWordsLevel10_0_2} from "./TwoSegmentFourWordsLevel10_0_2"; export class LevelHelper { static setLevelType(typeId, level) { @@ -44,6 +47,9 @@ LevelHelper.types = { 82: SimpleFourWordsLevel10_2, 83: SimpleFourWordsLevel10_3, 100: SixWordsRowLevel8, + 110: TwoSegmentFourWordsLevel10_0_3, + 111: TwoSegmentFourWordsLevel10_1_3, + 112: TwoSegmentFourWordsLevel10_0_2, 120: FourWordsLevel8, 140: SixWordsRowLevel12, 160: FourWordsLevel12, diff --git a/src/module/Application/pwa/js/wordrotator/Level/SimpleFourWordsLevel.js b/src/module/Application/pwa/js/wordrotator/Level/SimpleFourWordsLevel.js index 70b7adc..16266d0 100644 --- a/src/module/Application/pwa/js/wordrotator/Level/SimpleFourWordsLevel.js +++ b/src/module/Application/pwa/js/wordrotator/Level/SimpleFourWordsLevel.js @@ -1,76 +1,7 @@ -import {Level} from "./Level"; -import {RowSegment} from "../Segment/RowSegment"; -import {ParentSegment} from "../Segment/ParentSegment"; -import {ColumnSegment} from "../Segment/ColumnSegment"; +import {BigSegmentsLevels} from "./BigSegmentsLevels"; -export class SimpleFourWordsLevel extends Level{ +export class SimpleFourWordsLevel extends BigSegmentsLevels{ constructor(templateContainer, wordLength, bigSegmentPosition) { - super(templateContainer); - this.wordLength = wordLength; - this.bigSegmentPosition = bigSegmentPosition; - } - - createSegments() { - if (this.words.length >= 4 && - this.words[0].length >= this.wordLength && - this.words[1].length >= this.wordLength && - this.words[2].length >= this.wordLength && - this.words[3].length >= this.wordLength && - this.wordLength >= 4 - ) { - let leafsWords = []; - leafsWords[0] = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate()); - leafsWords[1] = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate()); - leafsWords[2] = Level._createLeafsForWord(this.words[2], this.templateContainer.copyLeafTemplate()); - leafsWords[3] = Level._createLeafsForWord(this.words[3], this.templateContainer.copyLeafTemplate()); - - let rootSegment = new RowSegment(this.templateContainer.copyRowTemplate()); - for (let i = 0; i < this.wordLength / 2; i++) { - let parents = []; - parents[0] = new ParentSegment(this.templateContainer.copyParentTemplate()); - parents[1] = new ParentSegment(this.templateContainer.copyParentTemplate()); - - parents[0].addChild(leafsWords[0][2 * i]); - parents[0].addChild(leafsWords[0][2 * i + 1]); - parents[0].addChild(leafsWords[1][2 * i]); - parents[0].addChild(leafsWords[1][2 * i + 1]); - - parents[1].addChild(leafsWords[2][2 * i]); - parents[1].addChild(leafsWords[2][2 * i + 1]); - parents[1].addChild(leafsWords[3][2 * i]); - parents[1].addChild(leafsWords[3][2 * i + 1]); - - let parentSegment =null; - if (i === this.bigSegmentPosition){ - parents[2] = new ParentSegment(this.templateContainer.copyParentTemplate()); - parents[3] = new ParentSegment(this.templateContainer.copyParentTemplate()); - - parents[2].addChild(leafsWords[0][2 * i + 2]); - parents[2].addChild(leafsWords[0][2 * i + 3]); - parents[2].addChild(leafsWords[1][2 * i + 2]); - parents[2].addChild(leafsWords[1][2 * i + 3]); - - parents[3].addChild(leafsWords[2][2 * i + 2]); - parents[3].addChild(leafsWords[2][2 * i + 3]); - parents[3].addChild(leafsWords[3][2 * i + 2]); - parents[3].addChild(leafsWords[3][2 * i + 3]); - - parentSegment = new ParentSegment(this.templateContainer.copyParentTemplate()); - parentSegment.addChild(parents[0]); - parentSegment.addChild(parents[2]); - parentSegment.addChild(parents[1]); - parentSegment.addChild(parents[3]); - i++; - } - else{ - parentSegment = new ColumnSegment(this.templateContainer.copyColumnTemplate()); - parentSegment.addChild(parents[0]); - parentSegment.addChild(parents[1]); - } - - rootSegment.addChild(parentSegment); - } - this.setRootSegment(rootSegment) - } + super(templateContainer, wordLength, [bigSegmentPosition]); } } \ No newline at end of file diff --git a/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_2.js b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_2.js new file mode 100644 index 0000000..c85614c --- /dev/null +++ b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_2.js @@ -0,0 +1,8 @@ +import {BigSegmentsLevels} from "./BigSegmentsLevels"; + +export class TwoSegmentFourWordsLevel10_0_2 extends BigSegmentsLevels{ + constructor(templateContainer) { + super(templateContainer, 10, [0,2]); + } +} + diff --git a/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_3.js b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_3.js new file mode 100644 index 0000000..54240dc --- /dev/null +++ b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_0_3.js @@ -0,0 +1,8 @@ +import {BigSegmentsLevels} from "./BigSegmentsLevels"; + +export class TwoSegmentFourWordsLevel10_0_3 extends BigSegmentsLevels{ + constructor(templateContainer) { + super(templateContainer, 10, [0,3]); + } +} + diff --git a/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_1_3.js b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_1_3.js new file mode 100644 index 0000000..cd2d226 --- /dev/null +++ b/src/module/Application/pwa/js/wordrotator/Level/TwoSegmentFourWordsLevel10_1_3.js @@ -0,0 +1,8 @@ +import {BigSegmentsLevels} from "./BigSegmentsLevels"; + +export class TwoSegmentFourWordsLevel10_1_3 extends BigSegmentsLevels{ + constructor(templateContainer) { + super(templateContainer, 10, [1,3]); + } +} + diff --git a/src/module/Application/src/Model/Manager/LevelManager.php b/src/module/Application/src/Model/Manager/LevelManager.php index 1a44d83..60e0ded 100755 --- a/src/module/Application/src/Model/Manager/LevelManager.php +++ b/src/module/Application/src/Model/Manager/LevelManager.php @@ -79,6 +79,11 @@ class LevelManager extends StandardManager return $returnArray; } + public function countWhere($whereArray) + { + return $this->repository->countWhere($whereArray); + } + public function getDoubleUsedWords() { $words = []; @@ -113,151 +118,210 @@ class LevelManager extends StandardManager public function generateLevels() { $levelsToGenerate = [ + //(0) 80 [ - "wordLength" => 12, + "wordLength" => 10, "numWords" => 4, - "numPositions" => 15, - "renderer" => 160, + "numPositions" => 11, + "renderer" => 80, "difficulty" => function () { - return 160; + return 1000; }, ], + //(1) 81 [ - "wordLength" => 8, + "wordLength" => 10, "numWords" => 4, - "numPositions" => 10, - "renderer" => 120, + "numPositions" => 11, + "renderer" => 81, "difficulty" => function () { - $propabillity = rand(1, 100); - if ($propabillity <= 2){ - return 160; - } - if ($propabillity <= 7){ - return 140; - } - return 120; + return 1000; }, ], + //(2) 82 [ - "wordLength" => 12, - "numWords" => 6, - "numPositions" => 21, - "renderer" => 140, + "wordLength" => 10, + "numWords" => 4, + "numPositions" => 11, + "renderer" => 82, "difficulty" => function () { - return ((rand(1, 100) <= 5) ? 160 : 140); + return 1000; }, ], + //(3) 83 + [ + "wordLength" => 10, + "numWords" => 4, + "numPositions" => 11, + "renderer" => 83, + "difficulty" => function () { + return 1000; + }, + ], + //(4) 100 [ "wordLength" => 8, "numWords" => 6, "numPositions" => 14, "renderer" => 100, "difficulty" => function () { - $propabillity = rand(1, 100); - if ($propabillity <= 2){ - return 140; - } - if ($propabillity <= 7){ - return 120; - } - return 100; + return 1000; }, ], + //(5) 110 [ "wordLength" => 10, "numWords" => 4, - "numPositions" => 11, - "renderer" => function(){ - $renderers = [80,81,82,83]; - return $renderers[rand(0, count($renderers) - 1)]; - }, + "numPositions" => 12, + "renderer" => 110, "difficulty" => function () { - return ((rand(1, 100) <= 2) ? 100: 80); + return 1000; + }, + ], + //(6) 111 + [ + "wordLength" => 10, + "numWords" => 4, + "numPositions" => 12, + "renderer" => 111, + "difficulty" => function () { + return 1000; + }, + ], + //(7) 112 + [ + "wordLength" => 10, + "numWords" => 4, + "numPositions" => 12, + "renderer" => 112, + "difficulty" => function () { + return 1000; + }, + ], + //(8) 120 + [ + "wordLength" => 8, + "numWords" => 4, + "numPositions" => 10, + "renderer" => 120, + "difficulty" => function () { + return 1000; + }, + ], + //(9) 140 + [ + "wordLength" => 12, + "numWords" => 6, + "numPositions" => 21, + "renderer" => 140, + "difficulty" => function () { + return 1000; + }, + ], + //(10) 160 + [ + "wordLength" => 12, + "numWords" => 4, + "numPositions" => 15, + "renderer" => 160, + "difficulty" => function () { + return 1000; }, ], -// [ -// "wordLength" => 10, -// "numWords" => 2, -// "numPositions" => 5, -// "renderer" => 60, -// "difficulty" => function () { -// return ((rand(1,100) <= 5)?100:60); -// }, -// ], -// [ -// "wordLength" => 8, -// "numWords" => 2, -// "numPositions" => 4, -// "renderer" => 40, -// "difficulty" => function () { -// return ((rand(1,100) <= 5)?120:100); -// }, -// ], - ]; - //Für höhere Wahrscheinlichkeiten - $levelsToGenerate[] = $levelsToGenerate[0]; - $levelsToGenerate[] = $levelsToGenerate[1]; + $creationRation = [ + 0 => 1, + 1 => 1, + 2 => 1, + 3 => 1, + 4 => 16, + 5 => 5.333333, + 6 => 5.333333, + 7 => 5.333333, + 8 => 24, + 9 => 28, + 10 => 52 + ]; + + $currentNumbers = []; + for ($i = 0; $i < count($levelsToGenerate); $i++) { + $currentNumbers[$i] = $this->countWhere(["renderer" => $levelsToGenerate[$i]["renderer"], "difficulty" => 1000]); + } + $levelGenerated = 0; + $currentIndex = count($levelsToGenerate) - 1; $words = []; do { // var_dump($levelsToGenerate); - $currentIndex = rand(0, count($levelsToGenerate) - 1); + if ($currentIndex === 0 || $currentNumbers[$currentIndex] >= $currentNumbers[0] * $creationRation[$currentIndex]) { + $currentIndex = ($currentIndex + 1) % count($levelsToGenerate); + } + + $words[$levelsToGenerate[$currentIndex]["wordLength"]] = $words[$levelsToGenerate[$currentIndex]["wordLength"]] ?? $this->wordManager->findWordsForLength($levelsToGenerate[$currentIndex]["wordLength"]); $currentWords = $words[$levelsToGenerate[$currentIndex]["wordLength"]]; -// var_dump(count($currentWords), $levelsToGenerate[$currentIndex]["numWords"]); - - if (count($currentWords) >= $levelsToGenerate[$currentIndex]["numWords"]) { - $selectedWords = []; - for ($i = 0; $i < $levelsToGenerate[$currentIndex]["numWords"]; $i++) { - $wordCount = count($currentWords); - $currentWordIndex = rand(0, $wordCount - 1); - $selectedWords[] = strtoupper($currentWords[$currentWordIndex]->getWord()); - $currentWords[$currentWordIndex]->setUsed(true); - $this->wordManager->save($currentWords[$currentWordIndex], false); - array_splice($currentWords, $currentWordIndex, 1); - } + $level = $this->generateLevelWithData($levelsToGenerate[$currentIndex], $currentWords); + if ($level) { $words[$levelsToGenerate[$currentIndex]["wordLength"]] = $currentWords; - $positions = []; - 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)); - $level->setPositions(json_encode($positions)); - $level->setDifficulty($levelsToGenerate[$currentIndex]["difficulty"]()); - $level->setLastUpdated(new \DateTime()); - $level->setLang(1); //German - $level->setDeleted(false); - - if (is_int($levelsToGenerate[$currentIndex]["renderer"])){ - $level->setRenderer($levelsToGenerate[$currentIndex]["renderer"]); - } - else{ - $level->setRenderer($levelsToGenerate[$currentIndex]["renderer"]()); - } - $this->save($level, false); - $levelGenerated++; + $currentNumbers[$currentIndex]++; } else { - array_splice($levelsToGenerate, $currentIndex, 1); + break; } - } while (count($levelsToGenerate) > 0 && $levelGenerated < 100); + } while (count($levelsToGenerate) > 0 && $levelGenerated < 180); $this->emFlush(); $this->wordManager->emFlush(); return $levelGenerated; } + + private function generateLevelWithData($levelData, &$words) + { + if (count($words) >= $levelData["numWords"]) { + $selectedWords = []; + for ($i = 0; $i < $levelData["numWords"]; $i++) { + $wordCount = count($words); + $currentWordIndex = rand(0, $wordCount - 1); + $selectedWords[] = strtoupper($words[$currentWordIndex]->getWord()); + $words[$currentWordIndex]->setUsed(true); + $this->wordManager->save($words[$currentWordIndex], false); + array_splice($words, $currentWordIndex, 1); + } + + $positions = []; + do { + for ($i = 0; $i < $levelData["numPositions"]; $i++) { + $positions[] = rand(0, 3); + } + } while (count(array_filter($positions, function ($position) { + return $position == 0; + })) / $levelData["numPositions"] >= 0.67); + + $level = new Level(); + $level->setWords(json_encode($selectedWords)); + $level->setPositions(json_encode($positions)); + $level->setDifficulty($levelData["difficulty"]()); + $level->setLastUpdated(new \DateTime()); + $level->setLang(1); //German + $level->setDeleted(false); + + if (is_int($levelData["renderer"])) { + $level->setRenderer($levelData["renderer"]); + } else { + $level->setRenderer($levelData["renderer"]()); + } + + return $level; + } else { + return null; + } + + } } \ No newline at end of file diff --git a/src/module/Application/src/Model/Repository/LevelRepository.php b/src/module/Application/src/Model/Repository/LevelRepository.php index 7fc2782..9baf017 100755 --- a/src/module/Application/src/Model/Repository/LevelRepository.php +++ b/src/module/Application/src/Model/Repository/LevelRepository.php @@ -18,8 +18,7 @@ class LevelRepository extends StandardRepository $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder->select("l")->from(Level::class, "l"); - if ($date != null) - { + if ($date != null) { $queryBuilder->andWhere($queryBuilder->expr()->gte("l.lastUpdated", ":fromDate")); $queryBuilder->setParameter("fromDate", $date->format("Y-m-d H:i:00")); } @@ -34,8 +33,7 @@ class LevelRepository extends StandardRepository $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder->select("COUNT(l.id) as number")->from(Level::class, "l"); - if ($date != null) - { + if ($date != null) { $queryBuilder->andWhere($queryBuilder->expr()->gte("l.lastUpdated", ":fromDate")); $queryBuilder->setParameter("fromDate", $date->format("Y-m-d H:i:00")); } @@ -50,12 +48,24 @@ class LevelRepository extends StandardRepository public function endTransaction() { - try{ + try { $this->_em->getConnection()->commit(); - } catch (\Exception $e) - { + } catch (\Exception $e) { $this->_em->getConnection()->rollBack(); throw $e; } } + + public function countWhere($whereArray) + { + $queryBuilder = $this->_em->createQueryBuilder(); + $queryBuilder->select("COUNT(l.id) as number")->from(Level::class, "l"); + + foreach ($whereArray as $field => $arg) { + $queryBuilder->andWhere($queryBuilder->expr()->eq("l.".$field, ":".$field)); + $queryBuilder->setParameter("".$field, $arg); + } + + return $queryBuilder->getQuery()->getSingleScalarResult(); + } } \ No newline at end of file