From 3702e60f95ea5adf898e2242a4f838a0203c9cc3 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 16 Aug 2022 12:56:53 +0000 Subject: [PATCH] We will now make sure we are safe pathing to an apple in reverse hierarchy --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6849132..6440235 100644 --- a/index.js +++ b/index.js @@ -323,8 +323,11 @@ snake.onTick = function(obj) { // When the game updates //TODO Try different apples here before trying to "just survive". There may be a better path. console.log("Okay maybe this apple wasn't such a good idea... Try another one.") - - for (var apple of snake.apples()) { + APPLES_LIST= + snake.apples() + .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))) + for (var apple of APPLES_LIST) { TEST_REGIONS = [] EXTRA_MOVEMENT=false var adjacentBodies=0;