Matrix now just does the dumping but I need to make this more formal I think.
This commit is contained in:
parent
eb0ca38e30
commit
56b26e1c4a
9 changed files with 44 additions and 33 deletions
25
map.cpp
25
map.cpp
|
@ -5,30 +5,11 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "matrix.hpp"
|
||||||
|
|
||||||
using std::vector, std::pair;
|
using std::vector, std::pair;
|
||||||
using namespace fmt;
|
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) :
|
Map::Map(size_t width, size_t height) :
|
||||||
$width(width),
|
$width(width),
|
||||||
$height(height),
|
$height(height),
|
||||||
|
@ -73,8 +54,8 @@ bool Map::iswall(size_t x, size_t y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::dump(int show_x, int show_y) {
|
void Map::dump(int show_x, int show_y) {
|
||||||
dump_map("WALLS", walls(), show_x, show_y);
|
matrix_dump("WALLS", walls(), show_x, show_y);
|
||||||
dump_map("PATHS", paths(), show_x, show_y);
|
matrix_dump("PATHS", paths(), show_x, show_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::can_move(Point move_to) {
|
bool Map::can_move(Point move_to) {
|
||||||
|
|
2
map.hpp
2
map.hpp
|
@ -26,8 +26,6 @@ struct Room {
|
||||||
DEFINE_SERIALIZABLE(Room, x, y, width, height);
|
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 {
|
class Map {
|
||||||
public:
|
public:
|
||||||
size_t $width;
|
size_t $width;
|
||||||
|
|
25
matrix.cpp
Normal file
25
matrix.cpp
Normal file
|
@ -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
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
typedef std::vector<int> MatrixRow;
|
typedef std::vector<int> MatrixRow;
|
||||||
typedef std::vector<MatrixRow> Matrix;
|
typedef std::vector<MatrixRow> Matrix;
|
||||||
|
@ -12,3 +13,5 @@ inline void matrix_assign(Matrix &out, int new_value) {
|
||||||
row.assign(row.size(), 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', [
|
runtests = executable('runtests', [
|
||||||
|
'matrix.cpp',
|
||||||
'dbc.cpp',
|
'dbc.cpp',
|
||||||
'map.cpp',
|
'map.cpp',
|
||||||
'rand.cpp',
|
'rand.cpp',
|
||||||
|
@ -55,6 +56,7 @@ runtests = executable('runtests', [
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
roguish = executable('roguish', [
|
roguish = executable('roguish', [
|
||||||
|
'matrix.cpp',
|
||||||
'dbc.cpp',
|
'dbc.cpp',
|
||||||
'main.cpp',
|
'main.cpp',
|
||||||
'map.cpp',
|
'map.cpp',
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
"expected": [
|
"expected": [
|
||||||
[1, 1, 1, 0],
|
[1, 1, 1, 0],
|
||||||
[1, 0, 1, 1],
|
[1, 0, 1, 1],
|
||||||
[1, 0, 10, 2],
|
[1, 0, 1000, 2],
|
||||||
[1, 1, 10, 3]
|
[1, 1, 1000, 3]
|
||||||
]
|
]
|
||||||
},{
|
},{
|
||||||
"input": [
|
"input": [
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
"expected": [
|
"expected": [
|
||||||
[1, 1, 1, 0],
|
[1, 1, 1, 0],
|
||||||
[1, 0, 1, 1],
|
[1, 0, 1, 1],
|
||||||
[1, 0, 16, 2],
|
[1, 0, 1000, 2],
|
||||||
[1, 1, 16, 3]
|
[1, 1, 1000, 3]
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
|
|
@ -48,8 +48,8 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
||||||
|
|
||||||
if(paths != expected) {
|
if(paths != expected) {
|
||||||
println("ERROR! ------");
|
println("ERROR! ------");
|
||||||
dump_map("EXPECTED", expected);
|
matrix_dump("EXPECTED", expected);
|
||||||
dump_map("RESULT", paths);
|
matrix_dump("RESULT", paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(map.INVARIANT());
|
REQUIRE(map.INVARIANT());
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "pathing.hpp"
|
#include "pathing.hpp"
|
||||||
#include "map.hpp"
|
#include "matrix.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
@ -30,6 +30,8 @@ TEST_CASE("dijkstra algo test", "[pathing]") {
|
||||||
|
|
||||||
REQUIRE(pathing.INVARIANT());
|
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);
|
WorldBuilder builder(map);
|
||||||
builder.generate();
|
builder.generate();
|
||||||
|
|
||||||
dump_map("GENERATED", map.paths());
|
matrix_dump("GENERATED", map.paths());
|
||||||
map.dump();
|
map.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue