From fcfd6e1e9883fbbb9d01f60bb3a0314096e358cf Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 16 Aug 2022 12:34:56 +0000 Subject: [PATCH] Reset blocked regions when trying new iterations --- index.js | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index ee5cfc9..b410410 100644 --- a/index.js +++ b/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; + } } } }