title: Algorithm to traverse grid of connected paths
body: <p>I am trying to figure out an algorithm that will allow me to traverse a grid of connected paths that I have created so that I can determine if there are any paths that are not connected. For example, see the image below of my grid: </p>
  
  <p><a href="https://i.stack.imgur.com/X2nX3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2nX3.png" alt="enter image description here"></a></p>
  
  <p>Everything works fine, the only problem is the block near the bottom left corner that is not connected to anything. I want all the paths to be connected to each other in some way.</p>
  
  <p>So I need to write an algorithm that works through the grid and determines if there are blocks that are not connected.</p>
  
  <p>Currently, the grid is build using a two-dimensional array, as follows:</p>
  
  <pre><code>for(var x = 0; x &lt; 10; x++){
          hz[x] = new Array(10);
  
          for(var y = 0; y &lt; 10; y++){
              hz[x][y] = new block(0, 0, 0, 0);
          }
      }
  </code></pre>
  
  <p>Each element in the array contains an object of type <code>block</code>, as follows: </p>
  
  <pre><code>function block(top, bottom, left, right){
      this.top = top;
      this.bottom = bottom;
      this.left = left;
      this.right = right;
  }
  </code></pre>
  
  <p>To determine the paths, I have a bunch of code that randomly assigns edges to each element by making the <code>left</code>, <code>top</code>, <code>bottom</code> and/or <code>right</code> values true or false. There are additional conditions for blocks on the edge. Each block is then assigned an image based on which of its values are true and false.</p>
  
  <p>Please can you help me to figure out some sort of algorithm that lets me traverse this structure to check if each block is connected.</p>