snake: attempt to move path refresh to post-regen
This commit is contained in:
parent
727e13a1c9
commit
86ef363d3b
10
src/snake.ts
10
src/snake.ts
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user