Make the endings tolerable with actual apple lists.

master
sigonasr2 2 years ago
parent 6ddfab3871
commit e086651495
  1. 6
      data
  2. 20
      index.js

@ -1,7 +1,7 @@
Hit self
923
122
29350
129
29815
923
sigonasr2
sigonasr2

@ -321,21 +321,21 @@ snake.onTick = function(obj) { // When the game updates
}
if (Math.abs(diff_x) > Math.abs(diff_y)) {
if (diff_x > 0) {
if (dir !== RIGHT && findSafePath(LEFT, x - 1, y, targetX, targetY)) {
if (dir !== RIGHT && findSafePath(LEFT, x - 1, y, targetX, targetY,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== LEFT && findSafePath(RIGHT, x + 1, y, targetX, targetY)) {
if (dir !== LEFT && findSafePath(RIGHT, x + 1, y, targetX, targetY,appleDepth)) {
return true;
}
}
} else {
if (diff_y > 0) {
if (dir !== DOWN && findSafePath(UP, x, y - 1, targetX, targetY)) {
if (dir !== DOWN && findSafePath(UP, x, y - 1, targetX, targetY,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== UP && findSafePath(DOWN, x, y + 1, targetX, targetY)) {
if (dir !== UP && findSafePath(DOWN, x, y + 1, targetX, targetY,appleDepth)) {
return true;
}
}
@ -429,6 +429,11 @@ snake.onTick = function(obj) { // When the game updates
console.log("No viable path, just survive for now...")
TEST_REGIONS = []
EXTRA_MOVEMENT=false
APPLES_LIST=
snake.apples()
.filter((a)=>a[0]!==bestApp.x&&a[1]!==bestApp.y) //I want apples furthest away to be checked first. These are probably the safest calculations to make.
.sort((a,b)=>Math.sqrt(Math.pow(snake.x-b[0],2)+Math.pow(snake.y-b[1],2))-Math.sqrt(Math.pow(snake.x-a[0],2)+Math.pow(snake.y-a[1],2)))
if (snake.x !== 0 && snake.y !== 0) {
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 0, 0)) {
setDirection(UP);
@ -450,6 +455,11 @@ snake.onTick = function(obj) { // When the game updates
TEST_REGIONS = []
EXTRA_MOVEMENT=false
console.log("Last resort...")
APPLES_LIST=
snake.apples()
.filter((a)=>a[0]!==bestApp.x&&a[1]!==bestApp.y) //I want apples furthest away to be checked first. These are probably the safest calculations to make.
.sort((a,b)=>Math.sqrt(Math.pow(snake.x-b[0],2)+Math.pow(snake.y-b[1],2))-Math.sqrt(Math.pow(snake.x-a[0],2)+Math.pow(snake.y-a[1],2)))
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 149, 149)) {
setDirection(UP);
return;
@ -466,7 +476,7 @@ snake.onTick = function(obj) { // When the game updates
setDirection(DOWN);
return;
}
console.log("Good luck....")
TEST_REGIONS = []
EXTRA_MOVEMENT=false
if (spotIsFree(snake.me().direction, x + (snake.me().direction === RIGHT ? 1 : snake.me().direction === LEFT ? -1 : 0), y + (snake.me().direction === DOWN ? 1 : snake.me().direction === UP ? -1 : 0))) {

Loading…
Cancel
Save