I have x,y coordinates board like this:
the board is up to 100x100.
Where myPosition is gold, destinations is green and collisions is red. myPosition
is object destinations
and collisions
are array of objects:
let myPosition={x:0,y:0};
let destinations = [{x: 0, y: 5}, {x: 2, y: 0}, {x: 2, y: 2}];
let collisions = [{x: 1, y: 0},{x: 1, y: 1},{x: 1, y: 2},{x: 1, y: 3},{x: 1, y: 4},{x: 2, y: 1},{x: 2, y: 0},{x: 2, y: 1}]
With this code (live demo) I'm able to find nearest destination but it doesn't know about collisions at all. I can not figure how to write algorithm which additionally would check for collision and give ouput 0,5
in above scenerio.
There is also assumption that we can not move diagonally.
I found this SO answer which seems to provide answer to my question but I can not get it to work with my input arrays.