Reset blocked regions when trying new iterations

master
sigonasr2, Sig, Sigo 2 years ago
parent c3b0f2e2dc
commit fcfd6e1e98
  1. 48
      index.js

@ -25,8 +25,8 @@ horz_dir = LEFT
vert_dir = UP
LAST_DEATH = ""
BEST_LENGTH = 744
TOTAL_ATTEMPTS = 36
TOTAL_LENGTH = 7848
TOTAL_ATTEMPTS = 37
TOTAL_LENGTH = 8066
LAST_LENGTH = 0
BEST_SEEN = 764
BEST_SEEN_WHO = "Bot 2578"
@ -187,28 +187,32 @@ snake.onTick = function(obj) { // When the game updates
if (--appleDepth===0) {
return true;
} else {
var newApple = APPLES_LIST.shift()
targetApp={x:newApple[0],y:newApple[1]}
diff_x = x - targetApp.x
diff_y = y - targetApp.y
if (Math.abs(diff_x) > Math.abs(diff_y)) {
if (diff_x > 0) {
if (dir !== RIGHT && findPath(LEFT, x - 1, y,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== LEFT && findPath(RIGHT, x + 1, y,appleDepth)) {
return true;
var myRegions = [...TEST_REGIONS]
while (APPLES_LIST.length>0) {
var newApple = APPLES_LIST.shift()
TEST_REGIONS=[...myRegions]
targetApp={x:newApple[0],y:newApple[1]}
diff_x = x - targetApp.x
diff_y = y - targetApp.y
if (Math.abs(diff_x) > Math.abs(diff_y)) {
if (diff_x > 0) {
if (dir !== RIGHT && findPath(LEFT, x - 1, y,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== LEFT && findPath(RIGHT, x + 1, y,appleDepth)) {
return true;
}
}
}
} else {
if (diff_y > 0) {
if (dir !== DOWN && findPath(UP, x, y - 1,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== UP && findPath(DOWN, x, y + 1,appleDepth)) {
return true;
if (diff_y > 0) {
if (dir !== DOWN && findPath(UP, x, y - 1,appleDepth)) {
return true;
} //Preferred direction found.
} else {
if (dir !== UP && findPath(DOWN, x, y + 1,appleDepth)) {
return true;
}
}
}
}

Loading…
Cancel
Save