Mostly cleaned up world get to handle more rooms and paths, but rando_rect needs to be actually random.

This commit is contained in:
Zed A. Shaw 2025-01-12 14:57:54 -05:00
parent c19c53b15b
commit e9277bf052
11 changed files with 257 additions and 39 deletions

View file

@ -194,7 +194,8 @@ TEST_CASE("prototype flood algorithm", "[matrix:flood]") {
if(map.room_count() < 2) continue;
Point start = map.place_entity(map.room_count() / 2);
Point start;
REQUIRE(map.place_entity(map.room_count() / 2, start));
map.set_target(start);
map.make_paths();
Matrix result = map.paths();
@ -286,7 +287,8 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
size_t view_width = width/2;
size_t view_height = height/2;
Point player = map.place_entity(1);
Point player;
REQUIRE(map.place_entity(1, player));
Point start = map.center_camera(player, view_width, view_height);
size_t end_x = std::min(view_width, map.width() - start.x);
@ -300,3 +302,71 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
}
}
}
TEST_CASE("random rectangle", "[matrix:rando_rect]") {
for(int i = 0; i < 10; i++) {
size_t width = Random::uniform<size_t>(9, 21);
size_t height = Random::uniform<size_t>(13, 25);
Map map(width, height);
WorldBuilder builder(map);
builder.generate_rooms();
map.invert_space();
auto wall_copy = map.walls();
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
Room &room = map.room(rnum);
Point pos;
for(matrix::rando_rect it{map.walls(), room.x, room.y, room.width, room.height}; it.next();)
{
if(map.iswall(it.x, it.y)) {
matrix::dump("BAD RECTANGLE SPOT", map.walls(), it.x, it.y);
}
REQUIRE(!map.iswall(it.x, it.y));
REQUIRE(size_t(it.x) >= room.x);
REQUIRE(size_t(it.y) >= room.y);
REQUIRE(size_t(it.x) <= room.x + room.width);
REQUIRE(size_t(it.y) <= room.y + room.height);
wall_copy[it.y][it.x] = wall_copy[it.y][it.x] + 5;
}
}
matrix::dump("WALLS FILLED", wall_copy);
}
}
TEST_CASE("standard rectangle", "[matrix:rectangle]") {
for(int i = 0; i < 20; i++) {
size_t width = Random::uniform<size_t>(9, 21);
size_t height = Random::uniform<size_t>(13, 25);
Map map(width, height);
WorldBuilder builder(map);
builder.generate_rooms();
map.invert_space();
auto wall_copy = map.walls();
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
Room &room = map.room(rnum);
Point pos;
for(matrix::rectangle it{map.walls(), room.x, room.y, room.width, room.height}; it.next();)
{
if(map.iswall(it.x, it.y)) {
matrix::dump("BAD RECTANGLE SPOT", map.walls(), it.x, it.y);
}
REQUIRE(!map.iswall(it.x, it.y));
REQUIRE(size_t(it.x) >= room.x);
REQUIRE(size_t(it.y) >= room.y);
REQUIRE(size_t(it.x) <= room.x + room.width);
REQUIRE(size_t(it.y) <= room.y + room.height);
wall_copy[it.y][it.x] = wall_copy[it.y][it.x] + 5;
}
}
matrix::dump("WALLS FILLED", wall_copy);
}
}