|
|
@ -163,7 +163,7 @@ TEST_CASE("thrash compass iterators", "[matrix:compass]") { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("prototype flood algorithm", "[matrix:flood]") { |
|
|
|
TEST_CASE("prototype flood algorithm", "[matrix:flood]") { |
|
|
|
for(int count = 0; count < 1; count++) { |
|
|
|
for(int count = 0; count < 1000; count++) { |
|
|
|
size_t width = Random::uniform<size_t>(10, 25); |
|
|
|
size_t width = Random::uniform<size_t>(10, 25); |
|
|
|
size_t height = Random::uniform<size_t>(10, 33); |
|
|
|
size_t height = Random::uniform<size_t>(10, 33); |
|
|
|
|
|
|
|
|
|
|
@ -171,32 +171,56 @@ TEST_CASE("prototype flood algorithm", "[matrix:flood]") { |
|
|
|
WorldBuilder builder(map); |
|
|
|
WorldBuilder builder(map); |
|
|
|
builder.generate(); |
|
|
|
builder.generate(); |
|
|
|
|
|
|
|
|
|
|
|
REQUIRE(map.room_count() > 0); |
|
|
|
if(map.room_count() < 2) continue; |
|
|
|
|
|
|
|
|
|
|
|
Point start = map.place_entity(map.room_count() / 2); |
|
|
|
Point start = map.place_entity(map.room_count() / 2); |
|
|
|
|
|
|
|
map.set_target(start); |
|
|
|
|
|
|
|
map.make_paths(); |
|
|
|
|
|
|
|
Matrix result = map.paths(); |
|
|
|
|
|
|
|
|
|
|
|
// BUG: place_entity should not put things in walls
|
|
|
|
// matrix::dump("WALLS BEFORE FLOOD", result, start.x, start.y);
|
|
|
|
map.$walls[start.y][start.x] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrix::dump("WALLS BEFORE FLOOD", map.walls(), start.x, start.y); |
|
|
|
for(matrix::flood it{result, start, 3, 15}; it.next();) { |
|
|
|
|
|
|
|
REQUIRE(matrix::inbounds(result, it.x, it.y)); |
|
|
|
|
|
|
|
result[it.y][it.x] = 15; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// matrix::dump("WALLS AFTER FLOOD", result, start.x, start.y);
|
|
|
|
for(matrix::flood it{map.$walls, start, 0, 10}; it.next_working(); tick++) { |
|
|
|
} |
|
|
|
println("TEST WORKING"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(matrix::flood it{map.$walls, start, 0, 15}; it.next();) { |
|
|
|
TEST_CASE("prototype line algorithm", "[matrix:line]") { |
|
|
|
REQUIRE(matrix::inbounds(map.$walls, it.x, it.y)); |
|
|
|
size_t width = Random::uniform<size_t>(10, 12); |
|
|
|
map.$walls[it.y][it.x] = 15; |
|
|
|
size_t height = Random::uniform<size_t>(10, 15); |
|
|
|
|
|
|
|
Map map(width,height); |
|
|
|
|
|
|
|
// create a target for the paths
|
|
|
|
|
|
|
|
Point start{.x=map.width() / 2, .y=map.height()/2}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(matrix::in_box box{map.walls(), start.x, start.y, 3}; |
|
|
|
|
|
|
|
box.next();) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Matrix result = map.walls(); |
|
|
|
|
|
|
|
result[start.y][start.x] = 1; |
|
|
|
|
|
|
|
Point end{.x=box.x, .y=box.y}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(matrix::line it{start, end}; it.next();) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
REQUIRE(map.inmap(it.x, it.y)); |
|
|
|
|
|
|
|
result[it.y][it.x] = 15; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
matrix::dump("WALLS AFTER FLOOD", map.walls(), start.x, start.y); |
|
|
|
result[start.y][start.x] = 15; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// matrix::dump("RESULT AFTER LINE", result, end.x, end.y);
|
|
|
|
|
|
|
|
|
|
|
|
// confirm that everything is 1 or 2 which confirms
|
|
|
|
bool f_found = false; |
|
|
|
// every cell possible is visited and nothing is visited twice
|
|
|
|
for(matrix::each_cell it{result}; it.next();) { |
|
|
|
for(matrix::each_cell it{map.$walls}; it.next();) { |
|
|
|
if(result[it.y][it.x] == 15) { |
|
|
|
REQUIRE(map.$walls[it.y][it.x] <= 15); |
|
|
|
f_found = true; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REQUIRE(f_found); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|