37 lines
871 B
C
37 lines
871 B
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 solve_maze(char* maze,int size){
|
|
int solved = solve_recursive(maze, size, 0, 0, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int solve_recursive(char* maze, int size, int x, int y, int down_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);
|
|
}
|
|
|
|
else if(y != size - 1 && maze[x + (y + 1) * size] != 'x' && down_visited != 1){
|
|
return solve_recursive(maze, size, x, y+1, 0);
|
|
}
|
|
|
|
else if(y != 0 && maze[x + (y - 1) * size] != 'x'){
|
|
return solve_recursive(maze, size, x, y - 1, 1);
|
|
}
|
|
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|