title: DFS algorithm maze generator
body: <p>I'm trying to use the DFS algo to create a maze in ASCII ('#' represents a wall and ' ' a free space) that has as start the upper left corner and as exit the lower right corner. The problem is the maze starts its creation and then it's blocked because all its neighbors have been already visited.</p>
  
  <p>I start at the upper left corner, mark the cell as visited and put a ' ' (it represents a free space), then I chose randomly a neighbor of the cell and I do the same. However I put this in a while loop and I'm sure this isn't the good idea.</p>
  
  <p>Here my attempt of the DFS :</p>
  
  <pre><code>int     generation(t_maze *maze, int pos_y, int pos_x)                                                                                                                                                              
  {                                                                                                                                                                                                                   
    int   dest;                                                                                                                                                                                                       
  
    maze-&gt;maze[pos_y][pos_x] = ' ';                                                                                                                                                                                   
    maze-&gt;visited[pos_y][pos_x] = '1';                                                                                                                                                                                
    while (maze-&gt;maze[maze-&gt;height - 1][maze-&gt;width - 1] == '#')                                                                                                                                                      
      {                                                                                                                                                                                                               
        if ((dest = my_rand(1, 4)) == 1 &amp;&amp; pos_y - 1 &gt;= 0 &amp;&amp; maze-&gt;visited[pos_y - 1][pos_x] == '0')                                                                                                                  
          generation(maze, pos_y - 1, pos_x);                                                                                                                                                                         
        else if (dest == 2 &amp;&amp; pos_x + 1 &lt; maze-&gt;width &amp;&amp; maze-&gt;visited[pos_y][pos_x + 1] == '0')                                                                                                                      
          generation(maze, pos_y, pos_x + 1);                                                                                                                                                                         
        else if (dest == 3 &amp;&amp; pos_y + 1 &lt; maze-&gt;height &amp;&amp; maze-&gt;visited[pos_y + 1][pos_x] == '0')                                                                                                                     
          generation(maze, pos_y + 1, pos_x);                                                                                                                                                                         
        else if (dest == 4 &amp;&amp; pos_x - 1 &gt;= 0 &amp;&amp; maze-&gt;visited[pos_y][pos_x - 1] == '0')                                                                                                                               
          generation(maze, pos_y, pos_x - 1);                                                                                                                                                                         
        my_showtab(maze-&gt;maze); //it prints the 2d array                                                                                                                                                                                      
        usleep(50000);                                                                                                                                                                                                
      }  
  
  
  typedef struct  s_maze                                                                                                                                                                                              
  {                                                                                                                                                                                                                   
    int           width;                                                                                                                                                                                              
    int           height;                                                                                                                                                                                             
    char          **maze;                                                                                                                                                                                             
    char          **visited;                                                                                                                                                                                          
  }               t_maze; 
  </code></pre>
  
  <p>In the structure,
  width is the width of the maze
  height is the height of the maze
  maze is a 2D array that is supposed to be filled with ' ' and '#'
  visited is a 2D array with 0 and 1, 0 : unvisited, 1 : visited</p>
  
  <p>I want to have a maze like this (little example)</p>
  
  <pre><code> ########
        # #
   ##     #
   #  #
  #######  
  </code></pre>