Maze Solving Cont....PLZ

This is a discussion on Maze Solving Cont....PLZ within the C Programming forums, part of the General Programming Boards category; Hi this is not the first thread on this topic...the previous one can be found at http://cboard.cprogramming.com/showthread.php?t=71922 i have now ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    15

    Maze Solving Cont....PLZ

    Hi
    this is not the first thread on this topic...the previous one can be found at
    Solving A Maze Using C Language!!!!
    i have now found a way to move around the maze but i have now come across another problem....

    If i come across a grid such as 6 ( 0 1 1 0), this would mean no wall on the noth or east sides so i could go through to the next grid.

    This is a problem as what if say i went north, then after a certain amount of grids i come across a dead end. I then need to go back to the grid that had the other wall missing.

    I would hen have to go backwards to the grid that had the two paths to choose from. I would therefore need some sort of marker.

    This is where i need the help.

    could someone please help me and also answer these questions:

    - if i used the & on 6 with 1 to find out if east had a wall. (seen below)

    0 1 1 0
    0 0 0 1
    ---------
    0 0 0 0 (this means east is free)
    do i have to convert the number 6 into its binary form first?

    thanks a lot

    jonny

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    the & operator works automatically. For your walls, why don't u just hardcode the data? Maybe make the program do it randomly...it seems a whole lot easier to me but oh well. You could make an array of 2D Vectors to hold the data. Something like: walls[20] = { Vec2(10,12), Vec2(50,14)....etc. Testing for wall collisions would be fairly simple from there.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    15
    hardcode???
    sorry i am a newbie to C...
    could you exaplin your idea in a bit more detail plz?
    thnks

  4. #4
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    I think I misunderstood you, if the number is an int and its 0110 then when the & operator converts it to binary it won't be the same. instead you should make an unsigned char hold the data and give it the hex form of the number. 0110 = 0x06 in hex and 6 in decimal so:

    Code:
    unsigned char wall1 = 0x06;
    unsigned char test = 0x01; //0001 = 1
    
    if(wall1 & test)....
    would get you the right results.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    15
    ok..not sure if i understand the whole unsigned char bit but i will have a look into it....
    ok..im having great trouble actually scanning in the file that has the maze info.
    the file would be a simple .txt file which woudl have the following layout.. could you help me with inputting it plz.

    10 10 (this is the size of the maze)
    2 2 (this is starting location)
    6 7 (this is end location)
    6 3 9 8 6 3 2 5 12 8
    6 8 3 5 12 14 6 8 3 7
    ........
    ...
    ..
    ..
    .. etc... (10 by 10 numbers, these numbers give the mazo info)

    i have been stuck on this for a whiel..

  6. #6
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    couldn't tell you in C...Perhaps this is a C++ Program?

    btw...The windows calculator can convert decimal to hex and binary. Could be very useful for your situation.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    15
    nope..
    ive managed to fscanf it...and can printf the maze...so that is 1 step.

    now i need to start implementing the & thing.

    i have an array maze[i][j]. which contains the maze info...
    how would i go about doing the & on each square.

    also. given this:

    6 5 4 3
    6 7 8 9
    3 4 5 6
    2 3 5 6
    and then say maze[0][0], my printf is giving out 6. but i need 0,0 to start from the bottom left corner and go up to the top right.

    any help on this would be good

  8. #8
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    As to your maze reorder problem...reorder the text file to work with your program or parse the file differently...

    For the & operator, testing for collision on input is probably your only solution. When the player presses the -> arrow key, & the grid number with 1. <- arrow key would be &'d with 8. I got this information from windows calculator btw. 1000 = 8 0001 = 1.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    15
    oh...i didnt explain that very well....
    the only input i have is to give the program an input file. then after that the next thing the program shoudl do is output a string/array showing the quickest route through the maze.. such as
    N N E W S N ...... and so on.

    does this make sense?

  10. #10
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    I'll give you a sample:

    Code:
    maze[20][20]; //Predefined maze array
    
    if( GetKeyState(VK_LEFT) ) //However you do it in C
    {
      if( CharacterPosition & 0x08 ) //Character position is a maze[][] spot
        MoveCharacterLeft();
    }
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Take baby steps. How about you first figure out how to read your file correctly. Then once you've got that set up correctly, how about you either setup a way for you to walk through the maze with your keyboard, or whatever it is you're doing, just to test out how to work with walls. Once you actually understand what you're doing, then you can try and solve the maze. Once you can actually solve it, how about then working on keeping the path?

    It does no good to have some random code given to you, if you're not going to take the time to figure out what the hell is happening.


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

  12. #12
    Registered User
    Join Date
    Nov 2005
    Posts
    15
    yeah i know.
    right
    im trying to & an array element with 0x8..it looks like this.

    maze[xstart][ystart] & W_NORTH

    it doesnt like it..

    any help would be useful..
    thnks

  13. #13
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    you can't just & it...is it in an if statement or are you assigning the result to something? More than anything, what is the error???
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Consult this FAQ.


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

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Well this isn't the fastest way but follow this algo and it will solve the maze.

    1. Pick a random direction
    2. If empty, go there and push movement to stack, else 4
    3. goto 1
    4. Pop a movement off the stack and goto 1

    The final stack will hold the path through the maze.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Solving maze using rec'
    By gavra in forum C Programming
    Replies: 14
    Last Post: 07-13-2008, 09:20 AM
  2. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 12:52 AM
  3. Solving A Maze Using C Language!!!!
    By jonnybgood in forum C Programming
    Replies: 6
    Last Post: 11-08-2005, 11:15 AM
  4. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 08:28 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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