From 95a043d0ad75ae93e0007cfbdac78bc7872562a5 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sun, 9 Jan 2022 17:06:45 +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 | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/sk1a/maze.c b/sk1a/maze.c index e5a49f3..e28c095 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -1 +1,36 @@ -qqq \ No newline at end of file +#include +#include +#include "maze.h" +#include +#include + +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; + } +}