Skip to content

Instantly share code, notes, and snippets.

@markusos
Last active July 16, 2016 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusos/bd58f2ee6abc2e4010cb to your computer and use it in GitHub Desktop.
Save markusos/bd58f2ee6abc2e4010cb to your computer and use it in GitHub Desktop.
Solves the color tests on www.kuku-kube.com automatically
/* KukuKube Solver
*
* Solves the color tests on www.kuku-kube.com automatically.
* To run this, run the javascript code below in the browsers developer console.
* The script identifies the uniquely colored box in the box grid and uses javascript to click on it.
*
* WARNING: Don't run the script if you have epilepsy! It will flash different colors fast when it solves the color tests.
*
* MIT License (MIT)
* Copyright (c) 2015 Markus Östberg
*/
var KukuKube = function ($) {
function startTest() {
var start = $('.play-btn:visible');
if (start.size() === 1) {
start.first().click();
solveKukuKube();
} else {
console.log('Could not find start button. Are you sure this is www.kuku-kube.com ?')
}
}
function solveKukuKube() {
var boxes = $("#box").find("span");
// Get the color of the first box as a baseline
var color = boxes.first().css('backgroundColor');
var colorCount = 0, secondColorCount = 0;
var colorPosition, secondColorPosition;
boxes.each(function(i) {
// Count color occurrences
if ($(this).css('backgroundColor') === color) {
colorCount += 1;
colorPosition = i;
} else {
secondColorCount += 1;
secondColorPosition = i;
}
// If one color count is exactly one and the other is larger then 2,
// then we have found the unique square in the color test.
if (secondColorCount === 1 && colorCount >= 2) {
boxes[secondColorPosition].click();
return false;
}
if (colorCount === 1 && secondColorCount >= 2) {
boxes[colorPosition].click();
return false;
}
});
// Check if game is over
if ($('.gameover:visible').size() > 0) {
console.log('Game Over!');
}
else {
// Game is still running, solve the next one!
setTimeout(solveKukuKube, 10);
}
}
return {
init: function () {
startTest();
}
};
}(jQuery);
jQuery(KukuKube.init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment