From 38060c54f9f923d49b019fcf90f3494fd5469b74 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Thu, 5 Dec 2019 10:23:42 -0800 Subject: Bugfix, add debug function, add dots 2 --- Source/PuzzleSerializer.cpp | 61 +++++++++++++++++++++++++++++---------------- Source/Randomizer2.cpp | 58 ++++++++++++++++++++++++++++++++++-------- Source/pch.cpp | 12 ++++++++- Source/pch.h | 2 ++ 4 files changed, 100 insertions(+), 33 deletions(-) (limited to 'Source') 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) { for (int x=0; x(_intersectionFlags.size())); - int flags = Flags::HAS_DOT; - switch (p.grid[x][y].dot) { - case Cell::Dot::BLACK: - break; - case Cell::Dot::BLUE: - flags |= DOT_IS_BLUE; - break; - case Cell::Dot::YELLOW: - flags |= DOT_IS_ORANGE; - break; - case Cell::Dot::INVISIBLE: - flags |= DOT_IS_INVISIBLE; - break; + int flags = 0; + if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].dot == Cell::Dot::NONE) { + // A dot was asked to be introduced strictly for tracing reasons, don't set any flags. + } else { + flags |= Flags::HAS_DOT; + switch (p.grid[x][y].dot) { + case Cell::Dot::BLACK: + break; + case Cell::Dot::BLUE: + flags |= DOT_IS_BLUE; + break; + case Cell::Dot::YELLOW: + flags |= DOT_IS_ORANGE; + break; + case Cell::Dot::INVISIBLE: + flags |= DOT_IS_INVISIBLE; + break; + } } auto [xPos, yPos] = xy_to_pos(p, x, y); @@ -414,13 +430,11 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) { _connectionsB.push_back(gap2Location); AddIntersection(p, x, y, xPos + INTERVAL / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); } - if (p.symmetry != Puzzle::Symmetry::NONE) { - if (p.grid[x][y].gap == Cell::Gap::NONE) { - // A gap was asked to be introduced strictly for interaction reasons, but it shouldn't look like a gap. - // Add a connection between two halves of the gap to cover it graphically. - _connectionsA.push_back(gap1Location); - _connectionsB.push_back(gap2Location); - } + if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].gap == Cell::Gap::NONE) { + // A gap was asked to be introduced strictly for tracing reasons, but it shouldn't look like a gap. + // Add a connection between two halves of the gap to cover it graphically. + _connectionsA.push_back(gap1Location); + _connectionsB.push_back(gap2Location); } } } @@ -546,7 +560,10 @@ int PuzzleSerializer::xy_to_loc(const Puzzle& p, int x, int y) const { int PuzzleSerializer::extra_xy_to_loc(const Puzzle& p, int x, int y) const { auto search = _extraLocations.find(x * p.height + y); - if (search == _extraLocations.end()) return -1; // @Error + if (search == _extraLocations.end()) { + assert(false); + return -1; // @Error + } return search->second; } 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() { else edges.emplace_back(Pos{x, y}); } } + edges.insert(edges.end(), corners.begin(), corners.end()); + std::vector dots; for (int j=0;; j++) { - std::vector dots = Random::SelectFromSet(edges, 1); - std::vector dots2 = Random::SelectFromSet(corners, 2); - dots.insert(dots.end(), dots2.begin(), dots2.end()); + dots = Random::SelectFromSet(edges, 3); for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK; auto solutions = Solver::Solve(p); - if (solutions.size() == 2) { - for (Pos pos : dots) { - Pos sym = p.GetSymmetricalPos(pos.x, pos.y); - p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK; - } - break; - } + if (solutions.size() == 2) break; for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::NONE; } + for (Pos pos : dots) { + Pos sym = p.GetSymmetricalPos(pos.x, pos.y); + p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK; + } + _serializer.WritePuzzle(p, 0x22); } + { // Dots 2 + Puzzle p; + p.NewGrid(3, 3); + p.symmetry = Puzzle::Symmetry::Y; + p.grid[0][2].start = true; + p.grid[0][4].start = true; + p.grid[6][2].end = Cell::Dir::RIGHT; + p.grid[6][4].end = Cell::Dir::RIGHT; + + std::vector corners; + std::vector cells; + std::vector edges; + for (int x=0; x dots; + for (int j=0;; j++) { + dots = Random::SelectFromSet(edges, 3); + for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::BLACK; + + auto solutions = Solver::Solve(p); + if (solutions.size() == 2) break; + + for (Pos pos : dots) p.grid[pos.x][pos.y].dot = Cell::Dot::NONE; + } + + Pos pos = dots[1]; + Pos sym = p.GetSymmetricalPos(pos.x, pos.y); + p.grid[pos.x][pos.y].dot = Cell::Dot::NONE; + p.grid[sym.x][sym.y].dot = Cell::Dot::BLACK; + + _serializer.WritePuzzle(p, 0x23); + } } void 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 @@ -#include "pch.h" \ No newline at end of file +#include "pch.h" + +void DebugPrint(std::string text) { +#ifdef _DEBUG + if (text[text.size()-1] != '\n') { + text += '\n'; + } + OutputDebugStringA(text.c_str()); + std::cout << text; +#endif +} 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 @@ #include "MemoryException.h" #include "Memory.h" #include "Puzzle.h" + +void DebugPrint(std::string text); \ No newline at end of file -- cgit 1.4.1