Jank thoughts on using the dijk map to walk from door to door for tunnels.

main
Zed A. Shaw 1 week ago
parent b100950877
commit a82944f55a
  1. 15
      main.cpp
  2. 31
      map.cpp
  3. 4
      map.hpp

@ -12,6 +12,8 @@
#include <ftxui/dom/node.hpp> // for Render
#include <ftxui/screen/box.hpp> // for ftxui
#include <ftxui/component/component.hpp>
#include <ftxui/screen/color.hpp>
#include <fmt/core.h>
#include "map.hpp"
#include "dbc.hpp"
@ -31,10 +33,10 @@ int main() {
Matrix &input_map = game_map.input_map();
Matrix &walls = game_map.walls();
input_map[10][10] = 0;
// place character
// input_map[10][10] = 0;
auto map = Renderer([&] {
game_map.make_paths();
Matrix &result = game_map.paths();
for(size_t x = 0; x < result[0].size(); ++x) {
@ -43,11 +45,12 @@ int main() {
if(path == 1000) {
// it's a wall or unreachable, use the wall_map
const string tile = walls[y][x] == 1 ? "#" : ".";
c.DrawText(x*2, y*4, tile);
c.DrawText(x*2, y*4, tile, Color::Yellow);
} else {
// it's a path number, show it
const string tile = format("{}", path);
c.DrawText(x*2, y*4, tile);
Color color = path == 0 ? Color::Red : Color::GrayDark;
c.DrawText(x*2, y*4, tile, color);
}
}
}
@ -58,7 +61,6 @@ int main() {
return canvas(c);
});
while (true) {
auto document = hbox({
hflow(
vbox(
@ -77,8 +79,5 @@ int main() {
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
return 0;
}

@ -42,7 +42,7 @@ inline void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t
}
Map::Map(size_t width, size_t height) : m_limit(1000) {
m_walls = Matrix(height, MatrixRow(width, 1));
m_walls = Matrix(height, MatrixRow(width, 0));
m_input_map = Matrix(height, MatrixRow(width, 1));
}
@ -94,7 +94,6 @@ void Map::make_paths() {
}
void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
println("MAKE ROOM x={}, y={}, w={}, h={}", origin_x, origin_y, w, h);
dbc::pre("x out of bounds", origin_x < width());
dbc::pre("y out of bounds", origin_y < height());
dbc::pre("w out of bounds", w <= width());
@ -104,7 +103,7 @@ void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
dbc::check(y < m_walls.size(), "y is out of bounds");
for(size_t x = origin_x; x < origin_x + w; ++x) {
dbc::check(x < m_walls[y].size(), "x is out of bounds");
m_walls[y][x] = 0;
m_walls[y][x] = 1;
}
}
}
@ -121,7 +120,6 @@ inline int make_split(Room &cur, bool horiz) {
}
void Map::partition_map(Room &cur, int depth) {
if(cur.width >= 5 && cur.width <= 10 &&
cur.height >= 5 && cur.height <= 10) {
m_rooms.push_back(cur);
@ -158,9 +156,12 @@ void Map::partition_map(Room &cur, int depth) {
}
}
void Map::draw_map(Room &cur) {
for(auto cur : m_rooms) {
void Map::place_rooms(Room &cur) {
for(auto &cur : m_rooms) {
make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2);
cur.door_x = cur.x+1;
cur.door_y = cur.y;
m_input_map[cur.door_y][cur.door_x] = 0;
}
}
@ -172,8 +173,22 @@ void Map::generate() {
.height = height()
};
partition_map(root, 6);
draw_map(root); // left
partition_map(root, 10);
place_rooms(root);
make_paths();
Room &room0 = m_rooms[0];
Room &room1 = m_rooms[1];
int cur = m_paths[room0.door_y][room0.door_x];
int next = m_paths[room0.door_y][room0.door_x+1];
int i = 1;
while(next >= cur) {
cur = next;
next = m_paths[room0.door_y][room0.door_x+i];
++i;
println("door_y: {}, door_x: {}, CUR: {}, NEXT: {}", room0.door_y, room0.door_x, cur, next);
}
}

@ -16,6 +16,8 @@ struct Room {
size_t y = 0;
size_t width = 0;
size_t height = 0;
size_t door_x = 0;
size_t door_y = 0;
std::vector<Room> next;
};
@ -57,7 +59,7 @@ public:
void make_room(size_t origin_y, size_t origin_x, size_t width, size_t height);
void generate();
void draw_map(Room &root);
void place_rooms(Room &root);
void make_paths();
void partition_map(Room &cur, int depth);
void dump();

Loading…
Cancel
Save