Refactored the maze functions to be a builder that can do different things to the maze. Also when I hit p in the game it'll save the map to a file. This was extremely hard for no reason.

This commit is contained in:
Zed A. Shaw 2025-05-21 13:56:53 -04:00
parent 20f03731e5
commit 5f1a453fb4
8 changed files with 270 additions and 254 deletions

View file

@ -9,112 +9,98 @@
using std::string;
using matrix::Matrix;
TEST_CASE("hunt-and-kill", "[mazes]") {
auto map = matrix::make(21, 21);
std::vector<Room> rooms;
std::vector<Point> dead_ends;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze::hunt_and_kill(map, rooms, dead_ends);
matrix::dump("BASIC MAZE", map);
maze.hunt_and_kill();
maze.dump("BASIC MAZE");
maze::randomize_rooms(rooms, dead_ends);
maze::hunt_and_kill(map, rooms, dead_ends);
maze.randomize_rooms();
maze.hunt_and_kill();
for(auto& room : rooms) {
for(matrix::box it{map, room.x, room.y, room.width};
REQUIRE(map.$dead_ends.size() > 0);
REQUIRE(map.$rooms.size() > 0);
for(auto& room : maze.$rooms) {
for(matrix::box it{maze.$walls, room.x, room.y, room.width};
it.next();)
{
map[it.y][it.x] = WALL_PATH_LIMIT;
maze.$walls[it.y][it.x] = WALL_PATH_LIMIT;
}
}
matrix::dump("MAZE WITH ROOMS", map);
maze.dump("MAZE WITH ROOMS");
}
TEST_CASE("hunt-and-kill box", "[mazes]") {
auto map = matrix::make(21, 21);
std::vector<Room> rooms;
std::vector<Point> dead_ends;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze::inner_box(map, 5, 3);
maze::hunt_and_kill(map, rooms, dead_ends);
maze.inner_box(5, 3);
maze.hunt_and_kill();
for(auto at : dead_ends) {
map[at.y][at.x]=32;
for(auto at : maze.$dead_ends) {
maze.$walls[at.y][at.x]=32;
}
matrix::dump("INNER BOX", map);
maze.dump("INNER BOX");
REQUIRE(rooms.size() == 0);
REQUIRE(maze.$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;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze::inner_donut(map, 5.5, 3.5);
maze::hunt_and_kill(map, rooms, dead_ends);
maze.inner_donut(5.5, 3.5);
maze.hunt_and_kill();
for(auto at : dead_ends) {
map[at.y][at.x]=32;
for(auto at : maze.$dead_ends) {
maze.$walls[at.y][at.x]=32;
}
matrix::dump("INNER RING", map);
maze.dump("INNER RING");
REQUIRE(rooms.size() == 0);
REQUIRE(maze.$rooms.size() == 0);
}
TEST_CASE("hunt-and-kill fissure", "[mazes]") {
auto map = matrix::make(21, 21);
std::vector<Room> rooms;
std::vector<Point> dead_ends;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze::divide(map, {3,3}, {19,18});
maze::hunt_and_kill(map, rooms, dead_ends);
maze.divide({3,3}, {19,18});
maze.hunt_and_kill();
for(auto at : dead_ends) {
map[at.y][at.x]=32;
for(auto at : maze.$dead_ends) {
maze.$walls[at.y][at.x]=32;
}
matrix::dump("FISSURE MAZE", map);
maze.dump("FISSURE MAZE");
REQUIRE(rooms.size() == 0);
REQUIRE(maze.$rooms.size() == 0);
}
TEST_CASE("hunt-and-kill no-dead-ends", "[mazes]") {
auto map = matrix::make(21, 21);
std::vector<Room> rooms;
std::vector<Point> dead_ends;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze.hunt_and_kill();
maze::hunt_and_kill(map, rooms, dead_ends);
maze.remove_dead_ends();
maze::remove_dead_ends(map, dead_ends);
matrix::dump("NO DEAD ENDS", map);
maze.dump("NO DEAD ENDS");
}
TEST_CASE("hunt-and-kill too much", "[mazes]") {
auto map = matrix::make(21, 21);
std::vector<Room> rooms;
std::vector<Point> dead_ends;
Map map(21, 21);
maze::Builder maze(map);
maze::init(map);
maze::inner_donut(map, 4, 2);
maze::divide(map, {3,3}, {19,18});
auto copy = map;
maze.hunt_and_kill();
maze.randomize_rooms();
maze.init();
maze.inner_donut(4, 2);
maze.divide({3,3}, {19,18});
maze.hunt_and_kill();
maze::hunt_and_kill(copy, rooms, dead_ends);
map = copy;
maze::randomize_rooms(rooms, dead_ends);
maze::hunt_and_kill(map, rooms, dead_ends);
matrix::dump("COMBINED", map);
maze.dump("COMBINED");
}