title: C++ finding distance between two points in 2D array
body: <p>I'm working with inheritance right now, which I'm having no problem with.
  I have this vector of strings (basically a 2D array of char's).</p>
  
  <p>The exact middle is where the shark is and the character of the shark
  changes based on where the other fish are.</p>
  
  <p>For example</p>
  
  <pre><code>.....
  .....
  ^.l..
  .....
  .....
  </code></pre>
  
  <p>The arrows are where the fish are and since the fish is to the left. The shark becomes a 'l'</p>
  
  <pre><code>.&gt;...
  .....
  ..u..
  .....
  .....
  </code></pre>
  
  <p>The arrows are where the fish are and since the fish is up. The shark becomes a 'u'</p>
  
  <p>The code I had to do this correctly is this:</p>
  
  <pre><code>void Shark::point(std::vector&lt;std::string&gt;&amp; map){
  
  if (map[0][0] != '.' || map[1][0] != '.' || map[2][0] != '.' || map[3][0] != '.' || map[4][0] != '.' || map[1][1] != '.' || map[2][1] != '.' || map[3][1] != '.'){
  ProtoFish::m_direction = Direction::left;
  }
  if (map[0][1] != '.' || map[0][2] != '.' || map[0][3] != '.' || map[1][2] != '.'){
  ProtoFish::m_direction = Direction::up;
  }
  if (map[4][1] != '.' || map[4][2] != '.' || map[4][3] != '.' || map[3][2] != '.'){
  ProtoFish::m_direction = Direction::down;
  }
  if (map[0][4] != '.' || map[1][4] != '.' || map[2][4] != '.' || map[3][4] != '.' || map[4][4] != '.' || map[1][3] != '.' || map[2][3] != '.' || map[3][3] != '.'){
  ProtoFish::m_direction = Direction::right;
  }
  }
  </code></pre>
  
  <p>I am basically just checking if the fish are in this map:</p>
  
  <pre><code>    l u u u r
      l l u r r
      l l . r r
      l l d r r
      l d d d r
  </code></pre>
  
  <p>where if the '.' char doesn't exist that's where a fish is, so the Shark should point in that direction.</p>
  
  <p>The problem occurs where there are multiple fish.</p>
  
  <pre><code>&gt;....
  ..&gt;..
  ..*..
  .&gt;...
  ..^&gt;.
  </code></pre>
  
  <p>I understand what I'm supposed to do, but I have no idea of how to do it, or how to even get started. The goal is just to get the Shark facing the same direction of the nearest fish. So basically the arrow "closest" to the middle.
  Can someone help me out to get started with this?
  Maybe like a separate function that calculates the distance of each element from the center?</p>