summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Source/PuzzleSerializer.cpp61
-rw-r--r--Source/Randomizer2.cpp58
-rw-r--r--Source/pch.cpp12
-rw-r--r--Source/pch.h2
4 files changed, 100 insertions, 33 deletions
diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 8faede9..3732db8 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp
@@ -318,7 +318,18 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) {
318 for (int x=0; x<p.width; x++) { 318 for (int x=0; x<p.width; x++) {
319 for (int y=0; y<p.height; y++) { 319 for (int y=0; y<p.height; y++) {
320 if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. 320 if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled.
321 if (p.grid[x][y].dot == Cell::Dot::NONE) continue; 321
322 bool shouldWriteDot = false;
323 if (p.grid[x][y].dot != Cell::Dot::NONE) {
324 shouldWriteDot = true;
325 } else if (p.symmetry != Puzzle::Symmetry::NONE) {
326 Pos sym = p.GetSymmetricalPos(x, y);
327 // Write symmetrical dots, but don't actually set the flag for them. They're only there for symmetrical tracing.
328 if (p.grid[sym.x][sym.y].dot != Cell::Dot::NONE) {
329 shouldWriteDot = true;
330 }
331 }
332 if (!shouldWriteDot) continue;
322 333
323 // We need to introduce a new segment which contains this dot. Break the existing segment, and add one. 334 // We need to introduce a new segment which contains this dot. Break the existing segment, and add one.
324 int connectionLocation = -1; 335 int connectionLocation = -1;
@@ -339,19 +350,24 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) {
339 _connectionsA.push_back(other_connection); 350 _connectionsA.push_back(other_connection);
340 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); 351 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
341 352
342 int flags = Flags::HAS_DOT; 353 int flags = 0;
343 switch (p.grid[x][y].dot) { 354 if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].dot == Cell::Dot::NONE) {
344 case Cell::Dot::BLACK: 355 // A dot was asked to be introduced strictly for tracing reasons, don't set any flags.
345 break; 356 } else {
346 case Cell::Dot::BLUE: 357 flags |= Flags::HAS_DOT;
347 flags |= DOT_IS_BLUE; 358 switch (p.grid[x][y].dot) {
348 break; 359 case Cell::Dot::BLACK:
349 case Cell::Dot::YELLOW: 360 break;
350 flags |= DOT_IS_ORANGE; 361 case Cell::Dot::BLUE:
351 break; 362 flags |= DOT_IS_BLUE;
352 case Cell::Dot::INVISIBLE: 363 break;
353 flags |= DOT_IS_INVISIBLE; 364 case Cell::Dot::YELLOW:
354 break; 365 flags |= DOT_IS_ORANGE;
366 break;
367 case Cell::Dot::INVISIBLE:
368 flags |= DOT_IS_INVISIBLE;
369 break;
370 }
355 } 371 }
356 372
357 auto [xPos, yPos] = xy_to_pos(p, x, y); 373 auto [xPos, yPos] = xy_to_pos(p, x, y);
@@ -414,13 +430,11 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) {
414 _connectionsB.push_back(gap2Location); 430 _connectionsB.push_back(gap2Location);
415 AddIntersection(p, x, y, xPos + INTERVAL / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); 431 AddIntersection(p, x, y, xPos + INTERVAL / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN);
416 } 432 }
417 if (p.symmetry != Puzzle::Symmetry::NONE) { 433 if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].gap == Cell::Gap::NONE) {
418 if (p.grid[x][y].gap == Cell::Gap::NONE) { 434 // A gap was asked to be introduced strictly for tracing reasons, but it shouldn't look like a gap.
419 // A gap was asked to be introduced strictly for interaction reasons, but it shouldn't look like a gap. 435 // Add a connection between two halves of the gap to cover it graphically.
420 // Add a connection between two halves of the gap to cover it graphically. 436 _connectionsA.push_back(gap1Location);
421 _connectionsA.push_back(gap1Location); 437 _connectionsB.push_back(gap2Location);
422 _connectionsB.push_back(gap2Location);
423 }
424 } 438 }
425 } 439 }
426 } 440 }
@@ -546,7 +560,10 @@ int PuzzleSerializer::xy_to_loc(const Puzzle& p, int x, int y) const {
546 560
547int PuzzleSerializer::extra_xy_to_loc(const Puzzle& p, int x, int y) const { 561int PuzzleSerializer::extra_xy_to_loc(const Puzzle& p, int x, int y) const {
548 auto search = _extraLocations.find(x * p.height + y); 562 auto search = _extraLocations.find(x * p.height + y);
549 if (search == _extraLocations.end()) return -1; // @Error 563 if (search == _extraLocations.end()) {
564 assert(false);
565 return -1; // @Error
566 }
550 return search->second; 567 return search->second;
551} 568}
552 569
diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index 0628414..421ce69 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp
@@ -412,27 +412,65 @@ void Randomizer2::RandomizeSymmetryIsland() {
412 else edges.emplace_back(Pos{x, y}); 412 else edges.emplace_back(Pos{x, y});
413 } 413 }
414 } 414 }
415 edges.insert(edges.end(), corners.begin(), corners.end());
415 416
417 std::vector<Pos> dots;
416 for (int j=0;; j++) { 418 for (int j=0;; j++) {
417 std::vector<Pos> dots = Random::SelectFromSet(edges, 1); 419 dots = Random::SelectFromSet(edges, 3);
418 std::vector<Pos> dots2 = Random::SelectFromSet(corners, 2);
419 dots.insert(dots.end(), dots2.begin(), dots2.end());
420 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK; 420 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK;
421 421
422 auto solutions = Solver::Solve(p); 422 auto solutions = Solver::Solve(p);
423 if (solutions.size() == 2) { 423 if (solutions.size() == 2) break;
424 for (Pos pos : dots) {
425 Pos sym = p.GetSymmetricalPos(pos.x, pos.y);
426 p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK;
427 }
428 break;
429 }
430 424
431 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::NONE; 425 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::NONE;
432 } 426 }
433 427
428 for (Pos pos : dots) {
429 Pos sym = p.GetSymmetricalPos(pos.x, pos.y);
430 p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK;
431 }
432
434 _serializer.WritePuzzle(p, 0x22); 433 _serializer.WritePuzzle(p, 0x22);
435 } 434 }
435 { // Dots 2
436 Puzzle p;
437 p.NewGrid(3, 3);
438 p.symmetry = Puzzle::Symmetry::Y;
439 p.grid[0][2].start = true;
440 p.grid[0][4].start = true;
441 p.grid[6][2].end = Cell::Dir::RIGHT;
442 p.grid[6][4].end = Cell::Dir::RIGHT;
443
444 std::vector<Pos> corners;
445 std::vector<Pos> cells;
446 std::vector<Pos> edges;
447 for (int x=0; x<p.width; x++) {
448 for (int y=0; y<p.height/2; y++) {
449 if (x%2 == 0 && y%2 == 0) corners.emplace_back(Pos{x, y});
450 else if (x%2 == 1 && y%2 == 1) cells.emplace_back(Pos{x, y});
451 else edges.emplace_back(Pos{x, y});
452 }
453 }
454 edges.insert(edges.end(), corners.begin(), corners.end());
455
456 std::vector<Pos> dots;
457 for (int j=0;; j++) {
458 dots = Random::SelectFromSet(edges, 3);
459 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK;
460
461 auto solutions = Solver::Solve(p);
462 if (solutions.size() == 2) break;
463
464 for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::NONE;
465 }
466
467 Pos pos = dots[1];
468 Pos sym = p.GetSymmetricalPos(pos.x, pos.y);
469 p.grid[pos.x][pos.y].dot = Cell::Dot::NONE;
470 p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK;
471
472 _serializer.WritePuzzle(p, 0x23);
473 }
436} 474}
437 475
438void Randomizer2::RandomizeKeep() { 476void Randomizer2::RandomizeKeep() {
diff --git a/Source/pch.cpp b/Source/pch.cpp index 1730571..45113cd 100644 --- a/Source/pch.cpp +++ b/Source/pch.cpp
@@ -1 +1,11 @@
1#include "pch.h" \ No newline at end of file 1#include "pch.h"
2
3void DebugPrint(std::string text) {
4#ifdef _DEBUG
5 if (text[text.size()-1] != '\n') {
6 text += '\n';
7 }
8 OutputDebugStringA(text.c_str());
9 std::cout << text;
10#endif
11}
diff --git a/Source/pch.h b/Source/pch.h index 9e39f33..a94cd3d 100644 --- a/Source/pch.h +++ b/Source/pch.h
@@ -25,3 +25,5 @@
25#include "MemoryException.h" 25#include "MemoryException.h"
26#include "Memory.h" 26#include "Memory.h"
27#include "Puzzle.h" 27#include "Puzzle.h"
28
29void DebugPrint(std::string text); \ No newline at end of file