usaa21/sk1a/maze.c

41 lines
1.0 KiB
C

#include <stdio.h>
#include <string.h>
#include "maze.h"
#include <assert.h>
#include <stdbool.h>
int solve_recursive(char* maze, int size, int x, int y, int down_visited, int right_visited);
int solve_maze(char* maze,int size){
int solved = solve_recursive(maze, size, 0, 0, 0, 0);
return 0;
}
int solve_recursive(char* maze, int size, int x, int y, int down_visited, int right_visited){
maze[x + y * size] = '*';
if(x == size - 1 && x == y){
return 1;
}
if(x != size - 1 && maze[x + 1 + y * size] != 'x'){
return solve_recursive(maze, size, x+1, y, 0, 0);
}
else if(y != size - 1 && maze[x + (y + 1) * size] != 'x' && down_visited != 1){
return solve_recursive(maze, size, x, y+1, 0, 0);
}
else if(x != 0 && maze[x - 1 + y * size] != 'x'){
return solve_recursive(maze, size, x - 1, y, 0, 1);
}
else if(y != 0 && maze[x + (y - 1) * size] != 'x'){
return solve_recursive(maze, size, x, y - 1, 1, 0);
}
else {
return 0;
}
}