title: How can I make something move in a specific order in a matrix?
body: <p>So I got this problem: I want to move from a black point to another like this:</p>
  
  <p><img src="https://i.stack.imgur.com/2l8Ni.png" alt="enter image description here"></p>
  
  <p>but whenever I try to do it, it moves like this:</p>
  
  <p><img src="https://i.stack.imgur.com/K7UdJ.png" alt="enter image description here"></p>
  
  <p>You can move only in 1 direction: north, south, east, and west at a time. 
  I tried to do something like this:</p>
  
  <pre><code>        int distance = game.Distance(myPirate.Loc,loc);
          List&lt;Direction&gt; allDirections = new List&lt;Direction&gt;() { Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, Direction.NOTHING };
          Location destination;
          foreach (Direction dir in allDirections)
          {
              destination = game.Destination(myPirate, dir);
              int distance2 = game.Distance(destination, loc);
              if (distance2 &lt; distance) return dir;
          }
          return Direction.NOTHING;
  </code></pre>
  
  <p>But whenever I try this code I get these results:</p>
  
  <p><img src="https://i.stack.imgur.com/K7UdJ.png" alt="enter image description here"></p>
  
  <p>Can anyone help me figure out how to move like the 1st picture and not like the 2nd one? You get the location of the 2 black squares in the matrix.
  If you need anything more, tell me.</p>