|
|
@ -15,8 +15,7 @@ void dump_map(const std::string &msg, Matrix &map) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
|
|
|
|
size_t h = closed.size(); |
|
|
|
size_t h = closed.size(); |
|
|
|
size_t w = closed[0].size(); |
|
|
|
size_t w = closed[0].size(); |
|
|
|
vector<size_t> rows{j - 1, j, j + 1}; |
|
|
|
vector<size_t> rows{j - 1, j, j + 1}; |
|
|
@ -35,15 +34,15 @@ void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
void Map::make_paths() { |
|
|
|
size_t h = input_map.size(); |
|
|
|
size_t h = m_input_map.size(); |
|
|
|
size_t w = input_map[0].size(); |
|
|
|
size_t w = m_input_map[0].size(); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize the new array with every pixel at limit distance
|
|
|
|
// Initialize the new array with every pixel at limit distance
|
|
|
|
// NOTE: this is normally ones() * limit
|
|
|
|
// NOTE: this is normally ones() * limit
|
|
|
|
limit = limit == 0 ? h * w : limit; |
|
|
|
int limit = m_limit == 0 ? h * w : m_limit; |
|
|
|
Matrix new_arr = Matrix(h, MatrixRow(w, limit)); |
|
|
|
Matrix new_arr = Matrix(h, MatrixRow(w, limit)); |
|
|
|
Matrix closed = walls_map; |
|
|
|
Matrix closed = m_walls_map; |
|
|
|
PairList starting_pixels; |
|
|
|
PairList starting_pixels; |
|
|
|
PairList open_pixels; |
|
|
|
PairList open_pixels; |
|
|
|
|
|
|
|
|
|
|
@ -51,7 +50,7 @@ Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
for(size_t counter = 0; counter < h * w; counter++) { |
|
|
|
for(size_t counter = 0; counter < h * w; counter++) { |
|
|
|
size_t i = counter % w; |
|
|
|
size_t i = counter % w; |
|
|
|
size_t j = counter / w; |
|
|
|
size_t j = counter / w; |
|
|
|
if(input_map[j][i] == 0) { |
|
|
|
if(m_input_map[j][i] == 0) { |
|
|
|
new_arr[j][i] = 0; |
|
|
|
new_arr[j][i] = 0; |
|
|
|
closed[j][i] = 1; |
|
|
|
closed[j][i] = 1; |
|
|
|
starting_pixels.push_back({.j=j,.i=i}); |
|
|
|
starting_pixels.push_back({.j=j,.i=i}); |
|
|
@ -79,5 +78,5 @@ Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
new_arr[sp.j][sp.i] = counter; |
|
|
|
new_arr[sp.j][sp.i] = counter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new_arr; |
|
|
|
m_paths = new_arr; |
|
|
|
} |
|
|
|
} |
|
|
|