Merge changes

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

@ -1,7 +1,7 @@
Hit self Hit other
923 923
500 500
62775 62775
954 954
Bot 5653 Bot 5653

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

Loading…
Cancel
Save