From c60df0e75e63f488d94fd744ad70df8124dc7724 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Aug 2021 17:12:29 -0400 Subject: Souped up the UI --- Source/Randomizer2Core.cpp | 203 --------------------------------------------- 1 file changed, 203 deletions(-) delete mode 100644 Source/Randomizer2Core.cpp (limited to 'Source/Randomizer2Core.cpp') diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp deleted file mode 100644 index 867fa5a..0000000 --- a/Source/Randomizer2Core.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include "pch.h" -#include "Randomizer2Core.h" -#include "Random.h" - -std::vector Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) { - return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges); -} - -std::vector Randomizer2Core::CutInsideEdges(const Puzzle& p, size_t numEdges) { - return CutEdgesInternal(p, 1, p.width-1, 1, p.height-1, numEdges); -} - -std::vector Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) { - Puzzle copy = p; - // Prevent cuts from landing on the midline - if (p.symmetry == Puzzle::Symmetry::X) { - for (int y=0; y Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) { - std::vector edges; - for (int x=xMin; x y) continue; // Only allow cuts bottom-left of the diagonal - } - - // If the puzzle already has a sequence, don't cut along it. - bool inSequence = false; - for (Pos pos : p.sequence) inSequence |= (pos.x == x && pos.y == y); - if (inSequence) continue; - edges.emplace_back(x, y); - } - } - assert(numEdges <= edges.size()); - - auto [colorGrid, numColors] = CreateColorGrid(p); - assert(numEdges <= numColors); - - // @Hack... sort of. I couldn't think of a better way to do this. - if (p.symmetry == Puzzle::Symmetry::XY) { - // Recolor the diagonal so that opposite cells share a color. This is because we're only cutting along half their edges, - // so they are in fact two sides of the same cell. - for (int x=1; x cutEdges; - for (int i=0; i 0) { - int edge = Random::RandInt(0, static_cast(edges.size() - 1)); - Pos pos = edges[edge]; - edges.erase(edges.begin() + edge); - - int color1 = 0; - int color2 = 0; - if (pos.x%2 == 0 && pos.y%2 == 1) { // Vertical - if (pos.x > 0) color1 = colorGrid[pos.x-1][pos.y]; - else color1 = 1; - - if (pos.x < p.width - 1) color2 = colorGrid[pos.x+1][pos.y]; - else color2 = 1; - } else { // Horizontal - assert(pos.x%2 == 1 && pos.y%2 == 0); - if (pos.y > 0) color1 = colorGrid[pos.x][pos.y-1]; - else color1 = 1; - - if (pos.y < p.height - 1) color2 = colorGrid[pos.x][pos.y+1]; - else color2 = 1; - } - // Enforce color1 < color2 - if (color1 > color2) std::swap(color1, color2); - - // Colors mismatch, valid cut - if (color1 != color2) { - // @Performance... have a lookup table instead? - for (int x=0; x -#endif - -void Randomizer2Core::DebugColorGrid(const std::vector>& colorGrid) { -#ifndef NDEBUG - static std::string colors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - for (int y=0; y>& colorGrid, int color, int x, int y) { - if (!p.SafeCell(x, y)) return; - if (colorGrid[x][y] != 0) return; // Already processed. - colorGrid[x][y] = color; - - FloodFill(p, colorGrid, color, x, y+1); - FloodFill(p, colorGrid, color, x, y-1); - FloodFill(p, colorGrid, color, x+1, y); - FloodFill(p, colorGrid, color, x-1, y); -} - -void Randomizer2Core::FloodFillOutside(const Puzzle& p, std::vector>& colorGrid, int x, int y) { - if (!p.SafeCell(x, y)) return; - if (colorGrid[x][y] != 0) return; // Already processed. - if (x%2 != y%2 && p.grid[x][y].gap == Cell::Gap::NONE) return; // Only flood-fill through gaps - colorGrid[x][y] = 1; // Outside color - - FloodFillOutside(p, colorGrid, x, y+1); - FloodFillOutside(p, colorGrid, x, y-1); - FloodFillOutside(p, colorGrid, x+1, y); - FloodFillOutside(p, colorGrid, x-1, y); -} - -// Color key: -// 0 (default): Uncolored -// 1: Outside color and separator color -// 2+: Flood-filled region color -std::tuple>, int> Randomizer2Core::CreateColorGrid(const Puzzle& p) { - std::vector> colorGrid; - colorGrid.resize(p.width); - - for (int x=0; x