Navigating a maze recursively
Hi I'm trying to teach myself cprogramming. I'm a couple of chapters past recursive and decided to go back and see if I can do this problem from the end of that chapter. This is what I have so far.
Right now I'm stuck at a logic error where I am trying to use function move to get from 0,0 to 7,7. I didn't add in any obstacles so I can finish move function first. I'm really bad at making recursive functions so I get stopped very easily.
Anyways what I have so far is, I'm just moving along the horizontal.
It gets to 6,0 from 0,0 and stops. When I should get to 7,0.
Thanks for any help
Code:
// Navigate a maze using recursive
#include <stdio.h>
#include <string.h>
#define ARSIZ 8
void initialize_array(int maze[ARSIZ][ARSIZ], int x, int y, int tf);
void move(int maze[ARSIZ][ARSIZ], int x, int y, int tf);
void neighbors(int maze[ARSIZ][ARSIZ],char check[4], int x, int y);
int main(){
int maze[ARSIZ][ARSIZ];
int n = ARSIZ - 1;
initialize_array(maze, n, n, 0);
move(maze,0,0,0);
return 0;
}
//set the maze so there are no obstacles until I finish navigation part.
void initialize_array(int maze[8][8], int x, int y, int tf){
if(tf == 1){
if(x > 0){
//change first array element position
initialize_array(maze,x-1,ARSIZ-1,0);
}
}else{
if(y >= 0){
//change second array element position
initialize_array(maze,x,y-1,0);
maze[x][y] = 0;
}else{
//go back to first array element position manipulation
initialize_array(maze,x,y,1);
}
}
}
//Ahhhhhhh HELP
void move(int maze[ARSIZ][ARSIZ], int x, int y, int tf){
char check[5];
if(tf == 1){
}
else{
neighbors(maze,check,x,y);
if(check[0] == '1'){
printf("%d,%d\t%s\n",x,y,check);
move(maze,x+1,y,0);
}
}
}
void neighbors(int maze[ARSIZ][ARSIZ],char check[5], int x, int y){
//check[0] = right
//check[1] = left
//check[2] = up
//check[3] = down
strcpy(check,"0000");
//
if(x < ARSIZ - 1){
if(maze[x+1][y] == 0){
check[0] = '1';
}
}
if(x != 0){
if(maze[x-1][y] == 0){
check[1] = '1';
}
}
if(y != 0){
if(maze[x][y-1] == 0){
check[2] = '1';
}
}
if(y != 7){
if(maze[x][y+1] == 0){
check[3] = '1';
}
}
}