Изменил(а) на 'sk1a/maze.c'

This commit is contained in:
Oleksandr Hryshchenko 2022-01-09 17:21:47 +00:00
parent bf666148ce
commit e59dd0032e

View File

@ -4,30 +4,34 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
int solve_recursive(char* maze, int size, int x, int y, int down_visited); 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 solve_maze(char* maze,int size){
int solved = solve_recursive(maze, size, 0, 0, 0); int solved = solve_recursive(maze, size, 0, 0, 0, 0);
return 0; return 0;
} }
int solve_recursive(char* maze, int size, int x, int y, int down_visited){ int solve_recursive(char* maze, int size, int x, int y, int down_visited, int right_visited){
maze[x + y * size] = '*'; maze[x + y * size] = '*';
if(x == size - 1 && x == y){ if(x == size - 1 && x == y){
return 1; return 1;
} }
if(x != size - 1 && maze[x + 1 + y * size] != 'x'){ if(x != size - 1 && maze[x + 1 + y * size] != 'x'){
return solve_recursive(maze, size, x+1, y, 0); return solve_recursive(maze, size, x+1, y, 0, 0);
} }
else if(y != size - 1 && maze[x + (y + 1) * size] != 'x' && down_visited != 1){ else if(y != size - 1 && maze[x + (y + 1) * size] != 'x' && down_visited != 1){
return solve_recursive(maze, size, x, y+1, 0); 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'){ else if(y != 0 && maze[x + (y - 1) * size] != 'x'){
return solve_recursive(maze, size, x, y - 1, 1); return solve_recursive(maze, size, x, y - 1, 1, 0);
} }
else { else {