A slightly working flood iterator and a working compass iterator.
This commit is contained in:
parent
043c0d91df
commit
1295e9631d
6 changed files with 214 additions and 4 deletions
46
matrix.hpp
46
matrix.hpp
|
@ -1,11 +1,18 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <fmt/core.h>
|
||||
#include "point.hpp"
|
||||
|
||||
using fmt::println;
|
||||
|
||||
namespace matrix {
|
||||
using std::vector, std::queue, std::array;
|
||||
|
||||
typedef std::vector<int> Row;
|
||||
typedef std::vector<Row> Matrix;
|
||||
typedef vector<int> Row;
|
||||
typedef vector<Row> Matrix;
|
||||
|
||||
struct each_cell {
|
||||
size_t x = ~0;
|
||||
|
@ -42,6 +49,18 @@ namespace matrix {
|
|||
void dump();
|
||||
};
|
||||
|
||||
struct compass {
|
||||
size_t x = 0; // these are set in constructor
|
||||
size_t y = 0; // again, no fancy ~ trick needed
|
||||
array<int, 4> x_dirs{0, 1, 0, -1};
|
||||
array<int, 4> y_dirs{-1, 0, 1, 0};
|
||||
size_t max_dirs=0;
|
||||
size_t dir = ~0;
|
||||
|
||||
compass(Matrix &mat, size_t x, size_t y);
|
||||
bool next();
|
||||
};
|
||||
|
||||
/*
|
||||
* Just a quick thing to reset a matrix to a value.
|
||||
*/
|
||||
|
@ -51,5 +70,28 @@ namespace matrix {
|
|||
}
|
||||
}
|
||||
|
||||
inline bool inbounds(Matrix &mat, size_t x, size_t y) {
|
||||
// since Point.x and Point.y are size_t any negatives are massive
|
||||
bool res = (y < mat.size()) && (x < mat[0].size());
|
||||
return res;
|
||||
}
|
||||
|
||||
void dump(const std::string &msg, Matrix &map, int show_x=-1, int show_y=-1);
|
||||
|
||||
struct flood {
|
||||
Matrix &mat;
|
||||
Point start;
|
||||
int old_val;
|
||||
int new_val;
|
||||
queue<Point> q;
|
||||
Point current_loc;
|
||||
int x;
|
||||
int y;
|
||||
matrix::compass dirs;
|
||||
|
||||
flood(Matrix &mat, Point start, int old_val, int new_val);
|
||||
bool next();
|
||||
bool next_working();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue