Maze Project

This is a discussion on Maze Project within the C++ Programming forums, part of the General Programming Boards category; Hey guys im new to the board and need some help with this path finding project iv gata make for ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    73

    Question Maze Project

    Hey guys im new to the board and need some help with this path finding project iv gata make for class.


    Ok first u need to know what the project intails. I have to write a dos orented program that reads in a .txt file with a maze made up of x's and o's. The x's represent the walls and the o's are open spaces. The program must then print out in a .txt file what moves where taken to reach the cheese. O and there is an m (for mouse) and c (for cheese). Here is an example of how the program should look;

    2 left
    1 down
    3 right
    1 up

    Stuff like that.


    Iv already figured out how to read in the file....print out the output to the .txt file and I think (note i said think) I figured out how to make the engine to move squares.

    But now I can't seem to impliment the search engine into the map. First problem I need to figure out a way to set up the maze (witch is 20x20 so 400 squares) in an array with out having to write 400 statements.

    Ill wait to ask the second question until someone replies.....just in case if figure out the second question after getting the first one answered.

    O any web sites that coudl help? Thanx in advance.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Reading the array is simple enough:
    Code:
    for ( int i = 0; i < 20; ++i )
      for ( int j = 0; j < 20; ++j )
        file>>maze[i][j];
    Finding a path through the maze is more difficult, but the solution is simpler if you use recursion. That way you can move through all possible paths and if you hit a wall, simply return to the last path where you had an untried option.

    -Prelude
    My best code is written with the delete key.

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    shows a map system under techs post:

    http://www.cprogramming.com/cboard/s...ight=scrolling

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Ok i read what yall wrote and i basically hit myselft in the head...because i had it setup like that and deleted it. Ok the second quesiton is.....i want to print all them out...but cout << maze[i][j]; wont print anything. how can i print out the entire .txt maze file?

    O and the thrid question. My professor said to take the 'c' varibale and make it 0 and then number each square according to how many steps it takes to get to the cheese. Then make a loop that counts down to each open square to 0. But how do u give each square a letter?

    O and code isnt nessicary. If u have examples yeah. but you can juz tell me in words what kinda stuff i would need.. That way i can learn it better. Thanx for the help.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    wow that sounds like an excellent excercise to try.

    I think I may have to try that one myself!

    Is your class a beginners programming class?

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Yeah im taking 1st semester programming. And i havent programmed anything for about 3 years..So I really need some help. And this program is due tomorrow at 2:30.soo

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    O and i ment to give each square a number. Sorry for the typo.

    Now since my time is running out im going to go ahead and ask for some help determaning weather the step was up, down, left, or right. I already know how to print it out. What i need to know is how to actually write the part that determines what direction im going in. So if yall could help me answer these questions, i would apreacate it.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Tell me what you think about this. Would it work if i took the character M and place it inside of an while loop that would count down to the next number as long as M doesn't equeal zero?

    And if this would work. What would I set M to? Because I can't set it to 0. So do i find the area in the maze where it is or what? What do yall think?

  9. #9
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Code:
    void demo()
    {
    
                int l, w;
    
                for (w = 0; w < 20; ++w)
                  {
    	for (l = 0; l < 20; ++l)
                   {
    	InMaze >> maze[w][l];
    	if (maze[w][l] == 'x')
    	  maze[w][l] = border;
    	else
    	if (maze[w][l] == 'o')
    	  maze[w][l] = open;
    	}
    	}
    
    while ( m != 0 )
    {
    
       char nextstep;
    
       nextstep = open;
    
       if ( nextstep == border )
    	nextstep == false;
       else
        if ( nextstep == true )
                     m--;
    }
    }
    would this code work to find the next avaible square? I really don't know of any way to test it. What do yall think?


    Code tags added by Kermi3

  10. #10
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    Code Tags

    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  11. #11
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Test it by inputting a small maze, like only 3x3 with an answer you know for sure. Then see what it does. heh it's simple but it woks.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  12. #12
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    You see i thought about doing that....but i still need one question answered. What do i set M to? Because if i set it to 0 the program will think that it is salved. So do i set m to it position on the map or what?

  13. #13
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Ok guys i inputted a smaller maze that i knew the answer to and added this code

    Code:
    while ( m != 0 )
    		{
    
    			char nextstep;
    
    			nextstep = open;
    
    			if ( nextstep == border )
    				nextstep == false;
    			else
    			if ( nextstep == true )
    				m--;
    			
    			cout << nextstep << endl;
    			cout << m << endl;
    			Maze << m << nextstep;
    		}
    	}
    but all i get back is jibberish. It looks like black squares. Why does it do this?

  14. #14
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    well to start with I can's see a time when nextsp would ever equal boarder...the other thing is the way I'm reading it you're using the same nextstep evertime. How is it supposed to change?
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  15. #15
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    So you mean nextstep should change position or value? And yeah i thought that nextstep equaling boarder wouldnt work. But im getting confused. What im trying to say is that if the nextstep is into a wall then don't take that step. How should I word it?

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  2. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

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