From e59dd0032ea16942b160a102e85445abee5c7d48 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sun, 9 Jan 2022 17:21:47 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'sk1a/maze.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sk1a/maze.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sk1a/maze.c b/sk1a/maze.c index e28c095..8ea8763 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -4,30 +4,34 @@ #include #include -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 solved = solve_recursive(maze, size, 0, 0, 0); + 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 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); + 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); + 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); + return solve_recursive(maze, size, x, y - 1, 1, 0); } else {