We will now make sure we are safe pathing to an apple in reverse hierarchy

master
sigonasr2, Sig, Sigo 2 years ago
parent 00694b7006
commit 3702e60f95
  1. 7
      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;

Loading…
Cancel
Save