Make the endings tolerable with actual apple lists.
This commit is contained in:
parent
6ddfab3871
commit
e086651495
6
data
6
data
@ -1,7 +1,7 @@
|
|||||||
Hit self
|
Hit self
|
||||||
923
|
923
|
||||||
122
|
129
|
||||||
29350
|
29815
|
||||||
923
|
923
|
||||||
sigonasr2
|
sigonasr2
|
||||||
|
|
20
index.js
20
index.js
@ -321,21 +321,21 @@ snake.onTick = function(obj) { // When the game updates
|
|||||||
}
|
}
|
||||||
if (Math.abs(diff_x) > Math.abs(diff_y)) {
|
if (Math.abs(diff_x) > Math.abs(diff_y)) {
|
||||||
if (diff_x > 0) {
|
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;
|
return true;
|
||||||
} //Preferred direction found.
|
} //Preferred direction found.
|
||||||
} else {
|
} else {
|
||||||
if (dir !== LEFT && findSafePath(RIGHT, x + 1, y, targetX, targetY)) {
|
if (dir !== LEFT && findSafePath(RIGHT, x + 1, y, targetX, targetY,appleDepth)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (diff_y > 0) {
|
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;
|
return true;
|
||||||
} //Preferred direction found.
|
} //Preferred direction found.
|
||||||
} else {
|
} else {
|
||||||
if (dir !== UP && findSafePath(DOWN, x, y + 1, targetX, targetY)) {
|
if (dir !== UP && findSafePath(DOWN, x, y + 1, targetX, targetY,appleDepth)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -429,6 +429,11 @@ snake.onTick = function(obj) { // When the game updates
|
|||||||
console.log("No viable path, just survive for now...")
|
console.log("No viable path, just survive for now...")
|
||||||
TEST_REGIONS = []
|
TEST_REGIONS = []
|
||||||
EXTRA_MOVEMENT=false
|
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.x !== 0 && snake.y !== 0) {
|
||||||
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 0, 0)) {
|
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 0, 0)) {
|
||||||
setDirection(UP);
|
setDirection(UP);
|
||||||
@ -450,6 +455,11 @@ snake.onTick = function(obj) { // When the game updates
|
|||||||
TEST_REGIONS = []
|
TEST_REGIONS = []
|
||||||
EXTRA_MOVEMENT=false
|
EXTRA_MOVEMENT=false
|
||||||
console.log("Last resort...")
|
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)) {
|
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 149, 149)) {
|
||||||
setDirection(UP);
|
setDirection(UP);
|
||||||
return;
|
return;
|
||||||
@ -466,7 +476,7 @@ snake.onTick = function(obj) { // When the game updates
|
|||||||
setDirection(DOWN);
|
setDirection(DOWN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("Good luck....")
|
||||||
TEST_REGIONS = []
|
TEST_REGIONS = []
|
||||||
EXTRA_MOVEMENT=false
|
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))) {
|
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…
x
Reference in New Issue
Block a user