snake: attempt to move path refresh to post-regen

This commit is contained in:
Trianta 2024-11-05 21:11:46 -06:00
parent 727e13a1c9
commit 86ef363d3b

View File

@ -255,8 +255,8 @@ class Bot {
return next; return next;
} }
autoplay() { pathRefresh() {
if (this.path.length > 0) if (this.path.length !== 0)
return; return;
this.bfs(); this.bfs();
this.trim(); this.trim();
@ -273,14 +273,14 @@ function snakeloop() {
if (g_snake.gameover) if (g_snake.gameover)
g_snake.reset(); g_snake.reset();
// Input
g_snakebot.autoplay();
g_snake.simulate(); g_snake.simulate();
// Regenerate food if needed // Regenerate food if needed
g_snake.foodRegen(); g_snake.foodRegen();
// Get new path to food
g_snakebot.pathRefresh();
g_snake.draw(); g_snake.draw();
} }