diff options
Diffstat (limited to 'Source/Randomizer2.cpp')
| -rw-r--r-- | Source/Randomizer2.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
| diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index db90f4c..e1b1712 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp | |||
| @@ -6,11 +6,13 @@ | |||
| 6 | #include "Solver.h" | 6 | #include "Solver.h" |
| 7 | #include "Windows.h" | 7 | #include "Windows.h" |
| 8 | 8 | ||
| 9 | Randomizer2::Randomizer2(const PuzzleSerializer& serializer) : _serializer(serializer) {} | 9 | Randomizer2::Randomizer2(const PuzzleSerializer& serializer) : _serializer(serializer) { |
| 10 | } | ||
| 10 | 11 | ||
| 11 | void Randomizer2::Randomize() { | 12 | void Randomizer2::Randomize() { |
| 12 | RandomizeTutorial(); | 13 | // RandomizeTutorial(); |
| 13 | RandomizeSymmetry(); | 14 | // RandomizeGlassFactory(); |
| 15 | RandomizeSymmetryIsland(); | ||
| 14 | // RandomizeKeep(); | 16 | // RandomizeKeep(); |
| 15 | } | 17 | } |
| 16 | 18 | ||
| @@ -144,7 +146,7 @@ void Randomizer2::RandomizeTutorial() { | |||
| 144 | } | 146 | } |
| 145 | } | 147 | } |
| 146 | 148 | ||
| 147 | void Randomizer2::RandomizeSymmetry() { | 149 | void Randomizer2::RandomizeGlassFactory() { |
| 148 | { // Back wall 1 | 150 | { // Back wall 1 |
| 149 | Puzzle p; | 151 | Puzzle p; |
| 150 | p.NewGrid(3, 3); | 152 | p.NewGrid(3, 3); |
| @@ -359,6 +361,55 @@ void Randomizer2::RandomizeSymmetry() { | |||
| 359 | } | 361 | } |
| 360 | } | 362 | } |
| 361 | 363 | ||
| 364 | void Randomizer2::RandomizeSymmetryIsland() { | ||
| 365 | { // Entry door | ||
| 366 | Puzzle p; | ||
| 367 | p.NewGrid(4, 3); | ||
| 368 | p.grid[0][6].start = true; | ||
| 369 | p.grid[8][0].end = Cell::Dir::RIGHT; | ||
| 370 | p.grid[4][3].gap = Cell::Gap::FULL; | ||
| 371 | |||
| 372 | std::vector<Pos> corners; | ||
| 373 | std::vector<Pos> cells; | ||
| 374 | std::vector<Pos> edges; | ||
| 375 | for (int x=0; x<p.width; x++) { | ||
| 376 | for (int y=0; y<p.height; y++) { | ||
| 377 | if (x%2 == 0 && y%2 == 0) corners.emplace_back(Pos{x, y}); | ||
| 378 | else if (x%2 == 1 && y%2 == 1) cells.emplace_back(Pos{x, y}); | ||
| 379 | else edges.emplace_back(Pos{x, y}); | ||
| 380 | } | ||
| 381 | } | ||
| 382 | |||
| 383 | for (int j=0;; j++) { | ||
| 384 | auto edgesCopy = edges; | ||
| 385 | |||
| 386 | std::vector<Pos> dots; | ||
| 387 | for (int i=0; i<4; i++) { | ||
| 388 | int edge = Random::RandInt(0, static_cast<int>(edgesCopy.size() - 1)); | ||
| 389 | dots.emplace_back(edgesCopy[edge]); | ||
| 390 | edgesCopy.erase(edgesCopy.begin() + edge); | ||
| 391 | } | ||
| 392 | |||
| 393 | for (Pos pos : dots) { | ||
| 394 | p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK; | ||
| 395 | } | ||
| 396 | |||
| 397 | auto solutions = Solver::Solve(p); | ||
| 398 | if (solutions.size() > 0 && solutions.size() < 10) { | ||
| 399 | std::string text = std::to_string(solutions.size()) + "\n"; | ||
| 400 | OutputDebugStringA(text.c_str()); | ||
| 401 | break; | ||
| 402 | } | ||
| 403 | |||
| 404 | for (Pos pos : dots) { | ||
| 405 | p.grid[pos.x][pos.y].dot = Cell::Dot::NONE; | ||
| 406 | } | ||
| 407 | } | ||
| 408 | |||
| 409 | _serializer.WritePuzzle(p, 0xB0); | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 362 | void Randomizer2::RandomizeKeep() { | 413 | void Randomizer2::RandomizeKeep() { |
| 363 | { // Hedges 1 | 414 | { // Hedges 1 |
| 364 | Puzzle p; | 415 | Puzzle p; |
