diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-19 09:42:45 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-19 09:42:45 -0800 |
commit | 52b01775c2c94f08786696cae7836ca56f683739 (patch) | |
tree | d6d7d7604c8f5d793be28bcf21753b02d7d31bb7 /Source/Randomizer2.cpp | |
parent | 7a13ef0a94f6ed4989677530b1b37e1af0692fc7 (diff) | |
download | witness-tutorializer-52b01775c2c94f08786696cae7836ca56f683739.tar.gz witness-tutorializer-52b01775c2c94f08786696cae7836ca56f683739.tar.bz2 witness-tutorializer-52b01775c2c94f08786696cae7836ca56f683739.zip |
Fix RNG -- this will break seeds, though.
Diffstat (limited to 'Source/Randomizer2.cpp')
-rw-r--r-- | Source/Randomizer2.cpp | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index 83427d7..adf8eb6 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp | |||
@@ -84,6 +84,77 @@ void Randomizer2::RandomizeTutorial() { | |||
84 | } | 84 | } |
85 | _serializer.WritePuzzle(p, 0xA3B5); | 85 | _serializer.WritePuzzle(p, 0xA3B5); |
86 | } | 86 | } |
87 | |||
88 | { // Back right | ||
89 | Puzzle p; | ||
90 | p.NewGrid(6, 6); | ||
91 | |||
92 | p.grid[0][12].start = true; | ||
93 | p.grid[12][12].start = true; | ||
94 | p.grid[6][0].end = Cell::Dir::UP; | ||
95 | |||
96 | std::vector<Pos> cuts; | ||
97 | bool toTheRight; | ||
98 | // Start by generating a cut line, to ensure one of the two startpoints is inaccessible | ||
99 | int x, y; | ||
100 | switch (Random::RandInt(1, 4)) | ||
101 | { | ||
102 | case 1: | ||
103 | x = 1; | ||
104 | y = 1; | ||
105 | toTheRight = true; | ||
106 | cuts.emplace_back(Pos{0, 1}); | ||
107 | break; | ||
108 | case 2: | ||
109 | x = 1; | ||
110 | y = 1; | ||
111 | toTheRight = true; | ||
112 | cuts.emplace_back(Pos{1, 0}); | ||
113 | break; | ||
114 | case 3: | ||
115 | x = 11; | ||
116 | y = 1; | ||
117 | toTheRight = false; | ||
118 | cuts.emplace_back(Pos{12, 1}); | ||
119 | break; | ||
120 | case 4: | ||
121 | x = 11; | ||
122 | y = 1; | ||
123 | toTheRight = false; | ||
124 | cuts.emplace_back(Pos{11, 0}); | ||
125 | break; | ||
126 | } | ||
127 | while (y < p.height) { // The final cut will push y below the bottom of the puzzle, which means we're done. | ||
128 | switch (Random::RandInt(1, 4)) { | ||
129 | case 1: // Go right | ||
130 | if (x < p.width-2) { | ||
131 | cuts.emplace_back(Pos{x+1, y}); | ||
132 | x += 2; | ||
133 | } | ||
134 | break; | ||
135 | case 2: // Go left | ||
136 | if (x > 1) { | ||
137 | cuts.emplace_back(Pos{x-1, y}); | ||
138 | x -= 2; | ||
139 | } | ||
140 | break; | ||
141 | case 3: | ||
142 | case 4: // Go down (biased) | ||
143 | cuts.emplace_back(Pos{x, y+1}); | ||
144 | y += 2; | ||
145 | break; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | for (Pos pos : cuts) { | ||
150 | p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; | ||
151 | } | ||
152 | |||
153 | for (Pos pos : Randomizer2Core::CutEdges(p, 30 - cuts.size(), true)) { | ||
154 | p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; | ||
155 | } | ||
156 | _serializer.WritePuzzle(p, 0xA3B2); | ||
157 | } | ||
87 | } | 158 | } |
88 | 159 | ||
89 | void Randomizer2::RandomizeKeep() { | 160 | void Randomizer2::RandomizeKeep() { |
@@ -109,7 +180,7 @@ void Randomizer2::RandomizeKeep() { | |||
109 | std::vector<Pos> cutEdges = Randomizer2Core::CutEdges(p, 5, false); | 180 | std::vector<Pos> cutEdges = Randomizer2Core::CutEdges(p, 5, false); |
110 | Puzzle copy = p; | 181 | Puzzle copy = p; |
111 | std::vector<int> gates = {0x00344, 0x00488, 0x00489, 0x00495, 0x00496}; | 182 | std::vector<int> gates = {0x00344, 0x00488, 0x00489, 0x00495, 0x00496}; |
112 | for (int i=0; i<gates.size(); i++) { | 183 | for (int i=0; i<cutEdges.size(); i++) { |
113 | Pos pos = cutEdges[i]; | 184 | Pos pos = cutEdges[i]; |
114 | copy.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; | 185 | copy.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; |
115 | SetGate(gates[i], pos.x, pos.y); | 186 | SetGate(gates[i], pos.x, pos.y); |
@@ -174,12 +245,13 @@ void Randomizer2::RandomizeKeep() { | |||
174 | p.grid[0][8].start = true; | 245 | p.grid[0][8].start = true; |
175 | p.grid[8][2].end = Cell::Dir::RIGHT; | 246 | p.grid[8][2].end = Cell::Dir::RIGHT; |
176 | 247 | ||
177 | std::vector<int> pebbleMarkers = {0x034a9, 0x034b1, 0x034be, 0x034c4}; | ||
178 | |||
179 | std::vector<Pos> cutEdges = Randomizer2Core::CutEdges(p, 7, false); | 248 | std::vector<Pos> cutEdges = Randomizer2Core::CutEdges(p, 7, false); |
180 | for (Pos pos : cutEdges) { | 249 | for (Pos pos : cutEdges) { |
181 | p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; | 250 | p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; |
182 | } | 251 | } |
252 | |||
253 | std::vector<int> pebbleMarkers = {0x034a9, 0x034b1, 0x034be, 0x034c4}; | ||
254 | |||
183 | // _serializer.WritePuzzle(p, 0x19E7); | 255 | // _serializer.WritePuzzle(p, 0x19E7); |
184 | } | 256 | } |
185 | 257 | ||