Created
February 21, 2022 03:50
-
-
Save topher200/aead3fd53b0f26bf880e7752eb8ba70a to your computer and use it in GitHub Desktop.
Auto-solver for https://0xf00ff00f.github.io/rotator/
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
const SLEEP_TIME_MS = 50; | |
// for example, if this is 0.001 we will click randomly every ~1000 loops | |
const RANDOM_CLICK_CHANCE = 0.1; | |
const NUM_LOOPS = 1; | |
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); | |
function sample(array) { | |
return array[Math.floor(Math.random() \* array.length)]; | |
} | |
async function clickInCanvas(x, y) { | |
console.log(`clicking (${x},${y})`); | |
document.getElementById("canvas").dispatchEvent( | |
new MouseEvent( | |
"mousedown", // or "click" if the canvas listens for such an event | |
{ | |
clientX: x, | |
clientY: y, | |
bubbles: true | |
} | |
) | |
); | |
} | |
async function iterateThroughAllGuesses() { | |
// Iterate through each of the pieces, trying it against every other piece | |
shapeCoordinates = [ | |
{ x: 200, y: 150 }, | |
{ x: 650, y: 150 }, | |
{ x: 850, y: 150 }, | |
{ x: 200, y: 490 }, | |
{ x: 650, y: 490 }, | |
{ x: 850, y: 490 } | |
]; | |
for (let cursor1 of shapeCoordinates) { | |
// click the first piece | |
await clickInCanvas(cursor1.x, cursor1.y); | |
for (let cursor2 of shapeCoordinates) { | |
// click each of the other pieces. click them each twice! | |
if (cursor1 == cursor2) { | |
continue; | |
} | |
await clickInCanvas(cursor2.x, cursor2.y); | |
await sleep(SLEEP_TIME_MS); | |
await clickInCanvas(cursor2.x, cursor2.y); | |
await sleep(SLEEP_TIME_MS); | |
// randomly click a shape every few loops loops because | |
// the canvas can get in a weird state. the weird | |
// state happens because we keep clicking while | |
// the "you found a shape!" animation plays, which means | |
// that the loop sometimes starts with a shape already selected | |
if (Math.random() <= RANDOM_CLICK_CHANCE) { | |
console.log('random click!'); | |
cursorRandom = sample(shapeCoordinates); | |
await clickInCanvas(cursorRandom.x, cursorRandom.y); | |
} | |
} | |
// crap, the first piece didn't match anyone. turn it off and try the next one! | |
await clickInCanvas(cursor1.x, cursor1.y); | |
} | |
} | |
async function run() { | |
for (i = 0; i < NUM_LOOPS; i++) { | |
await iterateThroughAllGuesses(); | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment