Show HN: Square Game
smitop.com
smitop.com
myRPG.parseKeyPress({keyCode: 40})
replacing keyCode with the respective key's code, to automate moves. The global variable "dead" should tell you if you've failed, and "score.innerText" should tell you how well you've done :-)Is there a JavaScript API for programatically controlling this game?
function parseMoves(str) {
const toks = str.split(',')
const moves = []
for (const tok of toks) {
const [dir, num] = tok.trim().split(' ')
moves.push(...new Array(num - moves.length).fill(dir))
}
return moves
}
function toCharCode(key) {
switch (key) {
case 'down':
return 40
case 'up':
return 38
case 'right':
return 39
case 'left':
return 37
}
}
async function doMoves(str) {
const moves = parseMoves(str)
for (const move of moves) {
await new Promise(resolve => setTimeout(resolve, 100))
myRPG.parseKeyPress({
keyCode: toCharCode(move)
})
}
}
doMoves('left 26, up 27, right 30, up 32, right 33, up 35, left 38, down 41, left 42, down 45, right 50, up 53, right 54, up 58, right 59, up 60, right 61, up 66, right 67, up 69, right 71, up 73, right 78, down 81, right 82, down 83, right 84, down 85, right 87, down 88, right 90, down 93, right 94, down 95, right 99, up 100, right 103, down 109, left 112, down 113, left 114, down 115, left 116, down 119, left 123, down 127, left 130, down 131, right 132, down 135, left 136, down 137, left 142, up 145, left 148, up 151, left 161, up 169, right 172, up 177, left 178, up 179, right 182, up 191, right 200, down 203, right 205, down 207, right 211, down 215, right 222, down 227, left 228, down 229, right 233, down 234, right 235, down 240')From what I can tell, the strategy is mostly what other people are doing by hand: go to one side, delay there to gather red dots for as long as possible, then move to an adjacent side. Repeat. The solver has a few tactical tricks as well, involving knowing how to get as close to red dots as possible without getting hit, and also how to move such that the dots group together.
I just posted a game with a score of 346 where you can see this quite clearly. It's able to actually get in more than two full laps around.
Maybe room for improvement in the end game, this was my fourth try?
I've also got up to 65 on similar strategies, but that's the best one I've got written down.
69: Alternate down/right to 18, up/right to 30, up to 32, right, left to 40, up to 46, left to 49, up to 55, left/up to 65, left to 69.