Matrix now just does the dumping but I need to make this more formal I think.

main
Zed A. Shaw 7 days ago
parent eb0ca38e30
commit 56b26e1c4a
  1. 25
      map.cpp
  2. 2
      map.hpp
  3. 25
      matrix.cpp
  4. 3
      matrix.hpp
  5. 2
      meson.build
  6. 8
      tests/dijkstra.json
  7. 4
      tests/map.cpp
  8. 6
      tests/pathing.cpp
  9. 2
      tests/worldbuilder.cpp

@ -5,30 +5,11 @@
#include <array>
#include <fmt/core.h>
#include <utility>
#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) {

@ -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;

@ -0,0 +1,25 @@
#include "matrix.hpp"
#include "constants.hpp"
#include <fmt/core.h>
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");
}
}

@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include <string>
typedef std::vector<int> MatrixRow;
typedef std::vector<MatrixRow> 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);

@ -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',

@ -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]
]
}]

@ -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());

@ -3,7 +3,7 @@
#include <nlohmann/json.hpp>
#include <fstream>
#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);
}
}

@ -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();
}

Loading…
Cancel
Save