diff --git a/src/snake.ts b/src/snake.ts index 7bd6f1a..740564a 100644 --- a/src/snake.ts +++ b/src/snake.ts @@ -214,7 +214,6 @@ class Bot { continue; if (isBitSet(g_snake.board[location.y][location.x], BoardState.SNAKE)) { reachedSnake = true; - this.path.push(location); continue; } var delta = new Point; @@ -240,6 +239,9 @@ class Bot { 4 = down */ nextMove() { + // Get new path to food + if (this.path.length !== 0) + this.pathRefresh(); var next: Point = new Point; next.copy(this.path.pop()); var delta = new Point; @@ -256,8 +258,6 @@ class Bot { } pathRefresh() { - if (this.path.length !== 0) - return; this.bfs(); this.trim(); this.unvisit(); @@ -272,9 +272,6 @@ function snakeloop() { // Reset of needed if (g_snake.gameover) g_snake.reset(); - - // Get new path to food - g_snakebot.pathRefresh(); // Simulate movement of snake g_snake.simulate();