diff options
Diffstat (limited to 'Source/Randomizer2Core.cpp')
-rw-r--r-- | Source/Randomizer2Core.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index f8d1312..dcb9fd2 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp | |||
@@ -6,13 +6,25 @@ | |||
6 | #include <iostream> | 6 | #include <iostream> |
7 | #include <cassert> | 7 | #include <cassert> |
8 | 8 | ||
9 | std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges, bool allowEdges) { | 9 | std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) { |
10 | std::vector<Pos> edges; | 10 | return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges); |
11 | int xMin = allowEdges ? 0 : 1; | 11 | } |
12 | int xMax = allowEdges ? p.width : p.width-1; | ||
13 | int yMin = allowEdges ? 0 : 1; | ||
14 | int yMax = allowEdges ? p.height : p.height-1; | ||
15 | 12 | ||
13 | std::vector<Pos> Randomizer2Core::CutInsideEdges(const Puzzle& p, size_t numEdges) { | ||
14 | return CutEdgesInternal(p, 1, p.width-1, 1, p.height-1, numEdges); | ||
15 | } | ||
16 | |||
17 | std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) { | ||
18 | assert(p.symmetry != Puzzle::Symmetry::NONE); | ||
19 | if (p.symmetry == Puzzle::Symmetry::X) { | ||
20 | return CutEdgesInternal(p, 0, (p.width-1)/2, 0, p.height, numEdges); | ||
21 | } | ||
22 | assert(false); | ||
23 | return {}; | ||
24 | } | ||
25 | |||
26 | std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) { | ||
27 | std::vector<Pos> edges; | ||
16 | for (int x=xMin; x<xMax; x++) { | 28 | for (int x=xMin; x<xMax; x++) { |
17 | for (int y=yMin; y<yMax; y++) { | 29 | for (int y=yMin; y<yMax; y++) { |
18 | if (x%2 == y%2) continue; | 30 | if (x%2 == y%2) continue; |
@@ -27,10 +39,8 @@ std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges, boo | |||
27 | edges.emplace_back(x, y); | 39 | edges.emplace_back(x, y); |
28 | } | 40 | } |
29 | } | 41 | } |
30 | return CutEdgesInternal(p, edges, numEdges); | 42 | assert(numEdges <= edges.size()); |
31 | } | ||
32 | 43 | ||
33 | std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, std::vector<Pos>& edges, size_t numEdges) { | ||
34 | auto [colorGrid, numColors] = CreateColorGrid(p); | 44 | auto [colorGrid, numColors] = CreateColorGrid(p); |
35 | assert(numEdges <= numColors); | 45 | assert(numEdges <= numColors); |
36 | 46 | ||