#include "Randomizer2.h" #include "Puzzle.h" #include "Random.h" #include "Solver.h" Randomizer2::Randomizer2(const std::shared_ptr& memory) : _memory(memory) {} void Randomizer2::Randomize() { // 4x4 // 14 gaps // start (x=0, y=8) // end (x=8, y=0) Up // 1 solution Puzzle p; int attemptCount = 0; while (true) { attemptCount++; p.NewGrid(4, 4); std::vector corners; std::vector cells; std::vector edges; for (int x=0; x(edges.size() - 1)); Pos pos = edges[edge]; p.grid[pos.x][pos.y].gap = Cell::Gap::FULL; edges.erase(edges.begin() + edge); } p.grid[0][8].start = true; p.grid[8][0].end = Cell::Dir::UP; auto solutions = Solver::Solve(p); if (solutions.size() == 1) { auto solution = solutions[0]; int solutionLength = 0; for (int x=0; x corners; std::vector cells; std::vector edges; for (int x=0; x(edges.size() - 1)); Pos pos = edges[edge]; p.grid[pos.x][pos.y].gap = Cell::Gap::FULL; edges.erase(edges.begin() + edge); } p.grid[8][8].start = true; p.grid[4][0].end = Cell::Dir::UP; auto solutions = Solver::Solve(p); if (solutions.size() > 0) break; if (solutions.size() > 0 && solutions.size() < 5) { auto solution = solutions[0]; int solutionLength = 0; for (int x=0; x 30 && solutionLength < 40) break; } } PuzzleSerializer(_memory).WritePuzzle(p, 0x295); }