Damn, I did this project in School in C++! Really fun and good stuff. It would be a lot better if you solved it yourself instead of depending on others.
However, I could post my C++ code for you and you could convert it to PHP. I think I'll do the PHP code for myself, but I'm not going to do any school work for anyone. If it isn't a project, then let me know and I'll see about posting some sample code.
--------------------
The trick is that without AI, you really need to parse the map into an array or vector. Using Numbers is easy because you only do comparsions.
Code: Select all
// After Parsing
$map[0] = array('A', NULL, NULL, NULL, NULL);
$map[1] = array(1, 0, 0, 0, 0);
$map[2] = array(1, 1, 1, 1, 0);
$map[3] = array(0, 1, 0, 1, 0);
$map[4] = array(0, 1, 0, 1, 1);
$map[5] = array(0, 0, 1, 0, 1);
$map[6] = array(1, 1, 1, 1, 1);
$map[7] = array('B', NULL, NULL, NULL, NULL);
Is your array, which you are transverse and I'm guessing that you won't be using any AI techniques to record the weight of the length of the 'bot' going through the maze. It is easier without AI.
All you do is start where at $map[0][0] and and go down, unless 'A' is at another position.
- Check where 'A' is in the 0 position array.
- Down is the only direction, but check to see if the 'bottom' position is '1' and return error if it is '0'
- Once in the maze, check all positions for '1', first checking the down position, then the right position, then the left.
- Repeat Step 3 until 'B' is reached.
If you would be better practice to 'record' the path you take, so that you can reverse your step if you reach a dead end.
The Maze PHP Code
It appears to me that they took either C++ code and converted it to PHP. You don't have to have such an complex code example. My code was all in a while loop.
EDIT
I realized that my C++ code had different and far easier specifications. A* path finding is a AI technique, in which you record all possible routes and choose the one that has the 'shortest' one. I think it would be a nice fun project to try to do.