diff --git a/src/snake.ts b/src/snake.ts index 841b846..a5051b9 100644 --- a/src/snake.ts +++ b/src/snake.ts @@ -255,8 +255,8 @@ class Bot { return next; } - autoplay() { - if (this.path.length > 0) + pathRefresh() { + if (this.path.length !== 0) return; this.bfs(); this.trim(); @@ -273,14 +273,14 @@ function snakeloop() { if (g_snake.gameover) g_snake.reset(); - // Input - g_snakebot.autoplay(); - g_snake.simulate(); // Regenerate food if needed g_snake.foodRegen(); + // Get new path to food + g_snakebot.pathRefresh(); + g_snake.draw(); }