first commit
This commit is contained in:
parent
49c820de76
commit
415e7d9678
14
skuska/sk1a/Makefile
Normal file
14
skuska/sk1a/Makefile
Normal file
@ -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
|
39
skuska/sk1a/main.c
Normal file
39
skuska/sk1a/main.c
Normal file
@ -0,0 +1,39 @@
|
||||
#define SZ 5
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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;
|
||||
}
|
BIN
skuska/sk1a/main.o
Normal file
BIN
skuska/sk1a/main.o
Normal file
Binary file not shown.
64
skuska/sk1a/maze.c
Normal file
64
skuska/sk1a/maze.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "maze.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
*/
|
22
skuska/sk1a/maze.h
Normal file
22
skuska/sk1a/maze.h
Normal file
@ -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
|
BIN
skuska/sk1a/maze.o
Normal file
BIN
skuska/sk1a/maze.o
Normal file
Binary file not shown.
BIN
skuska/sk1a/program
Executable file
BIN
skuska/sk1a/program
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user