I don’t know how to make sure that a random maze can lead from the entrance on the right side to the exit on the left side without any wall blocking the path. This is my code that I am still doing. Can everyone give me a hint or algorithm to achieve a simple maze (input / output)? Thank! P / S my problem is that the maze generator does not provide a way out ... (stuck)
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define SIZE 12
void mazeGenerator(char [][SIZE]);
int main(void)
{
char maze[SIZE][SIZE];
srand((unsigned int)time(NULL));
mazeGenerator(maze);
return 0;
}
void mazeGenerator(char a[SIZE][SIZE])
{
size_t row,column = 0, r;
for ( row = 0; row < SIZE; ++row )
{
a[row][column] = '#';
}
for ( row = 0; row < SIZE; ++row )
{
a[row][SIZE - 1] = '#';
}
row = rand() % 11 + 1;
a[row][0] = '.';
row = rand() % 11 + 1;
a[row][SIZE - 1] = '.';
for (column = 1; column < SIZE - 1; ++column)
{
a[0][column] = '#';
}
for (column = 1; column < SIZE - 1; ++column)
{
a[SIZE - 1][column] = '#';
}
puts("");
puts("** Maze Generator by Huy Le **\n");
for (row = 0; row < SIZE; ++row)
{
for (column = 0; column < SIZE; ++column)
{
printf_s("%2c",a[row][column]);
}
puts("");
}
puts("");
}
source
share