title: Check If All Tiles Are Connected
body: <p><img src="https://i.stack.imgur.com/3mifc.png" alt="enter image description here"></p>
  
  <p>Hi! I have an interesting problem. </p>
  
  <p>I have drawn in a HTML canvas a series of hexagons (ignore the dots)</p>
  
  <p>For each hexagon I have it's x and y coordinates of their center, that's how I identify them.</p>
  
  <p>I store the hexagons in an array called hexagons where I store Hexagons</p>
  
  <pre><code>    function Hexagon()
      {
          this.shape
          this.x
          this.y
      }
  </code></pre>
  
  <p>I have a function that returns an object with all the adjacent hexagons of a given hexagon</p>
  
  <pre><code>function get_adjacent_hexagons(hexagon)
  {
      var x = hexagon.x
      var y = hexagon.y
      var adjacents = []
      for(var i=0; i&lt;editor_hexagons.length; i++)
      {
          if(editor_hexagons[i].x === x &amp;&amp; editor_hexagons[i].y == y - (2*s))
          {
              adjacents.push(editor_hexagons[i])
          }
          if(editor_hexagons[i].x === x &amp;&amp; editor_hexagons[i].y == y + (2*s))
          {
              adjacents.push(editor_hexagons[i])  
          }
          if(editor_hexagons[i].x === x - (s*1.5) &amp;&amp; editor_hexagons[i].y == y - s)
          {
              adjacents.push(editor_hexagons[i])  
          }
          if(editor_hexagons[i].x === x - (s*1.5) &amp;&amp; editor_hexagons[i].y == y + s)
          {
              adjacents.push(editor_hexagons[i])  
          }
          if(editor_hexagons[i].x === x + (s*1.5) &amp;&amp; editor_hexagons[i].y == y - s)
          {
              adjacents.push(editor_hexagons[i])  
          }
          if(editor_hexagons[i].x === x + (s*1.5) &amp;&amp; editor_hexagons[i].y == y + s)
          {
              adjacents.push(editor_hexagons[i])  
          }
      }
      return adjacents
  }
  </code></pre>
  
  <p>Given this information, is it possible to make an algorithm to check if all the hexagons are connected</p>
  
  <p>That is if there is no hexagon or group of hexagons on their own? </p>
  
  <p>For example in the picture provided they are all connected.</p>
  
  <p>----- EDIT -----</p>
  
  <p>This seems to be working</p>
  
  <pre><code>function check_connection()
  {
      visited = []
      visit_hexagon(hexagons[0])
  }
  
  function visit_hexagon(hexagon)
  {
      var not_visited = true
      for(var i=0; i&lt;visited.length; i++)
      {
          if(visited[i] === hexagon)
          {
              not_visited = false
              break
          }
      }
      if(not_visited)
      {
          visited.push(hexagon)
          var adjacents = get_adjacent_hexagons(hexagon)
          for(var i=0; i&lt;adjacents.length; i++)
          {
              visit_hexagon(adjacents[i])
          }
      }
  }
  </code></pre>