snake: don't add the snake itself to path
This commit is contained in:
parent
33d5c491c2
commit
f59e7cf747
@ -214,7 +214,6 @@ class Bot {
|
|||||||
continue;
|
continue;
|
||||||
if (isBitSet(g_snake.board[location.y][location.x], BoardState.SNAKE)) {
|
if (isBitSet(g_snake.board[location.y][location.x], BoardState.SNAKE)) {
|
||||||
reachedSnake = true;
|
reachedSnake = true;
|
||||||
this.path.push(location);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var delta = new Point;
|
var delta = new Point;
|
||||||
@ -240,6 +239,9 @@ class Bot {
|
|||||||
4 = down
|
4 = down
|
||||||
*/
|
*/
|
||||||
nextMove() {
|
nextMove() {
|
||||||
|
// Get new path to food
|
||||||
|
if (this.path.length !== 0)
|
||||||
|
this.pathRefresh();
|
||||||
var next: Point = new Point;
|
var next: Point = new Point;
|
||||||
next.copy(this.path.pop());
|
next.copy(this.path.pop());
|
||||||
var delta = new Point;
|
var delta = new Point;
|
||||||
@ -256,8 +258,6 @@ class Bot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pathRefresh() {
|
pathRefresh() {
|
||||||
if (this.path.length !== 0)
|
|
||||||
return;
|
|
||||||
this.bfs();
|
this.bfs();
|
||||||
this.trim();
|
this.trim();
|
||||||
this.unvisit();
|
this.unvisit();
|
||||||
@ -273,9 +273,6 @@ function snakeloop() {
|
|||||||
if (g_snake.gameover)
|
if (g_snake.gameover)
|
||||||
g_snake.reset();
|
g_snake.reset();
|
||||||
|
|
||||||
// Get new path to food
|
|
||||||
g_snakebot.pathRefresh();
|
|
||||||
|
|
||||||
// Simulate movement of snake
|
// Simulate movement of snake
|
||||||
g_snake.simulate();
|
g_snake.simulate();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user