Implement random wall reopening to generate alternative paths and cycles

This commit is contained in:
2026-06-22 19:30:44 +02:00
parent d1bb95f166
commit 7d85aec6ec
2 changed files with 15 additions and 0 deletions
+15
View File
@@ -96,6 +96,21 @@ static void generate_maze(void) {
break;
}
}
// Reopen some walls to create alternative paths/loops
for (uint8_t y = 1; y < MAP_SIZE - 1; y++) {
for (uint8_t x = 1; x < MAP_SIZE - 1; x++) {
if (maze[y][x] == 0) {
// If it connects two paths horizontally or vertically, open it with a 15% probability
if ((maze[y][x - 1] == 1 && maze[y][x + 1] == 1) ||
(maze[y - 1][x] == 1 && maze[y + 1][x] == 1)) {
if ((rand() % 100) < 15) {
maze[y][x] = 1;
}
}
}
}
}
}
static void draw_map(uint8_t center_x, uint8_t center_y) {
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB