Merge changes

master
sigonasr2 2 years ago
commit 4e03338291
  1. 2
      data
  2. 59
      index.js

@ -1,4 +1,4 @@
Hit self
Hit other
923
500
62775

@ -34,8 +34,7 @@ ${BEST_SEEN_WHO}
`
*/
horz_dir = LEFT
vert_dir = UP
myDir = RIGHT
LAST_DEATH = vals[0]
BEST_LENGTH = Number(vals[1])
TOTAL_ATTEMPTS = Number(vals[2])
@ -167,8 +166,9 @@ snake.onTick = function(obj) { // When the game updates
}
function setDirection(dir) {
if (snake.me()?.direction!==dir) {
if (myDir!==dir) {
snake.setDirection(dir)
myDir=dir
}
}
@ -179,9 +179,11 @@ snake.onTick = function(obj) { // When the game updates
return false;
}
}
for (var i of snake.me()?.body) {
if (i[0] === newCoords[0] && i[1] === newCoords[1]) {
return false;
if (snake.me()) {
for (var i of snake.me()?.body) {
if (i[0] === newCoords[0] && i[1] === newCoords[1]) {
return false;
}
}
}
for (var i of snake.blackHoles()) {
@ -195,6 +197,9 @@ snake.onTick = function(obj) { // When the game updates
}
}
for (var i of snake.headPositions()) {
if (i[0]===snake.x&&y[1]===snake.y) {
continue; //Don't include our position in this.
}
if (i[0] === newCoords[0] && i[1] === newCoords[1]) {
return false;
}
@ -357,24 +362,24 @@ for (var i=10;i>5;i--) {
targetApp=bestApp
if (Math.abs(diff_x) > Math.abs(diff_y)) {
if (diff_x > 0) {
if (snake.me()?.direction !== RIGHT && findPath(LEFT, snake.x - 1, snake.y,i)) {
if (myDir !== RIGHT && findPath(LEFT, snake.x - 1, snake.y,i)) {
setDirection(LEFT);
return;
} //Preferred direction found.
} else {
if (snake.me()?.direction !== LEFT && findPath(RIGHT, snake.x + 1, snake.y,i)) {
if (myDir !== LEFT && findPath(RIGHT, snake.x + 1, snake.y,i)) {
setDirection(RIGHT);
return;
}
}
} else {
if (diff_y > 0) {
if (snake.me()?.direction !== DOWN && findPath(UP, snake.x, snake.y - 1,i)) {
if (myDir !== DOWN && findPath(UP, snake.x, snake.y - 1,i)) {
setDirection(UP);
return;
} //Preferred direction found.
} else {
if (snake.me()?.direction !== UP && findPath(DOWN, snake.x, snake.y + 1,i)) {
if (myDir !== UP && findPath(DOWN, snake.x, snake.y + 1,i)) {
setDirection(DOWN);
return;
}
@ -409,19 +414,19 @@ for (var i=10;i>5;i--) {
continue; //Skip this apple. It's dangerous.
}
if (snake.x !== 0 && snake.y !== 0) {
if (snake.me()?.direction !== DOWN && findSafePath(UP, snake.x, snake.y - 1, apple[0], apple[1])) {
if (myDir !== DOWN && findSafePath(UP, snake.x, snake.y - 1, apple[0], apple[1])) {
setDirection(UP);
return;
}
if (snake.me()?.direction !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, apple[0], apple[1])) {
if (myDir !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, apple[0], apple[1])) {
setDirection(LEFT);
return;
}
if (snake.me()?.direction !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, apple[0], apple[1])) {
if (myDir !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, apple[0], apple[1])) {
setDirection(RIGHT);
return;
}
if (snake.me()?.direction !== UP && findSafePath(DOWN, snake.x, snake.y + 1, apple[0], apple[1])) {
if (myDir !== UP && findSafePath(DOWN, snake.x, snake.y + 1, apple[0], apple[1])) {
setDirection(DOWN);
return;
}
@ -437,19 +442,19 @@ for (var i=10;i>5;i--) {
.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,1)) {
if (myDir !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 0, 0,1)) {
setDirection(UP);
return;
}
if (snake.me()?.direction !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, 0, 0,1)) {
if (myDir !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, 0, 0,1)) {
setDirection(LEFT);
return;
}
if (snake.me()?.direction !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, 0, 0,1)) {
if (myDir !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, 0, 0,1)) {
setDirection(RIGHT);
return;
}
if (snake.me()?.direction !== UP && findSafePath(DOWN, snake.x, snake.y + 1, 0, 0,1)) {
if (myDir !== UP && findSafePath(DOWN, snake.x, snake.y + 1, 0, 0,1)) {
setDirection(DOWN);
return;
}
@ -462,41 +467,41 @@ for (var i=10;i>5;i--) {
.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,1)) {
if (myDir !== DOWN && findSafePath(UP, snake.x, snake.y - 1, 149, 149,1)) {
setDirection(UP);
return;
}
if (snake.me()?.direction !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, 149, 149,1)) {
if (myDir !== RIGHT && findSafePath(LEFT, snake.x - 1, snake.y, 149, 149,1)) {
setDirection(LEFT);
return;
}
if (snake.me()?.direction !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, 149, 149,1)) {
if (myDir !== LEFT && findSafePath(RIGHT, snake.x + 1, snake.y, 149, 149,1)) {
setDirection(RIGHT);
return;
}
if (snake.me()?.direction !== UP && findSafePath(DOWN, snake.x, snake.y + 1, 149, 149,1)) {
if (myDir !== UP && findSafePath(DOWN, snake.x, snake.y + 1, 149, 149,1)) {
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))) {
if (spotIsFree(myDir, x + (myDir === RIGHT ? 1 : myDir === LEFT ? -1 : 0), y + (myDir === DOWN ? 1 : myDir === UP ? -1 : 0))) {
return;
} else
if (snake.me()?.direction !== UP && spotIsFree(DOWN, x, y + 1)) {
if (myDir !== UP && spotIsFree(DOWN, x, y + 1)) {
setDirection(DOWN)
return
} else
if (snake.me()?.direction !== RIGHT && spotIsFree(LEFT, x - 1, y)) {
if (myDir !== RIGHT && spotIsFree(LEFT, x - 1, y)) {
setDirection(LEFT)
return
} else
if (snake.me()?.direction !== LEFT && spotIsFree(RIGHT, x + 1, y)) {
if (myDir !== LEFT && spotIsFree(RIGHT, x + 1, y)) {
setDirection(RIGHT)
return
} else
if (snake.me()?.direction !== DOWN && spotIsFree(UP, x, y - 1)) {
if (myDir !== DOWN && spotIsFree(UP, x, y - 1)) {
setDirection(UP)
return
}

Loading…
Cancel
Save