From 4f25fa9ae42a0d43c20e954e8e50c66a6b057c92 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 27 Oct 2023 17:20:23 -0400 Subject: We can output a code for witnesspuzzles --- ext/wittle_generator/Generate.cpp | 57 ++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 13 deletions(-) (limited to 'ext/wittle_generator/Generate.cpp') diff --git a/ext/wittle_generator/Generate.cpp b/ext/wittle_generator/Generate.cpp index 22c211f..5776386 100644 --- a/ext/wittle_generator/Generate.cpp +++ b/ext/wittle_generator/Generate.cpp @@ -55,6 +55,33 @@ void Generate::initPanel() { init_treehouse_layout(); } + if (_custom_grid.size() > + 0) { // If we want to start with a certain default grid when generating + if (_custom_grid.size() < _panel->width()) { + _custom_grid.resize(_panel->width()); + } + if (_custom_grid[_custom_grid.size() - 1].size() < _panel->height()) { + for (auto& row : _custom_grid) { + row.resize(_panel->height()); + } + } + for (int x = 0; x < _panel->width(); x++) { + for (int y = 0; y < _panel->height(); y++) { + set(x, y, _custom_grid[x][y]); + } + } + } + // Sync up start/exit points between panel and generator. If both are + // different, the generator's start/exit point list will be used + for (Point e : _starts) { + _panel->SetGridSymbol(e.first, e.second, Decoration::Start, + Decoration::Color::None); + } + for (Point e : _exits) { + _panel->SetGridSymbol(e.first, e.second, Decoration::Exit, + Decoration::Color::None); + } + // Fill gridpos with every available grid block _gridpos.clear(); for (int x = 1; x < _panel->width(); x += 2) { @@ -503,6 +530,9 @@ bool Generate::generateInternal(int width, int height, PuzzleSymbols symbols) { std::cout << row << std::endl; } + erase_path(); + std::cout << _panel->Write() << std::endl; + return true; } @@ -944,12 +974,14 @@ bool Generate::place_start(int amount) { } if (adjacent && Random::rand() % 10 > 0) continue; _starts.insert(pos); - set(pos.first, pos.second, Decoration::Start | Decoration::Color::None); + _panel->SetGridSymbol(pos.first, pos.second, Decoration::Start, + Decoration::Color::None); amount--; if (_panel->symmetry) { Point sp = get_sym_point(pos); _starts.insert(sp); - set(sp.first, sp.second, Decoration::Start | Decoration::Color::None); + _panel->SetGridSymbol(sp.first, sp.second, Decoration::Start, + Decoration::Color::None); } } return true; @@ -994,12 +1026,14 @@ bool Generate::place_exit(int amount) { } if (adjacent) continue; _exits.insert(pos); - set(pos.first, pos.second, Decoration::Exit | Decoration::Color::None); + _panel->SetGridSymbol(pos.first, pos.second, Decoration::Exit, + Decoration::Color::None); amount--; if (_panel->symmetry) { Point sp = get_sym_point(pos); _exits.insert(sp); - set(sp.first, sp.second, Decoration::Exit | Decoration::Color::None); + _panel->SetGridSymbol(sp.first, sp.second, Decoration::Exit, + Decoration::Color::None); } } return true; @@ -1123,8 +1157,7 @@ bool Generate::can_place_dot(Point pos, bool intersectionOnly) { } // Place the given amount of dots at random points on the path -bool Generate::place_dots(int amount, Decoration::Color color, - bool intersectionOnly) { +bool Generate::place_dots(int amount, int color, bool intersectionOnly) { if (_parity != -1) { // For full dot puzzles, don't put dots on the starts // and exits unless there are multiple for (int x = 0; x < _panel->width(); x += 2) { @@ -1141,19 +1174,17 @@ bool Generate::place_dots(int amount, Decoration::Color color, setFlagOnce(Config::DisableDotIntersection); } - /*if (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) + if (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) color = IntersectionFlags::DOT_IS_BLUE; else if (color == Decoration::Color::Yellow || color == Decoration::Color::Orange) color = IntersectionFlags::DOT_IS_ORANGE; else - color = 0;*/ + color = 0; - std::set open = - (color == 0 ? _path - : (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) - ? _path1 - : _path2); + std::set open = (color == 0 ? _path + : (color == IntersectionFlags::DOT_IS_BLUE) ? _path1 + : _path2); for (Point p : _starts) open.erase(p); for (Point p : _exits) open.erase(p); for (Point p : blockPos) open.erase(p); -- cgit 1.4.1