-
Maze Solving Cont....PLZ
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 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
-
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.
-
hardcode???
sorry i am a newbie to C...
could you exaplin your idea in a bit more detail plz?
thnks
-
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.
-
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..
-
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.
-
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
-
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.
-
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?
-
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();
}
-
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.
-
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
-
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???
-
-
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.