summary refs log tree commit diff stats
path: root/Source/Randomizer2Core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Randomizer2Core.cpp')
-rw-r--r--Source/Randomizer2Core.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index 2a2c6ff..867fa5a 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp
@@ -25,17 +25,17 @@ std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_
25 return CutEdgesInternal(copy, 0, p.width, 0, (p.height-1)/2, numEdges); 25 return CutEdgesInternal(copy, 0, p.width, 0, (p.height-1)/2, numEdges);
26 } else { 26 } else {
27 assert(p.symmetry == Puzzle::Symmetry::XY); 27 assert(p.symmetry == Puzzle::Symmetry::XY);
28 if (p.width%4 == 1) { 28 int midX = p.width/2;
29 assert(p.width == 9); 29 int midY = p.height/2;
30 copy.grid[2][3]; 30 if (p.width%4 == 1 && p.height%4 == 1) { // For double-even grids, cut around the center
31 copy.grid[3][4]; 31 copy.grid[midX-1][midY].gap = Cell::Gap::FULL;
32 copy.grid[3][6]; 32 copy.grid[midX][midY-1].gap = Cell::Gap::FULL;
33 copy.grid[4][3]; 33 copy.grid[midX][midY+1].gap = Cell::Gap::FULL;
34 // For odd grids, cut the center out. 34 copy.grid[midX+1][midY].gap = Cell::Gap::FULL;
35 // for (int x=0; x<p.width; x++) { 35 } else if (p.width%4 == 1 && p.height%4 == 3) { // For half-even grids, there's only one line to cut
36 // copy.grid[x][p.height/2].gap = Cell::Gap::FULL; 36 copy.grid[midX][midY].gap = Cell::Gap::FULL;
37 // } 37 } else if (p.width%4 == 3 && p.height%4 == 1) { // For half-even grids, there's only one line to cut
38 38 copy.grid[midX][midY].gap = Cell::Gap::FULL;
39 } 39 }
40 return CutEdgesInternal(copy, 0, p.width, 0, p.height, numEdges); 40 return CutEdgesInternal(copy, 0, p.width, 0, p.height, numEdges);
41 } 41 }
@@ -49,7 +49,11 @@ std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, in
49 if (p.grid[x][y].gap != Cell::Gap::NONE) continue; 49 if (p.grid[x][y].gap != Cell::Gap::NONE) continue;
50 if (p.grid[x][y].start) continue; 50 if (p.grid[x][y].start) continue;
51 if (p.grid[x][y].end != Cell::Dir::NONE) continue; 51 if (p.grid[x][y].end != Cell::Dir::NONE) continue;
52 if (p.symmetry == Puzzle::Symmetry::XY && x > y) continue; // Only allow cuts bottom-left of the diagonal 52
53 if (p.symmetry == Puzzle::Symmetry::XY) {
54 assert(p.width == p.height); // TODO: This solution only supports square rotational symmetry.
55 if (x > y) continue; // Only allow cuts bottom-left of the diagonal
56 }
53 57
54 // If the puzzle already has a sequence, don't cut along it. 58 // If the puzzle already has a sequence, don't cut along it.
55 bool inSequence = false; 59 bool inSequence = false;
@@ -63,6 +67,16 @@ std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, in
63 auto [colorGrid, numColors] = CreateColorGrid(p); 67 auto [colorGrid, numColors] = CreateColorGrid(p);
64 assert(numEdges <= numColors); 68 assert(numEdges <= numColors);
65 69
70 // @Hack... sort of. I couldn't think of a better way to do this.
71 if (p.symmetry == Puzzle::Symmetry::XY) {
72 // Recolor the diagonal so that opposite cells share a color. This is because we're only cutting along half their edges,
73 // so they are in fact two sides of the same cell.
74 for (int x=1; x<p.width/2; x+=2) {
75 assert(p.width == p.height); // TODO: This solution only supports square rotational symmetry.
76 colorGrid[x][x] = colorGrid[p.width-x-1][p.width-x-1];
77 }
78 }
79
66 std::vector<Pos> cutEdges; 80 std::vector<Pos> cutEdges;
67 for (int i=0; i<numEdges; i++) { 81 for (int i=0; i<numEdges; i++) {
68 while (edges.size() > 0) { 82 while (edges.size() > 0) {