snake: fix snake body skipping placement half the time

This commit is contained in:
Trianta 2024-09-01 05:05:49 -05:00
parent f975b0a045
commit 8e626448a2

View File

@ -259,13 +259,12 @@ class Bot {
} }
autoplay() { autoplay() {
if (this.path.length === 0) { if (this.path.length > 0)
return;
this.bfs(); this.bfs();
this.trim(); this.trim();
this.unvisit(); this.unvisit();
} }
return this.nextMove();
}
} }
const snake: SnakeCore = new SnakeCore(); // Singleton for snake game const snake: SnakeCore = new SnakeCore(); // Singleton for snake game
@ -276,6 +275,7 @@ function snakeloop() {
// Reset of needed // Reset of needed
if (snake.gameover) if (snake.gameover)
snake.reset(); snake.reset();
// Input // Input
bot.autoplay(); bot.autoplay();