User prompt
create a globlal for round duration
Code edit (1 edits merged)
Please save this source code
User prompt
when there are 2 rows of vials move 1st row up by 300 and 2nd row by 500 relatively to current y positions
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Map is not a constructor' in or related to this line: 'var visitedStates = new Map();' Line Number: 458
User prompt
Please fix the bug: 'TypeError: Set is not a constructor' in or related to this line: 'var visitedStates = new Set();' Line Number: 458
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.Set is not a constructor' in or related to this line: 'var visitedStates = new LK.Set();' Line Number: 392
User prompt
Please fix the bug: 'TypeError: Set is not a constructor' in or related to this line: 'var visitedStates = new Set();' Line Number: 392
User prompt
Please fix the bug: 'TypeError: LK.Set is not a constructor' in or related to this line: 'var visitedStates = new LK.Set();' Line Number: 392
User prompt
Please fix the bug: 'TypeError: Set is not a constructor' in or related to this line: 'var visitedStates = new Set();' Line Number: 392
User prompt
Please fix the bug: 'TypeError: LK.Set is not a constructor' in or related to this line: 'var visitedStates = new LK.Set();' Line Number: 392
User prompt
Please fix the bug: 'TypeError: Set is not a constructor' in or related to this line: 'var visitedStates = new Set();' Line Number: 392
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Set is not a constructor' in or related to this line: 'var visitedStates = new Set();' Line Number: 415
Code edit (1 edits merged)
Please save this source code
User prompt
Early Termination: Implement a check to terminate the isSolvable function early if a violating condition is met during the solving process. For example, if a vial overflows or a color combination is already proven impossible, stop the evaluation and return false.
Code edit (1 edits merged)
Please save this source code
User prompt
When a vial is selected then an invalid tap is made, reset the selection status
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'if (self.vials && self.vials.length > 0) {' Line Number: 606
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'if (self.vials && self.vials.length > 0) {' Line Number: 606
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'self.vials.forEach(function (vial) {' Line Number: 606
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'self.vials.forEach(function (vial) {' Line Number: 604
User prompt
In init round also reset vial selection state
/**** * Classes ****/ var Liquid = Container.expand(function (color) { var self = Container.call(this); self.color = color; var liquidGraphics = self.attachAsset(color, { anchorX: 0.5, anchorY: 0.0 }); return self; }); var LiquidBase = Container.expand(function (color) { var self = Container.call(this); self.color = color; var liquidGraphics = self.attachAsset('liquidBase', { anchorX: 0.5, anchorY: 0.0 }); liquidGraphics.tint = colorList[color]; return self; }); var Vial = Container.expand(function () { var self = Container.call(this); // Attach graphical representation var tubeGraphics = self.attachAsset('tube', { anchorX: 0.5, anchorY: 0.0, alpha: 0.5 }); self.fillHeight = tubeGraphics.height - 25 - 100; self.baseLiquidY = tubeGraphics.height - 25; self.addChild(tubeGraphics); self.liquids = []; // Initialize functional representation self.addLiquid = function (liquid, ratio) { if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === liquid.color) { self.liquids[self.liquids.length - 1].ratio += ratio; } else { if (ratio > 0) { var newLiquid = { color: liquid.color, index: self.liquids.length, ratio: ratio }; self.liquids.push(newLiquid); } } }; self.removeLiquid = function (ratio) { if (self.liquids.length > 0) { var topLiquid = self.liquids[self.liquids.length - 1]; if (ratio >= topLiquid.ratio) { var removedLiquid = self.liquids.pop(); if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === removedLiquid.color) { self.liquids[self.liquids.length - 1].ratio += removedLiquid.ratio; } return removedLiquid; } else { topLiquid.ratio -= ratio; return { color: topLiquid.color, ratio: ratio }; } } return null; }; self.containsPoint = function (point) { var bounds = self.getBounds(); return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y + bounds.height; }; self.canPour = function (destinationTube) { if (self.liquids.length === 0) { return 0; // No liquid to pour } if (destinationTube.liquids.length === 0) { return 1; // Destination tube is empty, can pour all } var topLiquid = self.liquids[self.liquids.length - 1]; var destinationTopLiquid = destinationTube.liquids[destinationTube.liquids.length - 1]; if (topLiquid.color !== destinationTopLiquid.color) { return 0; // Different colors, cannot pour } var sameColorCount = 0; for (var i = self.liquids.length - 1; i >= 0; i--) { if (self.liquids[i].color === topLiquid.color) { sameColorCount++; } else { break; } } var totalRatio = destinationTube.liquids.reduce(function (sum, liquid) { return sum + liquid.ratio; }, 0); var availableSpace = 1 - totalRatio; return Math.min(sameColorCount, availableSpace) / sameColorCount; }; self.renderLiquids = function () { // Remove all existing liquid graphics for (var i = self.children.length - 1; i >= 0; i--) { if (self.children[i] !== tubeGraphics) { self.removeChild(self.children[i]); } } // Add new liquid graphics based on the current state of self.liquids var cumulativeHeight = 0; for (var j = 0; j < self.liquids.length; j++) { var liquid = self.liquids[j]; var liquidGraphics = self.attachAsset('liquidBase', { anchorX: 0.5, anchorY: 1.0 }); liquidGraphics.tint = colorList[liquid.color]; liquidGraphics.y = self.baseLiquidY - cumulativeHeight; // Adjust the offset to prevent liquids from appearing out of the vial bottom liquidGraphics.height = self.fillHeight * liquid.ratio; cumulativeHeight += liquidGraphics.height; self.addChildAt(liquidGraphics, 0); // Add debug text for liquidGraphics.y for index 0 and tubeGraphics.height if (j === 0) { updateDebugText('.y for index 0: ' + liquidGraphics.y + ' | .height: ' + tubeGraphics.height); } } }; self.down = function (x, y, obj) { var liquidInfo = self.liquids.map(function (liquid) { return liquid.color + ": " + liquid.ratio; }).join(", "); updateDebugText("Vial : " + liquidInfo); if (selectedTube === self) { self.scale.set(1, 1); // Reset the scale of the selected tube self.y += selectionYOffset; // Restore the tube to its initial position selectedTube = null; // Unselect the tube } else if (selectedTube) { var pourRatio = selectedTube.canPour(self); if (pourRatio > 0) { var liquid = selectedTube.removeLiquid(pourRatio); self.addLiquid(liquid, liquid.ratio); selectedTube.renderLiquids(); self.renderLiquids(); selectedTube.y += selectionYOffset; // Restore the previously selected tube to its initial position selectedTube.scale.set(1, 1); // Reset the scale of the previously selected tube selectedTube = null; if (puzzleManager.checkWinCondition()) { // Level up and initialize a new round currentLevel++; levelTxt.setText('Level: ' + currentLevel); initRound(); } } else { if (selectedTube) { selectedTube.scale.set(1, 1); // Reset the scale if selection is wrong selectedTube.y += selectionYOffset; // Restore the previously selected tube to its initial position } selectedTube = null; } } else { selectedTube = self; self.y -= selectionYOffset; // Move the selected tube up by selectionYOffset } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var distributionConfigurations = []; function deepCopyVials(vials) { return vials.map(function (vial) { var newVial = new Vial(); vial.liquids.forEach(function (liquid) { newVial.addLiquid(new LiquidBase(liquid.color), liquid.ratio); }); return newVial; }); } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) { throw o; } } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) { return _arrayLikeToArray(r, a); } var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; } var colorList = { blue: 0x0000FF, // DodgerBlue green: 0x00FF00, // LimeGreen red: 0xFF0000, // OrangeRed white: 0xFFFFFF, // White yellow: 0xFFFF00, // Yellow purple: 0x800080, // Purple cyan: 0x00FFFF, // Cyan magenta: 0xFF00FF, // Magenta orange: 0xFFA500, // Orange pink: 0xFFC0CB // Pink }; var selectionYOffset = 300; // Function to update debug text function updateDebugText(info) { if (debugTxt) { debugTxt.setText(info); } } // Create an instance of the PuzzleManager var PuzzleManager = function PuzzleManager() { var self = this; self.liquids = []; // Public property to store liquids self.initVials = function () { var nbVials = Math.min(currentLevel + 1, 10); self.vials = []; for (var i = 0; i < nbVials; i++) { self.vials.push(new Vial()); } var positions = []; var maxPerLine = 5; var spacingX = 2048 / (Math.min(nbVials, maxPerLine) + 1); var spacingY = 2732 / Math.ceil(nbVials / maxPerLine); for (var i = 0; i < nbVials; i++) { positions.push({ x: spacingX * (i % maxPerLine + 1), y: spacingY * Math.floor(i / maxPerLine) + 600 }); } for (var i = 0; i < self.vials.length; i++) { self.vials[i].x = positions[i].x; self.vials[i].y = positions[i].y; game.addChild(self.vials[i]); } }; // Initialize liquids self.initLiquids = function (level) { // Create and initialize liquid objects based on level if (level === 1) { self.liquids = [new LiquidBase('green')]; } else { if (level === 2) { self.liquids = [new LiquidBase('blue'), new LiquidBase('green')]; } else { self.liquids = []; for (var i = 0; i < level; i++) { var colorName = Object.keys(colorList)[i % Object.keys(colorList).length]; self.liquids.push(new LiquidBase(colorName)); } } } }; self.distributeLiquids = function () { if (self.vials.length === 0) { return; } if (currentLevel === 1) { self.vials[0].addLiquid(self.liquids[0], 0.25); self.vials[1].addLiquid(self.liquids[0], 0.75); } else if (currentLevel === 2) { self.vials[0].addLiquid(self.liquids[0], 0.5); self.vials[1].addLiquid(self.liquids[1], 0.5); self.vials[2].addLiquid(self.liquids[0], 0.5); self.vials[2].addLiquid(self.liquids[1], 0.5); } else { var totalPortions = (self.vials.length - 1) * (1 / BASE_LIQUID_RATIO); var portions = []; // Create portions array self.liquids.forEach(function (liquid) { for (var i = 0; i < totalPortions / self.liquids.length; i++) { portions.push(liquid.color); } }); var maxAttempts = 1000; var attempts = 0; while (attempts < maxAttempts) { // Shuffle portions for (var i = portions.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = portions[i]; portions[i] = portions[j]; portions[j] = temp; } // Clear previous liquids self.vials.forEach(function (vial) { vial.liquids = []; }); // Distribute portions var portionIndex = 0; for (var i = 0; i < self.vials.length - 1; i++) { var vialPortions = totalPortions / (self.vials.length - 1); for (var j = 0; j < vialPortions; j++) { var color = portions[portionIndex++]; var liquid = self.liquids.find(function (l) { return l.color === color; }); if (liquid) { self.vials[i].addLiquid(liquid, BASE_LIQUID_RATIO); } } } if (self.isSolvable()) { break; } attempts++; } if (attempts >= maxAttempts) { console.error("Failed to generate a solvable puzzle after " + maxAttempts + " attempts"); } // Store the distribution configuration distributionConfigurations.push(deepCopyVials(self.vials)); } }; self.isSolvable = function () { var visitedStates = new Set(); var stateQueue = []; function serializeState(vials) { return vials.map(function (vial) { return vial.liquids.map(function (liquid) { return liquid.color + ":" + liquid.ratio; }).join(","); }).join("|"); } function isSolved(vials) { return vials.every(function (vial) { return vial.liquids.length === 0 || vial.liquids.length === 1 / BASE_LIQUID_RATIO && vial.liquids.every(function (liquid) { return liquid.color === vial.liquids[0].color; }); }); } stateQueue.push(deepCopyVials(self.vials)); visitedStates.add(serializeState(self.vials)); var maxStates = 10000; // Limit the number of states to explore var statesExplored = 0; while (stateQueue.length > 0 && statesExplored < maxStates) { var currentState = stateQueue.shift(); if (isSolved(currentState)) { return true; } for (var i = 0; i < currentState.length; i++) { for (var j = 0; j < currentState.length; j++) { if (i !== j && currentState[i].canPour(currentState[j]) > 0) { var newVials = deepCopyVials(currentState); var liquid = newVials[i].removeLiquid(newVials[i].canPour(newVials[j])); newVials[j].addLiquid(liquid, liquid.ratio); var serializedState = serializeState(newVials); if (!visitedStates.has(serializedState)) { visitedStates.add(serializedState); stateQueue.push(newVials); } } } } statesExplored++; } return false; }; self.reloadDistribution = function (index) { if (index >= 0 && index < distributionConfigurations.length) { var savedVials = distributionConfigurations[index]; if (self.vials && Array.isArray(self.vials) && self.vials.length > 0) { self.vials.forEach(function (vial, i) { if (savedVials[i]) { vial.liquids = savedVials[i].liquids.map(function (liquid) { return { color: liquid.color, ratio: liquid.ratio }; }); vial.renderLiquids(); } }); } } }; // Check for win conditions self.checkWinCondition = function () { // Implement logic to check if the puzzle is solved var colorArray = []; if (!self.vials || self.vials.length === 0) { return false; // No vials to check } for (var i = 0; i < self.vials.length; i++) { if (self.vials[i].liquids.length > 0) { var firstColor = self.vials[i].liquids[0].color; if (colorArray.indexOf(firstColor) !== -1) { return false; // Color already found in another vial } colorArray.push(firstColor); for (var j = 1; j < self.vials[i].liquids.length; j++) { if (self.vials[i].liquids[j].color !== firstColor) { return false; // Different colors in the same vial } } } } return true; }; // Initialize the puzzle manager self.init = function (level) { self.initVials(); self.initLiquids(level); self.distributeLiquids(); for (var i = 0; i < self.vials.length; i++) { self.vials[i].renderLiquids(); } updateDebugText('Puzzle Solvable: ' + self.isSolvable()); }; return self; }; var BASE_LIQUID_RATIO = 0.25; var currentLevel = 4; // TEMP DEBUG 1; var score = 0; var scoreTxt; var timerTxt; var debugTxt; // Function to update score function updateScore(newScore) { score = newScore; if (scoreTxt) { if (newScore) { scoreTxt.setText(newScore.toString()); } else { scoreTxt.setText('0'); } } } // Function to update timer function updateTimer(newTime) { timeLeft = newTime; timerTxt.setText(timeLeft.toString()); } // Game update function game.update = function () { // Update timer if (LK.ticks % 60 == 0) { // Decrease time every second updateTimer(timeLeft - 1); if (timeLeft <= 0) { if (selectedTube) { selectedTube.scale.set(1, 1); // Reset the scale of the selected tube // Update debug text with current time and score updateDebugText('Time: ' + timeLeft + ' | Score: ' + score); } if (distributionConfigurations.length > 0) { puzzleManager.reloadDistribution(distributionConfigurations.length - 1); } // Reset the time counter updateTimer(30); } } }; function initUI() { scoreTxt = new Text2('0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); timerTxt = new Text2('60', { size: 100, fill: "#ffffff" }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); // Create debug text debugTxt = new Text2('Debug Info', { size: 50, fill: "#FFFFFF" }); debugTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(debugTxt); levelTxt = new Text2('Level: ' + currentLevel, { size: 100, fill: "#ffffff" }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); } // Function to initialize the game function initializeGame() { score = 0; // Initialize the score with 0 updateScore(score); initUI(); puzzleManager = new PuzzleManager(); initRound(); updateTimer(timeLeft); } initializeGame(); function initRound() { // Remove previous vials if (puzzleManager.vials) { for (var i = 0; i < puzzleManager.vials.length; i++) { game.removeChild(puzzleManager.vials[i]); } } distributionConfigurations = []; puzzleManager.init(currentLevel); selectedTube = null; if (puzzleManager.vials && puzzleManager.vials.length > 0) { puzzleManager.vials.forEach(function (vial) { vial.scale.set(1, 1); // Reset the scale of each vial vial.y += selectionYOffset; // Restore each vial to its initial position }); } timeLeft = 30; // Initialize the timer with 60 seconds }
===================================================================
--- original.js
+++ change.js
@@ -379,9 +379,9 @@
distributionConfigurations.push(deepCopyVials(self.vials));
}
};
self.isSolvable = function () {
- var visitedStates = new LK.Set();
+ var visitedStates = new Set();
var stateQueue = [];
function serializeState(vials) {
return vials.map(function (vial) {
return vial.liquids.map(function (liquid) {
Basic white Restart icon (rounded arrow). UI
Une classe d’une école de sorcière sans les élèves.
un sablier de sorcière.
a bubble.
exploded broken glass
Yound generously beautifull teacher witch smiling, with glasses, a black witch hat, holding a little brown book in her hands and looking at the camera. wearing light black clothes. Torso head and hat should appear.
tap
Sound effect
drop
Sound effect
reset
Sound effect
wrong
Sound effect
yes
Sound effect
goodJob
Sound effect
pouring
Sound effect
welcome
Sound effect
rememberTheRules
Sound effect
letsgo
Sound effect
hurryUp
Sound effect
boom
Sound effect
tryAgain
Sound effect
rainbowBoom
Sound effect
youDidIt
Sound effect
letmetry
Sound effect
rainbowMix
Sound effect
thankYou1
Sound effect
thankYou2
Sound effect
thankYou3
Sound effect
thankYou4
Sound effect
bonusTime
Sound effect