about summary refs log tree commit diff stats
path: root/Source/Randomizer2Core.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-21 10:03:34 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-21 10:03:34 -0800
commit859cfdb86d57bb230f1200c3a4c76c55ca920199 (patch)
treec401dd52d097f438517bc8c26cdae0ec90dfd68f /Source/Randomizer2Core.cpp
parent4816728c4a5bcf8fd9992f32464a1707f94c3b13 (diff)
downloadwitness-tutorializer-859cfdb86d57bb230f1200c3a4c76c55ca920199.tar.gz
witness-tutorializer-859cfdb86d57bb230f1200c3a4c76c55ca920199.tar.bz2
witness-tutorializer-859cfdb86d57bb230f1200c3a4c76c55ca920199.zip
Well, got started on randomization anyways
Diffstat (limited to 'Source/Randomizer2Core.cpp')
-rw-r--r--Source/Randomizer2Core.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index f8d1312..dcb9fd2 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp
@@ -6,13 +6,25 @@
6#include <iostream> 6#include <iostream>
7#include <cassert> 7#include <cassert>
8 8
9std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges, bool allowEdges) { 9std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) {
10 std::vector<Pos> edges; 10 return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges);
11 int xMin = allowEdges ? 0 : 1; 11}
12 int xMax = allowEdges ? p.width : p.width-1;
13 int yMin = allowEdges ? 0 : 1;
14 int yMax = allowEdges ? p.height : p.height-1;
15 12
13std::vector<Pos> Randomizer2Core::CutInsideEdges(const Puzzle& p, size_t numEdges) {
14 return CutEdgesInternal(p, 1, p.width-1, 1, p.height-1, numEdges);
15}
16
17std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) {
18 assert(p.symmetry != Puzzle::Symmetry::NONE);
19 if (p.symmetry == Puzzle::Symmetry::X) {
20 return CutEdgesInternal(p, 0, (p.width-1)/2, 0, p.height, numEdges);
21 }
22 assert(false);
23 return {};
24}
25
26std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) {
27 std::vector<Pos> edges;
16 for (int x=xMin; x<xMax; x++) { 28 for (int x=xMin; x<xMax; x++) {
17 for (int y=yMin; y<yMax; y++) { 29 for (int y=yMin; y<yMax; y++) {
18 if (x%2 == y%2) continue; 30 if (x%2 == y%2) continue;
@@ -27,10 +39,8 @@ std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges, boo
27 edges.emplace_back(x, y); 39 edges.emplace_back(x, y);
28 } 40 }
29 } 41 }
30 return CutEdgesInternal(p, edges, numEdges); 42 assert(numEdges <= edges.size());
31}
32 43
33std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, std::vector<Pos>& edges, size_t numEdges) {
34 auto [colorGrid, numColors] = CreateColorGrid(p); 44 auto [colorGrid, numColors] = CreateColorGrid(p);
35 assert(numEdges <= numColors); 45 assert(numEdges <= numColors);
36 46