title: JavaScript - Trying to find direction based on distance
body: <p>I am trying to create a simple treasure hunt game using input boxes that act as both input fields and game display. The game has a hero - h and multiple killers - k, controlled by the computer, that try to kill the hero.</p>
  
  <p>Here is an example board that I have:</p>
  
  <p><img src="https://i.imgur.com/iDuViak.png" alt="example board"></p>
  
  <p>So far I have hard coded some if statements to check the coordinates of the hero and a given killer (based on the input box that they are currently in) to figure out which way the killer should move (up,down,right,left and diagonally). However, it does not always find the best direction to go for.</p>
  
  <pre><code>if (killerX &lt; heroX) {
    if (killerY &lt; heroY) {
      console.log("move down andright");
    } else if (killerY &gt; heroY) {
      console.log("move up and right");
    }
  }
  </code></pre>
  
  <p>I was thinking about using Dijkstra's algorithm but I do not know how to implement it for my given problem. I am looking for a more efficient alternative for finding which way the killer has to move in order to get closer to the hero.</p>