usaa21/sk1a/maze.c

61 lines
893 B
C
Raw Normal View History

2022-01-09 00:12:46 +00:00
#include <stdio.h>
#include <string.h>
#include "maze.h"
#include <assert.h>
#include <math.h>
2022-01-21 20:53:46 +00:00
int solve_maze(char* maze,int size){
//int end = size*size;
int actualPos = 0;
maze[actualPos]='*';
while(actualPos != size*size-1){
//printf("acpos: %d\n", actualPos);
2022-01-21 21:13:58 +00:00
2022-01-21 20:53:46 +00:00
//Pohyb dole
if(actualPos < (size*size-size) && maze[actualPos+size]==' '){
2022-01-21 21:14:51 +00:00
//printf("dole\n");
2022-01-21 20:53:46 +00:00
maze[actualPos+size]='*';
actualPos+=size;
2022-01-21 21:01:56 +00:00
//printf("acpos: %d\n", actualPos);
2022-01-09 00:12:46 +00:00
continue;
2022-01-21 20:53:46 +00:00
}
//Pohyb vpravo
if(maze[actualPos+1]==' '){
2022-01-21 21:14:51 +00:00
//puts("vpravo");
2022-01-21 21:13:58 +00:00
maze[actualPos+1]='*';
2022-01-21 20:53:46 +00:00
actualPos++;
2022-01-09 00:12:46 +00:00
continue;
}
2022-01-21 20:53:46 +00:00
//Pohyb hore
2022-01-21 21:13:58 +00:00
if(maze[actualPos-size]==' ' && actualPos-size != 0){
2022-01-21 20:53:46 +00:00
maze[actualPos-size]='*';
actualPos-=size;
continue;
2022-01-21 21:13:58 +00:00
}
2022-01-09 00:12:46 +00:00
2022-01-21 20:53:46 +00:00
//Pohyb vlavo
if(maze[actualPos-1]==' '){
maze[actualPos]='*';
actualPos--;
continue;
2022-01-09 00:12:46 +00:00
}
2022-01-21 21:13:58 +00:00
2022-01-09 00:12:46 +00:00
2022-01-21 20:53:46 +00:00
}
2022-01-09 00:12:46 +00:00
2022-01-21 20:53:46 +00:00
return 1;
2022-01-09 00:12:46 +00:00
}