Last active
July 16, 2016 14:49
-
-
Save markusos/bd58f2ee6abc2e4010cb to your computer and use it in GitHub Desktop.
Solves the color tests on www.kuku-kube.com automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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