
Show HN: Square Game - smitop
https://smitop.com/square-game/
======
bschne
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](https://smitop.com/square-
game/rpg.js)

~~~
personjerry
`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.

------
TurplePurtle
Please fix the rendering on Firefox by adding `image-rendering: crisp-edges;`
to the canvas.

~~~
smitop
Fixed, thanks!

------
umvi
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?

~~~
csallen
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

~~~
benburk
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

~~~
csallen
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

~~~
benburk
Can you share the code you used to calculate these?

~~~
csallen
[https://gist.github.com/courthead/3d41cc03edda1e596051129b44...](https://gist.github.com/courthead/3d41cc03edda1e596051129b445fca17)

------
benburk
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

------
chris_st
Similar in some ways to the ancient "Daleks" terminal game.

~~~
nvahalik
I remember it being called robots:
[https://en.wikipedia.org/wiki/Chase_(video_game)](https://en.wikipedia.org/wiki/Chase_\(video_game\))

------
tempsq
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

------
iandanforth
Considering there is no win condition I think the "War Games" mantra applies.

~~~
quickthrower2
Highest score posted here before comments are closed wins!

------
natpalmer1776
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.

------
tobr
Just to be clear, I shouldn’t expect this to work on a phone, right?

------
surewhynat
got 91, fun it's sort of like live action mine sweeper.

