|
|
|
@ -5,6 +5,7 @@ |
|
|
|
|
#include "matrix.hpp" |
|
|
|
|
#include "rand.hpp" |
|
|
|
|
#include "components.hpp" |
|
|
|
|
#include "worldbuilder.hpp" |
|
|
|
|
#include <nlohmann/json.hpp> |
|
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
|
@ -13,7 +14,7 @@ using namespace fmt; |
|
|
|
|
using std::string; |
|
|
|
|
using matrix::Matrix; |
|
|
|
|
|
|
|
|
|
TEST_CASE("basic matrix iterator", "[matrix]") { |
|
|
|
|
TEST_CASE("basic matrix iterator", "[matrix:basic]") { |
|
|
|
|
std::ifstream infile("./tests/dijkstra.json"); |
|
|
|
|
json data = json::parse(infile); |
|
|
|
|
auto test = data[0]; |
|
|
|
@ -61,6 +62,15 @@ TEST_CASE("basic matrix iterator", "[matrix]") { |
|
|
|
|
} |
|
|
|
|
REQUIRE(row_count == 3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
matrix::compass star{walls, 1, 1}; |
|
|
|
|
while(star.next()) { |
|
|
|
|
println("START IS {},{}=={}", star.x, star.y, walls[star.y][star.x]); |
|
|
|
|
walls[star.y][star.x] = 11; |
|
|
|
|
} |
|
|
|
|
matrix::dump("STAR POINT", walls, 1,1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void random_matrix(Matrix &out) { |
|
|
|
@ -121,3 +131,72 @@ TEST_CASE("thrash box iterators", "[matrix]") { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_CASE("thrash compass iterators", "[matrix:compass]") { |
|
|
|
|
for(int count = 0; count < 2000; count++) { |
|
|
|
|
size_t width = Random::uniform<size_t>(1, 25); |
|
|
|
|
size_t height = Random::uniform<size_t>(1, 33); |
|
|
|
|
|
|
|
|
|
Matrix test(height, matrix::Row(width)); |
|
|
|
|
random_matrix(test); |
|
|
|
|
|
|
|
|
|
// this will be greater than the random_matrix cells
|
|
|
|
|
int test_i = Random::uniform<size_t>(20,30); |
|
|
|
|
|
|
|
|
|
// go through every cell
|
|
|
|
|
for(matrix::each_cell target{test}; target.next();) { |
|
|
|
|
PointList result; |
|
|
|
|
// make a random size box
|
|
|
|
|
matrix::compass compass{test, target.x, target.y}; |
|
|
|
|
|
|
|
|
|
while(compass.next()) { |
|
|
|
|
test[compass.y][compass.x] = test_i; |
|
|
|
|
result.push_back({compass.x, compass.y}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(auto point : result) { |
|
|
|
|
REQUIRE(test[point.y][point.x] == test_i); |
|
|
|
|
test[point.y][point.x] = 10; // kind of reset it for another try
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_CASE("prototype flood algorithm", "[matrix:flood]") { |
|
|
|
|
for(int count = 0; count < 1; count++) { |
|
|
|
|
size_t width = Random::uniform<size_t>(10, 25); |
|
|
|
|
size_t height = Random::uniform<size_t>(10, 33); |
|
|
|
|
|
|
|
|
|
Map map(width,height); |
|
|
|
|
WorldBuilder builder(map); |
|
|
|
|
builder.generate(); |
|
|
|
|
|
|
|
|
|
REQUIRE(map.room_count() > 0); |
|
|
|
|
|
|
|
|
|
Point start = map.place_entity(map.room_count() / 2); |
|
|
|
|
|
|
|
|
|
// BUG: place_entity should not put things in walls
|
|
|
|
|
map.$walls[start.y][start.x] = 0; |
|
|
|
|
|
|
|
|
|
matrix::dump("WALLS BEFORE FLOOD", map.walls(), 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();) { |
|
|
|
|
REQUIRE(matrix::inbounds(map.$walls, it.x, it.y)); |
|
|
|
|
map.$walls[it.y][it.x] = 15; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
matrix::dump("WALLS AFTER FLOOD", map.walls(), start.x, start.y); |
|
|
|
|
|
|
|
|
|
// confirm that everything is 1 or 2 which confirms
|
|
|
|
|
// every cell possible is visited and nothing is visited twice
|
|
|
|
|
for(matrix::each_cell it{map.$walls}; it.next();) { |
|
|
|
|
REQUIRE(map.$walls[it.y][it.x] <= 15); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|