Added debug check macro and some formats

This commit is contained in:
Dmitriy Shishkov 2022-05-31 09:03:38 +03:00
parent 12583220a3
commit ec43ed7c52
No known key found for this signature in database
GPG Key ID: 26720CB2A9608C97
3 changed files with 17 additions and 8 deletions

View File

@ -45,7 +45,9 @@ void Controller::fillSolveableTable() {
auto next_ptr = positions.begin(); auto next_ptr = positions.begin();
while (!positions.empty() || (not_end && !(positions.insert(getRandLowest()), positions.empty()))) { while (
!positions.empty() ||
(not_end && !(positions.insert(getRandLowest()), positions.empty()))) {
int id = genRandId(); int id = genRandId();
if (id < 34) { if (id < 34) {
@ -74,21 +76,27 @@ wxPoint Controller::getRandLowest() {
return {x, y}; return {x, y};
} }
#ifdef WXDEBUG
#include <wx/file.h> #include <wx/file.h>
void print_list(const std::set<ThreePoint>& positions) { void print_list(const std::set<ThreePoint>& positions) {
wxFile f("tmp.txt", wxFile::write_append); wxFile f("tmp.txt", wxFile::write_append);
for (const auto& el : positions) for (const auto& el : positions)
f.Write(itowxS(el.z) + " " + itowxS(el.x) + " " + itowxS(el.y) + "\n"); f.Write(itowxS(el.z) + " " + itowxS(el.x) + " " + itowxS(el.y) + "\n");
f.Write("_ size: " + itowxS(positions.size()) + "\n"); f.Write("_ size: " + itowxS(positions.size()) + "\n");
} }
#endif
void Controller::emplace_rand(int id, std::set<ThreePoint>& positions, void Controller::emplace_rand(int id, std::set<ThreePoint>& positions,
std::set<ThreePoint>::iterator& next_ptr, std::set<ThreePoint>::iterator& next_ptr,
bool canBeUp) { bool canBeUp) {
#ifdef WXDEBUG
print_list(positions); print_list(positions);
#endif
table[next_ptr->z][next_ptr->x][next_ptr->y] = id; table[next_ptr->z][next_ptr->x][next_ptr->y] = id;
@ -99,7 +107,7 @@ void Controller::emplace_rand(int id, std::set<ThreePoint>& positions,
do { do {
next_ptr++; next_ptr++;
if (next_ptr == positions.end()) if (next_ptr == positions.end())
next_ptr = positions.begin(); next_ptr = positions.begin();
} while (!canBeUp && !wouldBeUpFree(prev, *next_ptr)); } while (!canBeUp && !wouldBeUpFree(prev, *next_ptr));
@ -121,6 +129,7 @@ void Controller::push_available(std::set<ThreePoint>& positions,
const ThreePoint& pos) { const ThreePoint& pos) {
int z = pos.z, x = pos.x, y = pos.y; int z = pos.z, x = pos.x, y = pos.y;
// clang-format off
if (x >= 2 && table[z][x-2][y] == FREE) // left if (x >= 2 && table[z][x-2][y] == FREE) // left
positions.emplace(z, x-2, y); positions.emplace(z, x-2, y);
if (x + 2 < gridSize.x && table[z][x+2][y] == FREE) // right if (x + 2 < gridSize.x && table[z][x+2][y] == FREE) // right
@ -176,6 +185,7 @@ void Controller::push_available(std::set<ThreePoint>& positions,
positions.emplace(z+1, x+1, y+1); positions.emplace(z+1, x+1, y+1);
} }
} }
// clang-format on
} }
void Controller::free_table() { void Controller::free_table() {

View File

@ -140,9 +140,8 @@ bool Drawer::resizeBoard(const TLVec& layout, const Dimensions& gridSize) {
tilePixelSize.Set(gridPoint * TILE_WIDTH, gridPoint * TILE_HEIGHT); tilePixelSize.Set(gridPoint * TILE_WIDTH, gridPoint * TILE_HEIGHT);
} }
tablePixelRect.SetPosition( tablePixelRect.SetPosition({(resolution.x - tablePixelRect.width) / 2,
{(resolution.x - tablePixelRect.width) / 2, (resolution.y - tablePixelRect.height) / 2});
(resolution.y - tablePixelRect.height) / 2});
if (gridPoint != prevGridPoint) { if (gridPoint != prevGridPoint) {
composeBoard(layout, gridSize); composeBoard(layout, gridSize);

View File

@ -31,7 +31,7 @@ public:
ThreePoint() : x(0), y(0), z(0){}; ThreePoint() : x(0), y(0), z(0){};
bool operator<(const ThreePoint& b) const { bool operator<(const ThreePoint& b) const {
return z*144*144+x*144+y < b.z*144*144+b.x*144+b.y; return z * 144 * 144 + x * 144 + y < b.z * 144 * 144 + b.x * 144 + b.y;
} }
bool operator==(const ThreePoint& b) { bool operator==(const ThreePoint& b) {