mirror of
https://github.com/boostorg/graph.git
synced 2025-05-11 13:24:01 +00:00
Modify astar_maze.cpp to not return a dangling reference from random_maze().
See discussion in https://github.com/boostorg/graph/issues/148.
This commit is contained in:
parent
0310bbee74
commit
32bc0e1dff
@ -79,7 +79,7 @@ typedef boost::vertex_subset_complement_filter<grid, vertex_set>::type
|
|||||||
class maze {
|
class maze {
|
||||||
public:
|
public:
|
||||||
friend std::ostream& operator<<(std::ostream&, const maze&);
|
friend std::ostream& operator<<(std::ostream&, const maze&);
|
||||||
friend maze random_maze(std::size_t, std::size_t);
|
friend void random_maze(maze&);
|
||||||
|
|
||||||
maze():m_grid(create_grid(0, 0)),m_barrier_grid(create_barrier_grid()) {};
|
maze():m_grid(create_grid(0, 0)),m_barrier_grid(create_barrier_grid()) {};
|
||||||
maze(std::size_t x, std::size_t y):m_grid(create_grid(x, y)),
|
maze(std::size_t x, std::size_t y):m_grid(create_grid(x, y)),
|
||||||
@ -119,10 +119,10 @@ private:
|
|||||||
|
|
||||||
// The grid underlying the maze
|
// The grid underlying the maze
|
||||||
grid m_grid;
|
grid m_grid;
|
||||||
// The underlying maze grid with barrier vertices filtered out
|
|
||||||
filtered_grid m_barrier_grid;
|
|
||||||
// The barriers in the maze
|
// The barriers in the maze
|
||||||
vertex_set m_barriers;
|
vertex_set m_barriers;
|
||||||
|
// The underlying maze grid with barrier vertices filtered out
|
||||||
|
filtered_grid m_barrier_grid;
|
||||||
// The vertices on a solution path through the maze
|
// The vertices on a solution path through the maze
|
||||||
vertex_set m_solution;
|
vertex_set m_solution;
|
||||||
// The length of the solution path
|
// The length of the solution path
|
||||||
@ -256,8 +256,7 @@ std::size_t random_int(std::size_t a, std::size_t b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a maze with a random assignment of barriers.
|
// Generate a maze with a random assignment of barriers.
|
||||||
maze random_maze(std::size_t x, std::size_t y) {
|
void random_maze(maze& m) {
|
||||||
maze m(x, y);
|
|
||||||
vertices_size_type n = num_vertices(m.m_grid);
|
vertices_size_type n = num_vertices(m.m_grid);
|
||||||
vertex_descriptor s = m.source();
|
vertex_descriptor s = m.source();
|
||||||
vertex_descriptor g = m.goal();
|
vertex_descriptor g = m.goal();
|
||||||
@ -286,10 +285,8 @@ maze random_maze(std::size_t x, std::size_t y) {
|
|||||||
u = v;
|
u = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main (int argc, char const *argv[]) {
|
int main (int argc, char const *argv[]) {
|
||||||
// The default maze size is 20x10. A different size may be specified on
|
// The default maze size is 20x10. A different size may be specified on
|
||||||
// the command line.
|
// the command line.
|
||||||
@ -302,8 +299,8 @@ int main (int argc, char const *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
random_generator.seed(std::time(0));
|
random_generator.seed(std::time(0));
|
||||||
maze m = random_maze(x, y);
|
maze m(x, y);
|
||||||
|
random_maze(m);
|
||||||
if (m.solve())
|
if (m.solve())
|
||||||
std::cout << "Solved the maze." << std::endl;
|
std::cout << "Solved the maze." << std::endl;
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user