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 22:22:19 +00:00
|
|
|
|
|
|
|
|
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-09 00:12:46 +00:00
|
|
|
continue;
|
2022-01-21 20:53:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 22:22:19 +00:00
|
|
|
//Pohyb hore
|
|
|
|
if(actualPos-size > size && maze[actualPos-size]==' '){
|
|
|
|
//printf("hore\n");
|
|
|
|
maze[actualPos-size]='*';
|
|
|
|
actualPos-=size;
|
|
|
|
continue;
|
|
|
|
}else if(actualPos-size > size && maze[actualPos-size]=='*'){
|
|
|
|
maze[actualPos]=' ';
|
|
|
|
actualPos-=size;
|
|
|
|
}
|
|
|
|
|
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 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]==' '){
|
2022-01-21 22:22:19 +00:00
|
|
|
//printf("vlavo\n");
|
2022-01-21 20:53:46 +00:00
|
|
|
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
|
|
|
}
|