Cleaned up maze and ready to use.
This commit is contained in:
parent
33cd490ed3
commit
37715f05a5
3 changed files with 53 additions and 18 deletions
29
maze.cpp
29
maze.cpp
|
@ -119,11 +119,7 @@ void maze::divide(Matrix& maze, Point start, Point end) {
|
|||
}
|
||||
}
|
||||
|
||||
void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends, bool init_map) {
|
||||
|
||||
if(init_map) {
|
||||
maze::init(maze);
|
||||
}
|
||||
void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends) {
|
||||
|
||||
for(auto& room : rooms) {
|
||||
for(matrix::box it{maze, room.x, room.y, room.width}; it.next();) {
|
||||
|
@ -173,7 +169,28 @@ void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Poi
|
|||
}
|
||||
}
|
||||
|
||||
void maze::inner_ring(Matrix& maze, size_t outer_size, size_t inner_size) {
|
||||
void maze::inner_donut(Matrix& maze, float outer_rad, float inner_rad) {
|
||||
size_t x = matrix::width(maze) / 2;
|
||||
size_t y = matrix::height(maze) / 2;
|
||||
|
||||
for(matrix::circle it{maze, {x, y}, outer_rad};
|
||||
it.next();)
|
||||
{
|
||||
for(int x = it.left; x < it.right; x++) {
|
||||
maze[it.y][x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for(matrix::circle it{maze, {x, y}, inner_rad};
|
||||
it.next();)
|
||||
{
|
||||
for(int x = it.left; x < it.right; x++) {
|
||||
maze[it.y][x] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void maze::inner_box(Matrix& maze, size_t outer_size, size_t inner_size) {
|
||||
|
||||
size_t x = matrix::width(maze) / 2;
|
||||
size_t y = matrix::height(maze) / 2;
|
||||
|
|
5
maze.hpp
5
maze.hpp
|
@ -6,11 +6,12 @@ namespace maze {
|
|||
|
||||
void init(Matrix& maze);
|
||||
|
||||
void hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends, bool init_map=true);
|
||||
void hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends);
|
||||
|
||||
void randomize_rooms(std::vector<Room>& rooms_out, std::vector<Point> maybe_here);
|
||||
|
||||
void inner_ring(Matrix& map, size_t outer_size, size_t inner_size);
|
||||
void inner_donut(Matrix& maze, float outer_rad, float inner_rad);
|
||||
void inner_box(Matrix& map, size_t outer_size, size_t inner_size);
|
||||
|
||||
void divide(Matrix& maze, Point start, Point end);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ TEST_CASE("hunt-and-kill", "[mazes]") {
|
|||
std::vector<Room> rooms;
|
||||
std::vector<Point> dead_ends;
|
||||
|
||||
maze::init(map);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
matrix::dump("BASIC MAZE", map);
|
||||
|
||||
|
@ -32,19 +33,36 @@ TEST_CASE("hunt-and-kill", "[mazes]") {
|
|||
matrix::dump("MAZE WITH ROOMS", map);
|
||||
}
|
||||
|
||||
TEST_CASE("hunt-and-kill box", "[mazes]") {
|
||||
auto map = matrix::make(21, 21);
|
||||
std::vector<Room> rooms;
|
||||
std::vector<Point> dead_ends;
|
||||
|
||||
maze::init(map);
|
||||
maze::inner_box(map, 5, 3);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
|
||||
for(auto at : dead_ends) {
|
||||
map[at.y][at.x]=32;
|
||||
}
|
||||
matrix::dump("INNER BOX", map);
|
||||
|
||||
REQUIRE(rooms.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("hunt-and-kill ring", "[mazes]") {
|
||||
auto map = matrix::make(21, 21);
|
||||
std::vector<Room> rooms;
|
||||
std::vector<Point> dead_ends;
|
||||
|
||||
maze::init(map);
|
||||
maze::inner_ring(map, 5, 2);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends, false);
|
||||
maze::inner_donut(map, 5.5, 3.5);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
|
||||
for(auto at : dead_ends) {
|
||||
map[at.y][at.x]=32;
|
||||
}
|
||||
matrix::dump("RING MAZE", map);
|
||||
matrix::dump("INNER RING", map);
|
||||
|
||||
REQUIRE(rooms.size() == 0);
|
||||
}
|
||||
|
@ -56,7 +74,7 @@ TEST_CASE("hunt-and-kill fissure", "[mazes]") {
|
|||
|
||||
maze::init(map);
|
||||
maze::divide(map, {3,3}, {19,18});
|
||||
maze::hunt_and_kill(map, rooms, dead_ends, false);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
|
||||
for(auto at : dead_ends) {
|
||||
map[at.y][at.x]=32;
|
||||
|
@ -75,7 +93,7 @@ TEST_CASE("hunt-and-kill no-dead-ends", "[mazes]") {
|
|||
|
||||
maze::init(map);
|
||||
|
||||
maze::hunt_and_kill(map, rooms, dead_ends, false);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
|
||||
maze::remove_dead_ends(map, dead_ends);
|
||||
|
||||
|
@ -88,16 +106,15 @@ TEST_CASE("hunt-and-kill too much", "[mazes]") {
|
|||
std::vector<Point> dead_ends;
|
||||
|
||||
maze::init(map);
|
||||
maze::inner_ring(map, 4, 2);
|
||||
maze::inner_donut(map, 4, 2);
|
||||
maze::divide(map, {3,3}, {19,18});
|
||||
auto copy = map;
|
||||
|
||||
maze::hunt_and_kill(copy, rooms, dead_ends, false);
|
||||
|
||||
maze::hunt_and_kill(copy, rooms, dead_ends);
|
||||
|
||||
map = copy;
|
||||
maze::randomize_rooms(rooms, dead_ends);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends, false);
|
||||
maze::hunt_and_kill(map, rooms, dead_ends);
|
||||
|
||||
matrix::dump("NO DEAD ENDS", map);
|
||||
matrix::dump("COMBINED", map);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue