32 comments

[ 3.0 ms ] story [ 69.8 ms ] thread
My best is 61: Left to 26, Right to 38, Up to 54, Right to 61.

Is there a JavaScript API for programatically controlling this game?

63: Down to 5, right to 20, up to 25, right to 30, left to 38, up to 45, left to 48, up to 57, left to 63.

I've also got up to 65 on similar strategies, but that's the best one I've got written down.

I got 66 but I didn't track the steps. I'll try to get there again and document.
Diagonal moves by alternating directions are helpful.

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.

71: same as above up to 55, then left to 60, up to 65 and right to 71.
My best is 91. I can get to 80+ reliably by first going to one of the edges and attracting as many red squares as possible then dragging them to the other side of the screen. Seems like a fun training ground for an evolutionary algorithm.
126: down 25 up 37 left 53 up 59 right 63 up 69 right 72 up 73 right 77 up 83 right 89 down 93 right 95 down 97 right 101 down 105 right 113 down 119 left 122 down 124 left 126

Maybe room for improvement in the end game, this was my fourth try?

OP: It'd be nice if the game over screen showed the move sequence along with the score
240: 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
(comment deleted)
This is impressive. I can tell that you effectively group the red squares together, but I can't figure out exactly how you went about it. What was your thought process?
I wrote a solver that's just brute-forcing solutions. Specifically, it's doing a depth-first search through a tree where every node is a move with four child moves (left, up, right, and down).

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.

I made a JS snippet to parse/execute moves formatted like this:

  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')
248: left 26, up 27, right 30, up 33, left 36, up 41, right 44, up 45, right 48, down 51, right 52, down 55, left 62, down 69, right 74, down 75, right 76, down 79, right 80, down 82, right 86, down 91, right 92, down 93, right 98, up 101, right 102, up 103, right 104, up 105, right 106, up 107, right 110, up 114, right 118, up 119, right 122, up 127, left 130, up 131, left 132, up 133, left 134, up 135, left 136, up 139, left 142, up 143, left 144, up 147, left 150, up 153, left 154, up 155, left 160, down 163, left 166, down 169, left 177, down 185, right 189, down 193, right 195, down 197, right 200, down 203, right 206, down 209, right 210, down 213, right 218, up 221, right 222, up 223, right 224, up 225, right 226, up 227, right 230, up 233, right 236, up 239, right 243, down 244, up 247, left 248
346: 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 174, up 179, left 180, up 181, right 184, up 189, left 190, up 192, right 193, up 194, right 195, up 196, right 202, down 205, right 207, down 209, right 212, down 215, right 219, down 221, right 226, up 227, right 230, down 237, left 241, down 243, left 244, down 247, left 248, down 249, left 252, down 253, left 254, down 257, left 258, down 259, left 262, down 263, left 264, down 267, left 272, up 275, left 277, up 279, left 283, up 286, left 287, up 289, left 293, up 299, right 302, up 303, right 304, up 308, right 311, up 313, right 316, up 321, left 323, up 326, right 332, down 335, right 338, down 341, right 344, down 346
(comment deleted)
Please fix the rendering on Firefox by adding `image-rendering: crisp-edges;` to the canvas.
Looking at the bottom of the JS file [1], it looks like OP already started working on a genetic algorithm for this. I don't have time right now, but for anyone who's curious to try, you can just call

  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 :-)

1. https://smitop.com/square-game/rpg.js

I think living state, score and x,y position is all you would need to train a player. Is there any advantage to consuming the state of nearby cells if the game is entirely deterministic?
`mutate` in this code means "altering state". It does NOT hint at a "genetic algorithm". This game is solvable using floodfill where each floodfill state is a series of moves and the boundary condition is whether you've ended up alive or dead.
Just to be clear, I shouldn’t expect this to work on a phone, right?
Considering there is no win condition I think the "War Games" mantra applies.
Highest score posted here before comments are closed wins!
got 91, fun it's sort of like live action mine sweeper.
I got to 65, and from what I can tell the 'exploitable' pattern is that when an enemy to the side follows you for 'n' squares, it will join the 'queue' behind you, allowing you to play a game of inverse snake.
497: left 26, up 27, right 30, up 33, left 36, up 41, right 44, up 45, right 48, down 51, right 52, down 55, left 62, down 69, right 74, down 75, right 76, down 79, right 80, down 82, right 87, down 93, right 98, up 102, right 104, up 105, right 106, up 107, right 110, up 113, right 115, up 116, right 122, up 127, left 130, up 133, left 136, up 139, left 142, up 143, left 144, up 147, left 150, up 153, left 154, up 155, left 160, down 163, left 165, down 167, left 177, up 178, down 183, right 184, down 187, right 190, down 193, right 195, down 197, right 200, down 203, right 205, down 206, right 208, down 215, right 220, up 223, right 224, up 225, right 226, up 227, right 229, up 230, right 236, up 237, right 238, up 240, right 242, up 247, left 252, up 255, left 258, up 261, left 263, up 265, left 266, up 267, left 268, up 269, left 270, up 271, left 272, up 275, left 276, up 277, left 282, down 285, left 286, down 287, left 293, down 299, left 303, down 309, right 311, down 312, right 314, down 315, right 316, down 317, right 318, down 323, right 328, down 333, right 334, down 335, right 340, up 343, right 344, up 345, right 346, up 347, right 348, up 349, right 352, up 353, right 355, up 357, right 358, up 361, right 366, up 371, left 375, up 377, left 378, up 379, left 380, up 381, left 382, up 385, left 387, up 389, left 392, up 397, left 404, down 407, left 410, down 412, left 415, down 421, left 425, down 426, left 427, up 428, left 429, down 435, right 438, down 439, right 440, down 445, right 448, down 449, right 452, down 457, right 458, down 459, right 464, up 467, right 468, up 469, right 470, up 471, right 474, up 475, right 476, up 477, right 478, up 479, right 480, up 482, right 486, up 487, right 490, up 495, left 497
526: left 7, up 18, left 19, up 20, right 25, up 26, right 27, down 28, left 29, up 32, right 33, left 34, up 35, right 36, down 42, right 43, left 44, down 46, right 50, down 51, right 52, down 54, right 58, down 59, right 64, down 69, left 72, down 73, left 74, down 75, left 76, down 80, left 82, down 86, left 87, down 91, left 96, up 99, left 101, up 103, left 106, up 108, left 112, up 117, left 121, up 127, right 130, up 131, right 132, up 134, right 135, up 143, left 144, up 146, right 154, down 157, right 159, down 161, right 164, down 167, right 170, down 171, right 172, down 173, right 174, down 175, right 181, down 187, left 190, down 191, left 192, down 193, left 194, down 197, left 199, down 201, left 203, down 204, left 205, down 208, left 209, down 211, left 216, up 219, left 220, up 221, left 227, up 231, left 232, up 233, left 235, up 236, left 239, up 241, left 242, up 247, right 250, up 251, right 252, up 257, right 258, up 260, right 261, up 262, right 263, up 266, right 267, up 268, right 274, down 277, right 279, down 281, right 284, down 287, right 290, down 291, right 292, down 293, right 295, down 296, right 300, down 301, right 302, down 307, left 311, down 313, left 314, down 317, left 318, down 319, left 323, down 325, left 326, down 330, left 336, up 339, left 340, up 341, left 349, up 353, right 354, up 355, left 357, up 358, left 361, up 367, right 371, up 378, right 380, up 381, right 386, up 391, right 398, down 403, right 408, up 409, right 410, down 415, right 422, down 429, left 432, down 433, left 434, down 435, left 436, down 439, left 440, down 441, left 444, down 446, left 447, down 449, left 450, down 451, left 454, down 457, left 458, down 459, left 464, up 467, left 468, up 469, left 470, up 471, left 472, up 473, left 475, up 476, left 481, up 483, left 484, up 491, right 494, up 500, right 503, up 504, right 508, up 513, right 514, up 516, left 518, up 519, right 524, down 526