Classic maze problem

This is a discussion on Classic maze problem within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> void printMaze( const char maze[][12] ){ int i, j; system("cls"); for( i = 0 ; ...

  1. #1
    dat
    dat is offline
    Registered User
    Join Date
    Nov 2001
    Posts
    28

    Classic maze problem

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void printMaze( const char maze[][12] ){
    	int i, j;
    	
    	system("cls");
    	
    	for( i = 0 ; i < 12 ; i++ )
    		for( j = 0 ; j < 12 ; j++ ){
    			printf("%c", maze[i][j] );
    			if( j == 11 )
    				putchar('\n');
    		}
    }
    
    void mazeTraverse( char maze[][12], int row, int col ){
      // this function is suppose to make it's way through
      // maze. If you follow the "wall" to your right you will
      // eventually make your way through the maze.
      // I just haven't figured out an algorithm :(
    	
    		
    	
    }
    	
    
    
    int main(void){
    	const char maze[12][12]= {
    		{ '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
    		{ '#', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' },
    		{ '.', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' },
    		{ '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' },
    		{ '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' },
    		{ '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
    		{ '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
    		{ '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' },
    		{ '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' },
    		{ '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' },
    		{ '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' },
    		{ '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }
    		};
    	
    	mazeTraverse( maze, 2, 0 );
    
    
    	return 0;
    }

    The '#' are the maze walls, and the '.' are paths you can take. Any ideas is appreciated.
    Dat
    http://hoteden.com <-- not an porn site damnit!

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Following the wall to your right is your algorithm.

  3. #3
    dat
    dat is offline
    Registered User
    Join Date
    Nov 2001
    Posts
    28
    Originally posted by orbitz
    Following the wall to your right is your algorithm.
    Yes I know that but if you look at my function mazeTraverse, I haven't been able to figured it out. I tried one way but the 'X' goes back and forth.
    Dat
    http://hoteden.com <-- not an porn site damnit!

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There are countless posts and web sites for maze creation and solution. Search a bit and you'll easily find exactly what you need.

    Recursion is most commonly used for solving. It's easy.
    Code:
    if( can_go( N ) )
        go( N )
    if( can_go( E ) )
        go( E )
    if( can_go( S ) )
        go( S )
    if( can_go( W ) )
        go( W )
    Mark each square as "visited" as you run across it. When you can't go anymore, backtrack (return) util you have a way to go.

    Lather, rinse, repeat.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM
  3. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 04:36 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21