| | |
Maze game help.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 56
Reputation:
Solved Threads: 1
Hey guys,
I have written a recursive function mazeTraverse which finds the path of the mouse to find its food which is placed inside the maze. I am given a maze of of 15 rows and 25 columns. Mouse's starting position is (8,1)[eighth row and 1st column] and the food is placed in (5, 10).
In my maze, 'A' represents the way is blocked
' ' represnts an opening
'M' represents starting position for the mouse and 'T' represents the target which is food.
I am supposed to print X which will start moving from starting position to the target. X basically represents the mouse movement from the starting position to the target. I know I need to use recursive function so when mouse find dead end it has to do backtracking. I have written a function but it is not correct. Can anyone look at my code and guide me. I am very interested to learn something new.
Here is my code :
I am confused now. Is my algorithm correct? How can I print 'X' now? and how can I display like X is moving from starting position to find the target? Please guide me through. I am willing to learn. Thanks
I have written a recursive function mazeTraverse which finds the path of the mouse to find its food which is placed inside the maze. I am given a maze of of 15 rows and 25 columns. Mouse's starting position is (8,1)[eighth row and 1st column] and the food is placed in (5, 10).
In my maze, 'A' represents the way is blocked
' ' represnts an opening
'M' represents starting position for the mouse and 'T' represents the target which is food.
I am supposed to print X which will start moving from starting position to the target. X basically represents the mouse movement from the starting position to the target. I know I need to use recursive function so when mouse find dead end it has to do backtracking. I have written a function but it is not correct. Can anyone look at my code and guide me. I am very interested to learn something new.
Here is my code :
C++ Syntax (Toggle Plain Text)
class MazeMania { public: MazeMania(const int maze[][], int start, int end); int traverse( int x, int y); private: const int ROWS = 15; const int COLS = 25; char mouse = 'X'; }; # include "mazeMania.h" #define FALSE 0 #define TRUE 1 // initializes the constructor MazeMania::MazeMania(const int maze[][], int start, int end) { int start = 8; int end = 1; } int MazeMania::mazeTraverse(int x, int y) { if ( x < 0 || x > COLS -1 || y < 0 || y > ROWS -1) { return FALSE; } if (maze[y][x] == 'A') { return FALSE; } cout <<" "<<mouse; // if x, y is the goal, return true if (maze[y][x] == 'T') { return TRUE; } if (mazeTraserse(x-1, y) == TRUE) { return TRUE; } else if (mazeTraverse (x, y-1) == TRUE) { return TRUE; } else if (mazeTraverse (x + 1, y) == TRUE) { return TRUE; } else if (mazeTraverse (x, y + 1) == TRUE) { return TRUE; }
I am confused now. Is my algorithm correct? How can I print 'X' now? and how can I display like X is moving from starting position to find the target? Please guide me through. I am willing to learn. Thanks
•
•
Join Date: Jan 2008
Posts: 3,815
Reputation:
Solved Threads: 501
There's no ending bracket to your function, so is there more to the function? I see no change in the maze[][] array and no other variables that keep track of where you've been. You have cout statements that display an 'X', but what's the point of this? I get a return value of true or false, but assuming the maze is solvable, I'd better get true, right? But I get "true" returned, I still have no idea what path I took. As far as "backtracking" goes, there's no direction, there's just a coordinate or something, so how do I know how to reverse directions?
So if the goal is to decide WHETHER a maze is solvable, it might possibly work. If the goal is to determine the correct path, I don't see anything that has anything to do with a path here. I also think that possibly, you're going to have a massive call stack, though I'm not 100% positive. I don't understand the algorithm and I don't understand the purpose of the function.
So if the goal is to decide WHETHER a maze is solvable, it might possibly work. If the goal is to determine the correct path, I don't see anything that has anything to do with a path here. I also think that possibly, you're going to have a massive call stack, though I'm not 100% positive. I don't understand the algorithm and I don't understand the purpose of the function.
![]() |
Similar Threads
- Help with making a maze game with MASM (Assembly)
- Maze Game (Visual Basic 4 / 5 / 6)
- Maze Game (VB.NET)
- maze game (C++)
- maze game (C++)
- how to make maze game using "gotoxy" & getch? (C++)
Other Threads in the C++ Forum
- Previous Thread: Binary Search fails sometimes
- Next Thread: Generating Pythagorean Numbers
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






