So I got to playing 2048 a decent amount, and starting getting the feeling that there was a 'pattern' that would win this game for me. Perhaps you've had the same thought! As a result, I wrote a little snippet of code that that cycles throw the keys Up, Right, Down, Left (feel free to create your own pattern).
Copy and paste this into your Chrome/Firefox console to automate 2048!
function pressKey(i) {
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent ("keydown", true, true, window, 0, 0, 0, 0, 37+i%4, 37+i%4);
document.dispatchEvent(evt);
window.setTimeout(function(){pressKey(i+1);}, 500);
}
pressKey(0);
Note: Chrome has an initKeyboardEvent bug that causes KeyboardEvent.keyCode and KeyboardEvent.which to be readonly (e.g. always 0), so we overwrite it as below. This workaround taken from stackoverflow
Podium = {};
Podium.keydown = function(k) {
var oEvent = document.createEvent('KeyboardEvent');
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get : function() {
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'which', {
get : function() {
return this.keyCodeVal;
}
});
if (oEvent.initKeyboardEvent) {
oEvent.initKeyboardEvent("keydown", true, true, document.defaultView, k, k, "", "", false, "");
} else {
oEvent.initKeyEvent("keydown", true, true, document.defaultView, false, false, false, false, k, 0);
}
oEvent.keyCodeVal = k;
if (oEvent.keyCode !== k) {
alert("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")");
}
document.dispatchEvent(oEvent);
}
function pressKey(i) {
Podium.keydown(37+i%4);
window.setTimeout(function(){pressKey(i+1);}, 500);
}
pressKey(0);
Firefox 46