need help on my coding..of maze recursion
![]() ![]() ![]() ![]() ![]() |
need help on my coding..of maze recursion
|
|
Oct 29 2009, 09:55 PM
Show posts by this member only |This post's rating (0+, 0-) | Post
#1
|
|
Casual ![]() ![]() ![]() Group: Junior Member Posts: 303 Ratings earned: 0+, 0- Ratings given: 0+, 0- Joined: Jan 2007 |
hello i am doing my project in c++..
just near finish..however i have to get some errors done..care to help?? CODE #include <stdio.h> #define FALSE 0 #define TRUE 1 #define NROWS 6 #define MCOLS 6 // Symbols: // '.' = open // '#' = blocked // 'S' = start // 'G' = goal // '+' = path // 'x' = bad path char maze[NROWS][MCOLS] = { "S...##", "#.#...", "#.##.#", "..#.##", "#...#G", "#.#..." }; void display_maze(void); int find_path(int x, int y); int main(void) { display_maze(); if ( find_path(0, 0) == TRUE ) printf("Success!\n"); else printf("Failed\n"); display_maze(); return 0; } // main() void display_maze(void) { int i; printf("MAZE:\n"); for ( i = 0; i < NROWS; i++ ) printf("%.*s\n", MCOLS, maze[i]); printf("\n"); return; } int find_path(int x, int y) { // If x,y is outside maze, return false. if ( x < 0 || x > MCOLS - 1 || y < 0 || y > NROWS - 1 ) return FALSE; // If x,y is the goal, return true. if ( maze[y][x] == 'G' ) return TRUE; // If x,y is not open, return false. if ( maze[y][x] != '.' && maze[y][x] != 'S' ) return FALSE; // Mark x,y part of solution path. maze[y][x] = '+'; // If find_path North of x,y is true, return true. if ( find_path(x, y - 1) == TRUE ) return TRUE; // If find_path East of x,y is true, return true. if ( find_path(x + 1, y) == TRUE ) return TRUE; // If find_path South of x,y is true, return true. if ( find_path(x, y + 1) == TRUE ) return TRUE; // If find_path West of x,y is true, return true. if ( find_path(x - 1, y) == TRUE ) return TRUE; // Unmark x,y as part of solution path. maze[y][x] = 'x'; return FALSE; } // find_path() can anyone know why CODE char maze[NROWS][MCOLS] = { has error of initializer array code too long??any help??please...i just need to check the errors.. "S...##", "#.#...", "#.##.#", "..#.##", "#...#G", "#.#..." }; |
|
|
Oct 29 2009, 11:27 PM
Show posts by this member only |This post's rating (0+, 0-) | Post
#2
|
|
Getting Started ![]() ![]() Group: Junior Member Posts: 198 Ratings earned: 0+, 0- Ratings given: 0+, 0- Joined: Aug 2006 |
CODE char maze[NROWS][MCOLS] = { "S...##", "#.#...", "#.##.#", "..#.##", "#...#G", "#.#..." }; pls note that this piece of code is just an array of c-strings and dun forget that c-string require to have a null-terminating character so just 6 characters per row is not enough to hold that cheers |
![]() ![]() ![]() ![]() |
| Lo-Fi Version | Time is now: 20th March 2010 - 08:41 PM |