From 98db209c9008492baec6bb482b047d386fbdd42b Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sat, 9 Nov 2019 14:23:42 -0800 Subject: One down, 522 to go. --- Source/Randomizer2.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Source/Randomizer2.cpp (limited to 'Source/Randomizer2.cpp') diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp new file mode 100644 index 0000000..fcfec9a --- /dev/null +++ b/Source/Randomizer2.cpp @@ -0,0 +1,104 @@ +#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); + +} -- cgit 1.4.1