about summary refs log tree commit diff stats
path: root/Source/Randomizer2Core.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-18 09:16:16 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-18 09:16:16 -0800
commitbff40e55c9c55fbc8439bb225d1937b2d805e629 (patch)
treee3aa7a2912c4208247139a9c2b806035af876a33 /Source/Randomizer2Core.cpp
parent695d0e12950b9df248ea7b84f8434e32acc84f11 (diff)
downloadwitness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.tar.gz
witness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.tar.bz2
witness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.zip
Cleanup & progress on tutorial
Diffstat (limited to 'Source/Randomizer2Core.cpp')
-rw-r--r--Source/Randomizer2Core.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index 2659076..8bd5765 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp
@@ -6,40 +6,46 @@
6#include <iostream> 6#include <iostream>
7#include <cassert> 7#include <cassert>
8 8
9std::vector<Pos> Randomizer2Core::CutEdgesToBeUnique(const Puzzle& p) { 9// @Cutnpaste
10 auto [colorGrid, numColors] = CreateColorGrid(p); 10std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) {
11 std::vector<Pos> edges; 11 std::vector<Pos> edges;
12 for (int x=0; x<p.width; x++) { 12 for (int x=0; x<p.width; x++) {
13 for (int y=0; y<p.height; y++) { 13 for (int y=0; y<p.height; y++) {
14 if (x%2 == y%2) continue; 14 if (x%2 == y%2) continue;
15 if (p.grid[x][y].gap != Cell::Gap::NONE) continue; 15 if (p.grid[x][y].gap != Cell::Gap::NONE) continue;
16
17 // If the puzzle already has a sequence, don't cut along it.
18 bool inSequence = false;
19 for (Pos pos : p.sequence) inSequence |= (pos.x == x && pos.y == y);
20 if (inSequence) continue;
16 edges.emplace_back(Pos{x, y}); 21 edges.emplace_back(Pos{x, y});
17 } 22 }
18 } 23 }
19 return CutEdgesInternal(p, colorGrid, edges, numColors); 24 return CutEdgesInternal(p, edges, numEdges);
20} 25}
21 26
22void Randomizer2Core::CutEdgesNotOutsideNotBreakingSequence(Puzzle& p, size_t numEdges) { 27std::vector<Pos> Randomizer2Core::CutEdges2(const Puzzle& p, size_t numEdges) {
23 auto [colorGrid, numColors] = CreateColorGrid(p);
24 assert(numEdges <= numColors);
25 std::vector<Pos> edges; 28 std::vector<Pos> edges;
29 // Note the iterator bounds; we skip the outer edges.
26 for (int x=1; x<p.width-1; x++) { 30 for (int x=1; x<p.width-1; x++) {
27 for (int y=1; y<p.height-1; y++) { 31 for (int y=1; y<p.height-1; y++) {
28 if (x%2 == y%2) continue; 32 if (x%2 == y%2) continue;
29 if (p.grid[x][y].gap != Cell::Gap::NONE) continue; 33 if (p.grid[x][y].gap != Cell::Gap::NONE) continue;
34
35 // If the puzzle already has a sequence, don't cut along it.
30 bool inSequence = false; 36 bool inSequence = false;
31 for (Pos pos : p.sequence) inSequence |= (pos.x == x && pos.y == y); 37 for (Pos pos : p.sequence) inSequence |= (pos.x == x && pos.y == y);
32 if (inSequence) continue; 38 if (inSequence) continue;
33 edges.emplace_back(Pos{x, y}); 39 edges.emplace_back(Pos{x, y});
34 } 40 }
35 } 41 }
36 std::vector<Pos> cutEdges = CutEdgesInternal(p, colorGrid, edges, numEdges); 42 return CutEdgesInternal(p, edges, numEdges);
37 for (Pos pos : cutEdges) {
38 p.grid[pos.x][pos.y].gap = Cell::Gap::FULL;
39 }
40} 43}
41 44
42std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, std::vector<std::vector<int>>& colorGrid, std::vector<Pos>& edges, size_t numEdges) { 45std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, std::vector<Pos>& edges, size_t numEdges) {
46 auto [colorGrid, numColors] = CreateColorGrid(p);
47 assert(numEdges <= numColors);
48
43 std::vector<Pos> cutEdges; 49 std::vector<Pos> cutEdges;
44 for (int i=0; i<numEdges; i++) { 50 for (int i=0; i<numEdges; i++) {
45 for (int j=0; j<edges.size(); j++) { 51 for (int j=0; j<edges.size(); j++) {
@@ -79,6 +85,7 @@ std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, std::vector<
79 } 85 }
80 } 86 }
81 } 87 }
88 assert(cutEdges.size() == numEdges);
82 return cutEdges; 89 return cutEdges;
83} 90}
84 91