diff options
| author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 09:41:22 -0800 |
|---|---|---|
| committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 09:41:22 -0800 |
| commit | c282663a96ae9704a59c55c9300dbc8c49e0ef39 (patch) | |
| tree | 071a26b8e58b8aac4d347c6a8200a4b01663abe1 /Source/Randomizer2Core.cpp | |
| parent | bff40e55c9c55fbc8439bb225d1937b2d805e629 (diff) | |
| download | witness-tutorializer-c282663a96ae9704a59c55c9300dbc8c49e0ef39.tar.gz witness-tutorializer-c282663a96ae9704a59c55c9300dbc8c49e0ef39.tar.bz2 witness-tutorializer-c282663a96ae9704a59c55c9300dbc8c49e0ef39.zip | |
Add sanity checks for overwriting buffers
Diffstat (limited to 'Source/Randomizer2Core.cpp')
| -rw-r--r-- | Source/Randomizer2Core.cpp | 30 |
1 files changed, 9 insertions, 21 deletions
| diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index 8bd5765..0310ae2 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp | |||
| @@ -6,31 +6,19 @@ | |||
| 6 | #include <iostream> | 6 | #include <iostream> |
| 7 | #include <cassert> | 7 | #include <cassert> |
| 8 | 8 | ||
| 9 | // @Cutnpaste | 9 | std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges, bool allowEdges) { |
| 10 | std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) { | ||
| 11 | std::vector<Pos> edges; | 10 | std::vector<Pos> edges; |
| 12 | for (int x=0; x<p.width; x++) { | 11 | int xMin = allowEdges ? 0 : 1; |
| 13 | for (int y=0; y<p.height; y++) { | 12 | int xMax = allowEdges ? p.width : p.width-1; |
| 14 | if (x%2 == y%2) continue; | 13 | int yMin = allowEdges ? 0 : 1; |
| 15 | if (p.grid[x][y].gap != Cell::Gap::NONE) continue; | 14 | int yMax = allowEdges ? p.height : p.height-1; |
| 16 | 15 | ||
| 17 | // If the puzzle already has a sequence, don't cut along it. | 16 | for (int x=xMin; x<xMax; x++) { |
| 18 | bool inSequence = false; | 17 | for (int y=yMin; y<yMax; y++) { |
| 19 | for (Pos pos : p.sequence) inSequence |= (pos.x == x && pos.y == y); | ||
| 20 | if (inSequence) continue; | ||
| 21 | edges.emplace_back(Pos{x, y}); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | return CutEdgesInternal(p, edges, numEdges); | ||
| 25 | } | ||
| 26 | |||
| 27 | std::vector<Pos> Randomizer2Core::CutEdges2(const Puzzle& p, size_t numEdges) { | ||
| 28 | std::vector<Pos> edges; | ||
| 29 | // Note the iterator bounds; we skip the outer edges. | ||
| 30 | for (int x=1; x<p.width-1; x++) { | ||
| 31 | for (int y=1; y<p.height-1; y++) { | ||
| 32 | if (x%2 == y%2) continue; | 18 | if (x%2 == y%2) continue; |
| 33 | if (p.grid[x][y].gap != Cell::Gap::NONE) continue; | 19 | if (p.grid[x][y].gap != Cell::Gap::NONE) continue; |
| 20 | if (p.grid[x][y].start) continue; | ||
| 21 | if (p.grid[x][y].end != Cell::Dir::NONE) continue; | ||
| 34 | 22 | ||
| 35 | // If the puzzle already has a sequence, don't cut along it. | 23 | // If the puzzle already has a sequence, don't cut along it. |
| 36 | bool inSequence = false; | 24 | bool inSequence = false; |
