Down, right maybe

This commit is contained in:
Valér Jakubčo 2022-01-21 21:53:46 +01:00
parent 77b5b65d15
commit c8ef9fbd26

View File

@ -4,61 +4,55 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
int solve_maze(char* maze, int size){
for(int i = 0; i < size * size; i++){
if(maze[i] == ' '){ int solve_maze(char* maze,int size){
maze[i] = '*';
continue; //int end = size*size;
}else{ int actualPos = 0;
i = i+size-2; maze[actualPos]='*';
while(actualPos != size*size-1){
//printf("acpos: %d\n", actualPos);
//Pohyb dole
if(actualPos < (size*size-size) && maze[actualPos+size]==' '){
printf("dole\n");
maze[actualPos+size]='*';
actualPos+=size;
printf("acpos: %d\n", actualPos);
continue; continue;
} }
//Pohyb vpravo
if(maze[actualPos+1]==' '){
puts("vpravo");
maze[actualPos]='*';
actualPos++;
continue;
} }
//Pohyb hore
/* if(maze[actualPos-size]==' ' && actualPos-size != 0){
maze[actualPos-size]='*';
actualPos-=size;
continue;
}*/
/*
//Pohyb vlavo
if(maze[actualPos-1]==' '){
maze[actualPos]='*';
actualPos--;
continue;
}
*/
}
return 1; 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;
}
*/