A bit of late night work designing the little iterators.
This commit is contained in:
parent
da0b941dfd
commit
8e470df554
11 changed files with 115 additions and 235 deletions
53
matrix.cpp
53
matrix.cpp
|
@ -3,23 +3,54 @@
|
|||
#include <fmt/core.h>
|
||||
|
||||
using namespace fmt;
|
||||
using matrix::Matrix;
|
||||
|
||||
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];
|
||||
namespace matrix {
|
||||
|
||||
if(int(x) == show_x && int(y) == show_y) {
|
||||
print("{:x}<", col);
|
||||
} else if(col == WALL_PATH_LIMIT) {
|
||||
each_cell::each_cell(Matrix &mat)
|
||||
{
|
||||
height = mat.size();
|
||||
width = mat[0].size();
|
||||
}
|
||||
|
||||
bool each_cell::next() {
|
||||
x++;
|
||||
x *= (x < width);
|
||||
y = y + (x == 0);
|
||||
return y < height;
|
||||
}
|
||||
|
||||
each_row::each_row(Matrix &mat) :
|
||||
$mat(mat)
|
||||
{
|
||||
height = $mat.size();
|
||||
width = $mat[0].size();
|
||||
}
|
||||
|
||||
bool each_row::next() {
|
||||
x++;
|
||||
x *= (x < width);
|
||||
y = y + (x == 0);
|
||||
row = x == width - 1;
|
||||
cell = y < height ? $mat[y][x] : -1;
|
||||
return y < height;
|
||||
}
|
||||
|
||||
void dump(const std::string &msg, Matrix &map, int show_x, int show_y) {
|
||||
println("----------------- {}", msg);
|
||||
|
||||
for(each_row it{map}; it.next();) {
|
||||
if(int(it.x) == show_x && int(it.y) == show_y) {
|
||||
print("{:x}<", it.cell);
|
||||
} else if(it.cell == WALL_PATH_LIMIT) {
|
||||
print("# ");
|
||||
} else if(col > 15) {
|
||||
} else if(it.cell > 15) {
|
||||
print("* ");
|
||||
} else {
|
||||
print("{:x} ", col);
|
||||
print("{:x} ", it.cell);
|
||||
}
|
||||
|
||||
if(it.row) print("\n");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue