/** * @brief Recursive function to generate a maze. * * @param[in] cx Starting x-coordinate. * @param[in] cy Starting y-coordinate. */ void RecursiveBacktracker::carve_passages_from(int cx, int cy) { int i, nx, ny, directions[] = {N, S, E, W}; shuffle_array(directions, NUM_DIRECTIONS); for (i = 0; i < NUM_DIRECTIONS; i++) { nx = cx + get_dx(directions[i]); ny = cy + get_dy(directions[i]); if ((nx >= 0 && nx < WIDTH) && (ny >= 0 && ny < HEIGHT) && maze->grid[nx][ny] == 0) { maze->grid[cx][cy] |= directions[i]; maze->grid[nx][ny] |= get_opposite(directions[i]); carve_passages_from(nx, ny); } } }
// isolates the path sorrounding the city void isolate_city(pos_t start, cell_type env[][WIDTH]) { pos_t curr; direction_e camefrom = L; curr.row = start.row; curr.column = start.column; do { env[curr.row][curr.column] = G; pos_t check; direction_e next_d = camefrom; do { next_d = clock(next_d); check = get_pos(curr, next_d); } while (env[check.row][check.column] == S || \ (check.row == curr.row && check.column == curr.column)); camefrom = get_opposite(next_d); curr = check; } while (curr.row != start.row || \ curr.column != start.column); }