-
Notifications
You must be signed in to change notification settings - Fork 1
/
random_walk.c
42 lines (36 loc) · 1.09 KB
/
random_walk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "maze.h"
#include <stdlib.h>
void random_walk(Map * map) {
// I am lazy, we can probably know how many neighbors there will be ahead of time
int visitedCount = 0;
Tile * tile = randomTile(map);
Tile * neighborTile = NULL;
Direction dir;
int visited[(map->width * map->height)];
for (int i = 0; i < (map->width * map->height); i++) {
visited[i] = 0;
}
int at = accessableTiles(map);
while(visitedCount < at) {
dir = randomNeighbor(map, tile, &neighborTile);
if (visited[(neighborTile->y * map->width) + neighborTile->x] == 0) {
if (dir == NORTH) {
neighborTile->connections |= DOWN;
} else if (dir == SOUTH) {
tile->connections |= DOWN;
} else if (dir == EAST) {
tile->connections |= RIGHT;
} else if (dir == WEST) {
neighborTile->connections |= RIGHT;
}
visited[(neighborTile->y * map->width) + neighborTile->x] = 1;
visitedCount++;
}
tile = neighborTile;
startRender();
renderMap(map);
debugRenderCursor(tile->x, tile->y, 0, 100, 0);
endRender();
delay(1);
}
}