I got COMPLETELY stumped and just gave up, but for the sake that I'm trying to help you, here is wat I came up with before my mind Seg-Faulted and gave up...
Code:
#include <iostream.h>
#define up 1
#define down 2
#define left 3
#define right 4
struct pos
{
int x, y;
};
const char maze[][] = {
"#########",
"# S#",
"# #######",
"# #",
"# #######",
"# E#",
"#########"
};
const pos start = {7,1};
const pos end = {7,6};
bool move(int dir, pos &mypos)
{
switch(dir)
{
case left:
if(maze[mypos.x+1][mypos.y]=='#')
return false;
mypos.x++;
return true;
case right:
if(maze[mypos.x-1][mypos.y]=='#')
return false;
mypos.x--;
return true;
case up:
if(maze[mypos.x][mypos.y+1]=='#')
return false;
mypos.y++;
return true;
case down:
if(maze[mypos.x][mypos.y-1]=='#')
return false;
mypos.y--;
return true;
};
}
int follow(int x, int y, int dir)
{
if(x==end.x && y==end.y)
return 1; //found
switch(dir)
{
case left:
if(maze[x-1][y]=='#')
return 0;
return follow(x-1,y);
case right:
if(maze[x+1][y]=='#')
return 0;
return follow(x+1,y);
case up:
if(maze[x][y-1]=='#')
return 0;
return follow(x,y-1
int main()
{
Sorry I couldn't be of more help...
I did this thing for a project for my old class but I can't remember what I did or where it is. I know I did something recursive like this though....
When you figure it out, post the code plz, I'd like to see it.
-LC