Reset blocked regions when trying new iterations
This commit is contained in:
parent
c3b0f2e2dc
commit
fcfd6e1e98
48
index.js
48
index.js
@ -25,8 +25,8 @@ horz_dir = LEFT
|
|||||||
vert_dir = UP
|
vert_dir = UP
|
||||||
LAST_DEATH = ""
|
LAST_DEATH = ""
|
||||||
BEST_LENGTH = 744
|
BEST_LENGTH = 744
|
||||||
TOTAL_ATTEMPTS = 36
|
TOTAL_ATTEMPTS = 37
|
||||||
TOTAL_LENGTH = 7848
|
TOTAL_LENGTH = 8066
|
||||||
LAST_LENGTH = 0
|
LAST_LENGTH = 0
|
||||||
BEST_SEEN = 764
|
BEST_SEEN = 764
|
||||||
BEST_SEEN_WHO = "Bot 2578"
|
BEST_SEEN_WHO = "Bot 2578"
|
||||||
@ -187,28 +187,32 @@ snake.onTick = function(obj) { // When the game updates
|
|||||||
if (--appleDepth===0) {
|
if (--appleDepth===0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
var newApple = APPLES_LIST.shift()
|
var myRegions = [...TEST_REGIONS]
|
||||||
targetApp={x:newApple[0],y:newApple[1]}
|
while (APPLES_LIST.length>0) {
|
||||||
diff_x = x - targetApp.x
|
var newApple = APPLES_LIST.shift()
|
||||||
diff_y = y - targetApp.y
|
TEST_REGIONS=[...myRegions]
|
||||||
if (Math.abs(diff_x) > Math.abs(diff_y)) {
|
targetApp={x:newApple[0],y:newApple[1]}
|
||||||
if (diff_x > 0) {
|
diff_x = x - targetApp.x
|
||||||
if (dir !== RIGHT && findPath(LEFT, x - 1, y,appleDepth)) {
|
diff_y = y - targetApp.y
|
||||||
return true;
|
if (Math.abs(diff_x) > Math.abs(diff_y)) {
|
||||||
} //Preferred direction found.
|
if (diff_x > 0) {
|
||||||
} else {
|
if (dir !== RIGHT && findPath(LEFT, x - 1, y,appleDepth)) {
|
||||||
if (dir !== LEFT && findPath(RIGHT, x + 1, y,appleDepth)) {
|
return true;
|
||||||
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 {
|
} else {
|
||||||
if (dir !== UP && findPath(DOWN, x, y + 1,appleDepth)) {
|
if (diff_y > 0) {
|
||||||
return true;
|
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…
x
Reference in New Issue
Block a user