|
|
|
@ -12,20 +12,28 @@ |
|
|
|
|
#include <ftxui/dom/node.hpp> // for Render |
|
|
|
|
#include <ftxui/screen/box.hpp> // for ftxui |
|
|
|
|
#include <ftxui/component/component.hpp> |
|
|
|
|
#include <fmt/core.h> |
|
|
|
|
#include "map.hpp" |
|
|
|
|
#include "dbc.hpp" |
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
|
using namespace std::chrono_literals; |
|
|
|
|
|
|
|
|
|
std::array<std::string, 6> tiles = { |
|
|
|
|
"##########", |
|
|
|
|
"# #", |
|
|
|
|
"# #", |
|
|
|
|
"# |", |
|
|
|
|
"# #", |
|
|
|
|
"##########", |
|
|
|
|
Matrix input = { |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
{1,1,1,0,1,1,1,1,1,1,1,1}, |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matrix walls = { |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
{1,0,0,0,0,1,1,0,0,0,0,1}, |
|
|
|
|
{1,0,0,0,0,0,0,0,0,1,0,1}, |
|
|
|
|
{1,0,0,0,0,1,1,0,0,1,0,1}, |
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
using namespace ftxui; |
|
|
|
@ -35,17 +43,17 @@ int main() { |
|
|
|
|
|
|
|
|
|
// A triangle following the mouse, using braille characters.
|
|
|
|
|
auto map = Renderer([&] { |
|
|
|
|
for(size_t i = 0; i < tiles.size(); ++i) { |
|
|
|
|
c.DrawText(50, 50+i*4, tiles[i]); |
|
|
|
|
} |
|
|
|
|
Matrix result = dijkstra_map(input, walls, 1000); |
|
|
|
|
|
|
|
|
|
for(size_t i = 0; i < tiles[0].size() - 2; i++) { |
|
|
|
|
for(size_t j = 0; j < tiles.size() - 2; j++) { |
|
|
|
|
c.DrawText(52+i*2, 54+j*4, ".", Color::Yellow); |
|
|
|
|
for(size_t x = 0; x < result[0].size(); ++x) { |
|
|
|
|
for(size_t y = 0; y < result.size(); ++y) { |
|
|
|
|
auto val = result[y][x]; |
|
|
|
|
const string tile = val == 1000 ? "#" : fmt::format("{}", result[y][x]); |
|
|
|
|
c.DrawText(22+x*2, 24+y*4, tile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.DrawText(50+3*4, 50+3*4, "@", Color::Blue); |
|
|
|
|
c.DrawText(20+4*2, 20+3*4, "@", Color::Blue); |
|
|
|
|
|
|
|
|
|
return canvas(c); |
|
|
|
|
}); |
|
|
|
|