diff --git a/sk1a/Makefile b/sk1a/Makefile new file mode 100644 index 0000000..ae923d1 --- /dev/null +++ b/sk1a/Makefile @@ -0,0 +1,14 @@ +all: program + +maze.o: maze.c + gcc -c -g -Wall maze.c -o maze.o + +main.o: main.c + gcc -c -g -Wall main.c -o main.o + +program: maze.o main.o + gcc -g -Wall maze.o main.o -o program + +clean: + rm program + rm *.o diff --git a/sk1a/main.c b/sk1a/main.c new file mode 100644 index 0000000..091005a --- /dev/null +++ b/sk1a/main.c @@ -0,0 +1,39 @@ +#define SZ 5 +#include +#include +#include "maze.h" + +void print_solution(char* matrix,int sz){ + for (int i = 0; i < sz * sz; i++){ + printf("%c ",matrix[i]); + if (i % sz == (sz-1)){ + printf("\n"); + } + } +} + +int main(){ + char tmaze[SZ+1][SZ+1]={ + "*x ", + " x ", + " x ", + " x ", + " ", + }; + char maze[SZ*SZ]; + memset(maze,' ',SZ*SZ); + for (int i= 0; i < SZ; i++){ + for (int j= 0; j < SZ; j++){ + if (tmaze[i][j] == 'x'){ + maze[i*SZ+j] = 'x'; + } + } + } + int r = solve_maze(maze,SZ); + if (!r){ + printf("Nenasiel som riesenie\n"); + } + print_solution(maze,SZ); + + return 0; +} diff --git a/sk1a/main.o b/sk1a/main.o new file mode 100644 index 0000000..b67a4f1 Binary files /dev/null and b/sk1a/main.o differ diff --git a/sk1a/maze.c b/sk1a/maze.c new file mode 100644 index 0000000..c9a4c2f --- /dev/null +++ b/sk1a/maze.c @@ -0,0 +1,64 @@ +#include +#include +#include "maze.h" +#include +#include + +int solve_maze(char* maze, int size){ + for(int i = 0; i < size * size; i++){ + if(maze[i] == ' '){ + maze[i] = '*'; + continue; + }else{ + i = i+size-2; + continue; + } + } + return 1; +} + +/*int solve_maze(char* maze,int size){ + + char smaze[size+1][size+1]; + char* wmaze = smaze; + int k = 0; + memset(smaze, 0, size); + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + smaze[i][j] = maze[k]; + k++; + } + + } + + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + printf("%c ",smaze[i][j]); + + } + printf("\n"); + } + + + int r = findWay(0,0,size); + + return r; +} + + + + +int findWay(int i, int j, int size){ + + if(wmaze[i][j] == ' '){ + + wmaze[i][j] = '*'; + if(findWay(i, j+1, size) == 1) return 1; + if(findWay(i+1, j+1, size) == 1) return 1; + + wmaze[i][j] = ' '; + } + return 0; +} + +*/ diff --git a/sk1a/maze.h b/sk1a/maze.h new file mode 100644 index 0000000..2e34662 --- /dev/null +++ b/sk1a/maze.h @@ -0,0 +1,22 @@ +#ifndef _MAZEH +#define _MAZEH + +/** + * Funkcia by mala zobrať vstupnú mriežku a + * vyznačiť na nej cestu z ľavého horného rohu do pravého dolného rohu. + * Mriežka je uložená do jednorozmerného poľa, pričom najprv ide prvý riadok, + * za ním druhý a tak ďalej. + * + * Na mriežke sa nachádzajú znaky: + * ' ' - voľné miesto + * 'x' - stena. Stena nesmie byť prepísaná. + * '*' - poloha potkana. Na začiatku je na 0,0. + * + * @param maze Štvorcová mriežka rozmeru size x size. + * @param size Rozmer mriežky + * @return 1 ak existuje riešenie, 0 inak. + */ +int solve_maze(char* maze,int size); + + +#endif diff --git a/sk1a/maze.o b/sk1a/maze.o new file mode 100644 index 0000000..eac353e Binary files /dev/null and b/sk1a/maze.o differ diff --git a/sk1a/program b/sk1a/program new file mode 100755 index 0000000..dbdbbc9 Binary files /dev/null and b/sk1a/program differ