summary refs log tree commit diff stats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/PuzzleSerializer.cpp3
-rw-r--r--Source/Randomizer2.cpp47
-rw-r--r--Source/Randomizer2Core.cpp14
3 files changed, 53 insertions, 11 deletions
diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index da7a336..8165fe8 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp
@@ -157,17 +157,20 @@ void PuzzleSerializer::ReadExtras(Puzzle& p) {
157 // Note that Y coordinates are reversed: 0.0 (bottom) 1.0 (top) 157 // Note that Y coordinates are reversed: 0.0 (bottom) 1.0 (top)
158 else if (y1 < y2) p.grid[x][y].end = Cell::Dir::DOWN; 158 else if (y1 < y2) p.grid[x][y].end = Cell::Dir::DOWN;
159 else if (y1 > y2) p.grid[x][y].end = Cell::Dir::UP; 159 else if (y1 > y2) p.grid[x][y].end = Cell::Dir::UP;
160 else assert(false);
160 } else if (_intersectionFlags[i] & Flags::HAS_DOT) { 161 } else if (_intersectionFlags[i] & Flags::HAS_DOT) {
161 if (x1 < x2) x--; 162 if (x1 < x2) x--;
162 else if (x1 > x2) x++; 163 else if (x1 > x2) x++;
163 else if (y1 < y2) y++; 164 else if (y1 < y2) y++;
164 else if (y1 > y2) y--; 165 else if (y1 > y2) y--;
166 else assert(false);
165 p.grid[x][y].dot = FlagsToDot(_intersectionFlags[i]); 167 p.grid[x][y].dot = FlagsToDot(_intersectionFlags[i]);
166 } else if (_intersectionFlags[i] & Flags::HAS_ONE_CONN) { 168 } else if (_intersectionFlags[i] & Flags::HAS_ONE_CONN) {
167 if (x1 < x2) x--; 169 if (x1 < x2) x--;
168 else if (x1 > x2) x++; 170 else if (x1 > x2) x++;
169 else if (y1 < y2) y++; 171 else if (y1 < y2) y++;
170 else if (y1 > y2) y--; 172 else if (y1 > y2) y--;
173 else assert(false);
171 p.grid[x][y].gap = Cell::Gap::BREAK; 174 p.grid[x][y].gap = Cell::Gap::BREAK;
172 gapLocations[i] = Pos{x, y}; 175 gapLocations[i] = Pos{x, y};
173 } 176 }
diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index 107950d..d2046bb 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp
@@ -208,6 +208,53 @@ void Randomizer2::RandomizeSymmetry() {
208 208
209 _serializer.WritePuzzle(p, 0x59); 209 _serializer.WritePuzzle(p, 0x59);
210 } 210 }
211 { // Back wall 4
212 Puzzle p;
213 p.NewGrid(5, 8);
214 p.symmetry = Puzzle::Symmetry::X;
215 p.grid[2][16].start = true;
216 p.grid[8][16].start = true;
217 p.grid[4][0].end = Cell::Dir::UP;
218 p.grid[6][0].end = Cell::Dir::UP;
219 std::vector<Pos> cutEdges = Randomizer2Core::CutSymmetricalEdgePairs(p, 15);
220 for (int i=0; i<cutEdges.size(); i++) {
221 Pos pos = cutEdges[i];
222 if (i%2 == 0) {
223 p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK;
224 } else {
225 Pos sym = p.GetSymmetricalPos(pos.x, pos.y);
226 p.grid[sym.x][sym.y].gap = Cell::Gap::BREAK;
227 }
228 }
229
230 _serializer.WritePuzzle(p, 0x62);
231 }
232 { // Back wall 5
233 Puzzle p;
234 p.NewGrid(11, 8);
235 p.symmetry = Puzzle::Symmetry::X;
236 p.grid[0][16].start = true;
237 p.grid[10][16].start = true;
238 p.grid[12][16].start = true;
239 p.grid[22][16].start = true;
240 p.grid[2][0].end = Cell::Dir::UP;
241 p.grid[8][0].end = Cell::Dir::UP;
242 p.grid[14][0].end = Cell::Dir::UP;
243 p.grid[20][0].end = Cell::Dir::UP;
244
245 Puzzle q;
246 q.NewGrid(5, 8);
247 q.symmetry = Puzzle::Symmetry::X;
248
249 for (Pos pos : Randomizer2Core::CutSymmetricalEdgePairs(q, 16)) {
250 p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK;
251 }
252 for (Pos pos : Randomizer2Core::CutSymmetricalEdgePairs(q, 16)) {
253 p.grid[pos.x + 12][pos.y].gap = Cell::Gap::BREAK;
254 }
255
256 _serializer.WritePuzzle(p, 0x5C);
257 }
211} 258}
212 259
213void Randomizer2::RandomizeKeep() { 260void Randomizer2::RandomizeKeep() {
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index ceb726b..eaefa9a 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp
@@ -18,17 +18,9 @@ std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_
18 Puzzle copy = p; 18 Puzzle copy = p;
19 assert(p.symmetry != Puzzle::Symmetry::NONE); 19 assert(p.symmetry != Puzzle::Symmetry::NONE);
20 if (p.symmetry == Puzzle::Symmetry::X) { 20 if (p.symmetry == Puzzle::Symmetry::X) {
21 if (p.width%4 == 1) { 21 // Prevent cuts from landing on the midline
22 // The puzle has an even width (e.g. 4x4), so it has a midline for symmetry. 22 for (int y=0; y<p.height; y++) {
23 // Since this midline is unusable, we cut it pre-emptively. 23 copy.grid[p.width/2][y].gap = Cell::Gap::FULL;
24 for (int y=0; y<p.height; y++) {
25 copy.grid[p.width/2][y].gap = Cell::Gap::FULL;
26 }
27 } else {
28 // The puzzle has an odd width (e.g. 3x3), but we still need to cut the midline.
29 for (int y=0; y<p.height; y++) {
30 copy.grid[p.width/2][y].gap = Cell::Gap::FULL;
31 }
32 } 24 }
33 25
34 return CutEdgesInternal(copy, 0, (p.width-1)/2, 0, p.height, numEdges); 26 return CutEdgesInternal(copy, 0, (p.width-1)/2, 0, p.height, numEdges);