usaa21/sk1a
2022-01-20 08:04:32 +01:00
..
main.c prvy 2022-01-19 22:29:10 +01:00
main.o prvy 2022-01-19 23:23:25 +01:00
Makefile prvy 2021-12-28 16:21:01 +01:00
maze.c prvy 2022-01-19 23:23:25 +01:00
maze.h prvy 2021-12-28 16:21:01 +01:00
maze.o prvy 2022-01-19 23:23:25 +01:00
program prvy 2022-01-19 23:23:25 +01:00
readme.md prvy 2022-01-20 08:04:32 +01:00

#include <stdio.h> #include <string.h> #include "maze.h" #include <assert.h>

int issafe(char* maze, int x, int y, int size) { if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ return 1; } return 0; }

int backtracking(char* maze, int x, int y, int size){ //https://www.geeksforgeeks.org/rat-in-a-maze-backtracking-2/ if(x == size - 1 && y == size - 1 && maze[x * size + y] == ' '){ //kontrola ci sa nachadzam na konci maze[x * size + y] = '*'; return 1; }

if(issafe(maze, x, y, size) == 1) {												// znazornenie stien
    maze[x * size + y] = '*';

    if (backtracking(maze, x, y + 1, size) == 1) {
        return 1;
    }
    if (backtracking(maze, x + 1, y, size) == 1) {
        return 1;
    }
    if (backtracking(maze, x - 1, y, size) == 1) {
        return 1;
    }
    if (backtracking(maze, x, y - 1, size) == 1) {
        return 1;
    }
    maze[x * size + y] = ' ';
}
return 0;

}

int solve_maze(char* maze, int size) { return backtracking(maze, 0, 0, size); }