diff --git a/map.cpp b/map.cpp index c1295bb..0bb06c6 100644 --- a/map.cpp +++ b/map.cpp @@ -5,30 +5,11 @@ #include #include #include +#include "matrix.hpp" using std::vector, std::pair; using namespace fmt; -void dump_map(const std::string &msg, Matrix &map, int show_x, int show_y) { - println("----------------- {}", msg); - for(size_t y = 0; y < map.size(); y++) { - for(size_t x = 0; x < map[y].size(); x++) { - int col = map[y][x]; - - if(int(x) == show_x && int(y) == show_y) { - print("{:x}<", col); - } else if(col == WALL_PATH_LIMIT) { - print("# "); - } else if(col > 15) { - print("* "); - } else { - print("{:x} ", col); - } - } - print("\n"); - } -} - Map::Map(size_t width, size_t height) : $width(width), $height(height), @@ -73,8 +54,8 @@ bool Map::iswall(size_t x, size_t y) { } void Map::dump(int show_x, int show_y) { - dump_map("WALLS", walls(), show_x, show_y); - dump_map("PATHS", paths(), show_x, show_y); + matrix_dump("WALLS", walls(), show_x, show_y); + matrix_dump("PATHS", paths(), show_x, show_y); } bool Map::can_move(Point move_to) { diff --git a/map.hpp b/map.hpp index 6e5b158..9c834a5 100644 --- a/map.hpp +++ b/map.hpp @@ -26,8 +26,6 @@ struct Room { DEFINE_SERIALIZABLE(Room, x, y, width, height); }; -void dump_map(const std::string &msg, Matrix &map, int show_x=-1, int show_y=-1); - class Map { public: size_t $width; diff --git a/matrix.cpp b/matrix.cpp new file mode 100644 index 0000000..3c45046 --- /dev/null +++ b/matrix.cpp @@ -0,0 +1,25 @@ +#include "matrix.hpp" +#include "constants.hpp" +#include + +using namespace fmt; + +void matrix_dump(const std::string &msg, Matrix &map, int show_x, int show_y) { + println("----------------- {}", msg); + for(size_t y = 0; y < map.size(); y++) { + for(size_t x = 0; x < map[y].size(); x++) { + int col = map[y][x]; + + if(int(x) == show_x && int(y) == show_y) { + print("{:x}<", col); + } else if(col == WALL_PATH_LIMIT) { + print("# "); + } else if(col > 15) { + print("* "); + } else { + print("{:x} ", col); + } + } + print("\n"); + } +} diff --git a/matrix.hpp b/matrix.hpp index b34270f..df39410 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include typedef std::vector MatrixRow; typedef std::vector Matrix; @@ -12,3 +13,5 @@ inline void matrix_assign(Matrix &out, int new_value) { row.assign(row.size(), new_value); } } + +void matrix_dump(const std::string &msg, Matrix &map, int show_x=-1, int show_y=-1); diff --git a/meson.build b/meson.build index 0e047df..1bcd3fe 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,7 @@ dependencies = [ ] runtests = executable('runtests', [ + 'matrix.cpp', 'dbc.cpp', 'map.cpp', 'rand.cpp', @@ -55,6 +56,7 @@ runtests = executable('runtests', [ dependencies: dependencies) roguish = executable('roguish', [ + 'matrix.cpp', 'dbc.cpp', 'main.cpp', 'map.cpp', diff --git a/tests/dijkstra.json b/tests/dijkstra.json index 3cdd8d6..cafb3c2 100644 --- a/tests/dijkstra.json +++ b/tests/dijkstra.json @@ -14,8 +14,8 @@ "expected": [ [1, 1, 1, 0], [1, 0, 1, 1], - [1, 0, 10, 2], - [1, 1, 10, 3] + [1, 0, 1000, 2], + [1, 1, 1000, 3] ] },{ "input": [ @@ -33,7 +33,7 @@ "expected": [ [1, 1, 1, 0], [1, 0, 1, 1], - [1, 0, 16, 2], - [1, 1, 16, 3] + [1, 0, 1000, 2], + [1, 1, 1000, 3] ] }] diff --git a/tests/map.cpp b/tests/map.cpp index 9ea1fcb..68cf2fd 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -48,8 +48,8 @@ TEST_CASE("dijkstra algo test", "[map]") { if(paths != expected) { println("ERROR! ------"); - dump_map("EXPECTED", expected); - dump_map("RESULT", paths); + matrix_dump("EXPECTED", expected); + matrix_dump("RESULT", paths); } REQUIRE(map.INVARIANT()); diff --git a/tests/pathing.cpp b/tests/pathing.cpp index 8ab2ae2..c4df3a4 100644 --- a/tests/pathing.cpp +++ b/tests/pathing.cpp @@ -3,7 +3,7 @@ #include #include #include "pathing.hpp" -#include "map.hpp" +#include "matrix.hpp" using namespace fmt; using namespace nlohmann; @@ -30,6 +30,8 @@ TEST_CASE("dijkstra algo test", "[pathing]") { REQUIRE(pathing.INVARIANT()); - // REQUIRE(pathing.$paths == expected); + matrix_dump("PATHING RESULT", pathing.$paths); + matrix_dump("PATHING EXPECTED", expected); + REQUIRE(pathing.$paths == expected); } } diff --git a/tests/worldbuilder.cpp b/tests/worldbuilder.cpp index 218d133..052c6ed 100644 --- a/tests/worldbuilder.cpp +++ b/tests/worldbuilder.cpp @@ -20,7 +20,7 @@ TEST_CASE("dumping and debugging", "[builder]") { WorldBuilder builder(map); builder.generate(); - dump_map("GENERATED", map.paths()); + matrix_dump("GENERATED", map.paths()); map.dump(); }