summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--App/App.vcxproj12
-rw-r--r--App/Main.cpp7
-rw-r--r--Source/ChallengeRandomizer.cpp3
-rw-r--r--Source/ChallengeRandomizer.h2
-rw-r--r--Source/Memory.cpp4
-rw-r--r--Source/Memory.h9
-rw-r--r--Source/MemoryException.h3
-rw-r--r--Source/Panels.h1
-rw-r--r--Source/Puzzle.cpp2
-rw-r--r--Source/Puzzle.h4
-rw-r--r--Source/PuzzleSerializer.cpp16
-rw-r--r--Source/PuzzleSerializer.h5
-rw-r--r--Source/Random.cpp2
-rw-r--r--Source/Random.h1
-rw-r--r--Source/Randomizer.cpp8
-rw-r--r--Source/Randomizer.h2
-rw-r--r--Source/Randomizer2.cpp30
-rw-r--r--Source/Randomizer2.h1
-rw-r--r--Source/Randomizer2Core.cpp20
-rw-r--r--Source/Randomizer2Core.h4
-rw-r--r--Source/Solver.cpp1
-rw-r--r--Source/Source.vcxproj13
-rw-r--r--Source/Validator.cpp3
-rw-r--r--Source/pch.h26
-rw-r--r--Test/RandomTests.cpp1
-rw-r--r--Test/Temp.cpp1
-rw-r--r--Test/Test.vcxproj8
27 files changed, 99 insertions, 90 deletions
diff --git a/App/App.vcxproj b/App/App.vcxproj index 25ec076..e2e75a8 100644 --- a/App/App.vcxproj +++ b/App/App.vcxproj
@@ -89,7 +89,7 @@
89 </PropertyGroup> 89 </PropertyGroup>
90 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 90 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
91 <ClCompile> 91 <ClCompile>
92 <PrecompiledHeader>NotUsing</PrecompiledHeader> 92 <PrecompiledHeader>Create</PrecompiledHeader>
93 <WarningLevel>Level3</WarningLevel> 93 <WarningLevel>Level3</WarningLevel>
94 <Optimization>Disabled</Optimization> 94 <Optimization>Disabled</Optimization>
95 <SDLCheck>true</SDLCheck> 95 <SDLCheck>true</SDLCheck>
@@ -98,6 +98,7 @@
98 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 98 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
99 <LanguageStandard>stdcpp17</LanguageStandard> 99 <LanguageStandard>stdcpp17</LanguageStandard>
100 <TreatWarningAsError>true</TreatWarningAsError> 100 <TreatWarningAsError>true</TreatWarningAsError>
101 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
101 </ClCompile> 102 </ClCompile>
102 <Link> 103 <Link>
103 <SubSystem>Windows</SubSystem> 104 <SubSystem>Windows</SubSystem>
@@ -106,7 +107,7 @@
106 </ItemDefinitionGroup> 107 </ItemDefinitionGroup>
107 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 108 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
108 <ClCompile> 109 <ClCompile>
109 <PrecompiledHeader>NotUsing</PrecompiledHeader> 110 <PrecompiledHeader>Create</PrecompiledHeader>
110 <WarningLevel>Level3</WarningLevel> 111 <WarningLevel>Level3</WarningLevel>
111 <Optimization>Disabled</Optimization> 112 <Optimization>Disabled</Optimization>
112 <SDLCheck>true</SDLCheck> 113 <SDLCheck>true</SDLCheck>
@@ -116,6 +117,7 @@
116 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 117 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
117 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 118 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
118 <TreatWarningAsError>true</TreatWarningAsError> 119 <TreatWarningAsError>true</TreatWarningAsError>
120 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
119 </ClCompile> 121 </ClCompile>
120 <Link> 122 <Link>
121 <SubSystem>Windows</SubSystem> 123 <SubSystem>Windows</SubSystem>
@@ -124,7 +126,7 @@
124 </ItemDefinitionGroup> 126 </ItemDefinitionGroup>
125 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 127 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
126 <ClCompile> 128 <ClCompile>
127 <PrecompiledHeader>NotUsing</PrecompiledHeader> 129 <PrecompiledHeader>Create</PrecompiledHeader>
128 <WarningLevel>Level3</WarningLevel> 130 <WarningLevel>Level3</WarningLevel>
129 <Optimization>MaxSpeed</Optimization> 131 <Optimization>MaxSpeed</Optimization>
130 <FunctionLevelLinking>true</FunctionLevelLinking> 132 <FunctionLevelLinking>true</FunctionLevelLinking>
@@ -135,6 +137,7 @@
135 <LanguageStandard>stdcpp17</LanguageStandard> 137 <LanguageStandard>stdcpp17</LanguageStandard>
136 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 138 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
137 <TreatWarningAsError>true</TreatWarningAsError> 139 <TreatWarningAsError>true</TreatWarningAsError>
140 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
138 </ClCompile> 141 </ClCompile>
139 <Link> 142 <Link>
140 <SubSystem>Windows</SubSystem> 143 <SubSystem>Windows</SubSystem>
@@ -146,7 +149,7 @@
146 </ItemDefinitionGroup> 149 </ItemDefinitionGroup>
147 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 150 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
148 <ClCompile> 151 <ClCompile>
149 <PrecompiledHeader>NotUsing</PrecompiledHeader> 152 <PrecompiledHeader>Create</PrecompiledHeader>
150 <WarningLevel>Level3</WarningLevel> 153 <WarningLevel>Level3</WarningLevel>
151 <Optimization>MaxSpeed</Optimization> 154 <Optimization>MaxSpeed</Optimization>
152 <FunctionLevelLinking>true</FunctionLevelLinking> 155 <FunctionLevelLinking>true</FunctionLevelLinking>
@@ -158,6 +161,7 @@
158 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 161 <AdditionalIncludeDirectories>..\Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
159 <TreatWarningAsError>true</TreatWarningAsError> 162 <TreatWarningAsError>true</TreatWarningAsError>
160 <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 163 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
164 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
161 </ClCompile> 165 </ClCompile>
162 <Link> 166 <Link>
163 <SubSystem>Windows</SubSystem> 167 <SubSystem>Windows</SubSystem>
diff --git a/App/Main.cpp b/App/Main.cpp index 9e2757e..4bd009a 100644 --- a/App/Main.cpp +++ b/App/Main.cpp
@@ -1,12 +1,7 @@
1#include "Windows.h" 1#include "pch.h"
2#include "Richedit.h" 2#include "Richedit.h"
3#include "Version.h" 3#include "Version.h"
4 4
5#include <cassert>
6#include <iostream>
7#include <string>
8#include <thread>
9
10#include "Memory.h" 5#include "Memory.h"
11#include "Random.h" 6#include "Random.h"
12#include "Randomizer.h" 7#include "Randomizer.h"
diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp index e91e9ac..b497564 100644 --- a/Source/ChallengeRandomizer.cpp +++ b/Source/ChallengeRandomizer.cpp
@@ -1,5 +1,6 @@
1#include "pch.h"
1#include "ChallengeRandomizer.h" 2#include "ChallengeRandomizer.h"
2#include <iostream> 3#include "Memory.h"
3 4
4// Modify an opcode to use RNG2 instead of main RNG 5// Modify an opcode to use RNG2 instead of main RNG
5void ChallengeRandomizer::AdjustRng(int offset) { 6void ChallengeRandomizer::AdjustRng(int offset) {
diff --git a/Source/ChallengeRandomizer.h b/Source/ChallengeRandomizer.h index fb0338a..b06be81 100644 --- a/Source/ChallengeRandomizer.h +++ b/Source/ChallengeRandomizer.h
@@ -1,6 +1,4 @@
1#pragma once 1#pragma once
2#include "Memory.h"
3#include <memory>
4 2
5class ChallengeRandomizer { 3class ChallengeRandomizer {
6public: 4public:
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 80cd103..3121d20 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp
@@ -1,9 +1,7 @@
1#include "pch.h"
1#include "Memory.h" 2#include "Memory.h"
2#include <psapi.h> 3#include <psapi.h>
3#include <tlhelp32.h> 4#include <tlhelp32.h>
4#include <iostream>
5#include <string>
6#include <cassert>
7 5
8#undef PROCESSENTRY32 6#undef PROCESSENTRY32
9#undef Process32Next 7#undef Process32Next
diff --git a/Source/Memory.h b/Source/Memory.h index d497123..82d1293 100644 --- a/Source/Memory.h +++ b/Source/Memory.h
@@ -1,11 +1,4 @@
1#pragma once 1#pragma once
2#include <functional>
3#include <map>
4#include <thread>
5#include <vector>
6#include <windows.h>
7#include <cassert>
8#include "MemoryException.h"
9 2
10#define GLOBALS 0x5B28C0 3#define GLOBALS 0x5B28C0
11// #define GLOBALS 0x62D0A0 4// #define GLOBALS 0x62D0A0
@@ -16,6 +9,8 @@ enum class ProcStatus {
16 NewGame 9 NewGame
17}; 10};
18 11
12using byte = unsigned char;
13
19// https://github.com/erayarslan/WriteProcessMemory-Example 14// https://github.com/erayarslan/WriteProcessMemory-Example
20// http://stackoverflow.com/q/32798185 15// http://stackoverflow.com/q/32798185
21// http://stackoverflow.com/q/36018838 16// http://stackoverflow.com/q/36018838
diff --git a/Source/MemoryException.h b/Source/MemoryException.h index ad2824d..48753cd 100644 --- a/Source/MemoryException.h +++ b/Source/MemoryException.h
@@ -1,7 +1,4 @@
1#pragma once 1#pragma once
2#include <exception>
3#include <string>
4#include <vector>
5 2
6#define MEMORY_CATCH(expr) \ 3#define MEMORY_CATCH(expr) \
7try { \ 4try { \
diff --git a/Source/Panels.h b/Source/Panels.h index 2c7c075..4a850ee 100644 --- a/Source/Panels.h +++ b/Source/Panels.h
@@ -1,5 +1,4 @@
1#pragma once 1#pragma once
2#include <vector>
3 2
4// Some of these (the puzzle ones) are duplicated elsewhere 3// Some of these (the puzzle ones) are duplicated elsewhere
5std::vector<int> lasers = { 4std::vector<int> lasers = {
diff --git a/Source/Puzzle.cpp b/Source/Puzzle.cpp index 2f399a7..15352ed 100644 --- a/Source/Puzzle.cpp +++ b/Source/Puzzle.cpp
@@ -1,6 +1,6 @@
1#include "pch.h"
1#include "Puzzle.h" 2#include "Puzzle.h"
2#include "Memory.h" 3#include "Memory.h"
3#include <cassert>
4 4
5Cell Puzzle::GetCell(int x, int y) const { 5Cell Puzzle::GetCell(int x, int y) const {
6 x = Mod(x); 6 x = Mod(x);
diff --git a/Source/Puzzle.h b/Source/Puzzle.h index b7dedd5..c2a8fce 100644 --- a/Source/Puzzle.h +++ b/Source/Puzzle.h
@@ -1,8 +1,4 @@
1#pragma once 1#pragma once
2#include <memory>
3#include <vector>
4
5class Memory;
6 2
7enum Type { 3enum Type {
8 Stone = 0x100, 4 Stone = 0x100,
diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 7461f7b..33f6da6 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp
@@ -1,6 +1,6 @@
1#include "pch.h"
1#include "PuzzleSerializer.h" 2#include "PuzzleSerializer.h"
2#include "Memory.h" 3#include "Memory.h"
3#include <cassert>
4 4
5#pragma warning (disable:26451) 5#pragma warning (disable:26451)
6#pragma warning (disable:26812) 6#pragma warning (disable:26812)
@@ -65,16 +65,6 @@ void PuzzleSerializer::WritePuzzle(const Puzzle& p, int id) {
65 WriteSequence(p, id); 65 WriteSequence(p, id);
66 WriteSymmetry(p, id); 66 WriteSymmetry(p, id);
67 67
68#ifndef NDEBUG
69 int maxDots = _memory->ReadEntityData<int>(id, NUM_DOTS, 1)[0];
70 assert(_intersectionFlags.size() <= maxDots);
71 assert(_intersectionLocations.size() <= maxDots*2);
72
73 int maxConnections = _memory->ReadEntityData<int>(id, NUM_CONNECTIONS, 1)[0];
74 assert(_connectionsA.size() <= maxConnections);
75 assert(_connectionsB.size() <= maxConnections);
76#endif
77
78 _memory->WriteEntityData<int>(id, GRID_SIZE_X, {(p.width + 1)/2}); 68 _memory->WriteEntityData<int>(id, GRID_SIZE_X, {(p.width + 1)/2});
79 _memory->WriteEntityData<int>(id, GRID_SIZE_Y, {(p.height + 1)/2}); 69 _memory->WriteEntityData<int>(id, GRID_SIZE_Y, {(p.height + 1)/2});
80 _memory->WriteEntityData<int>(id, NUM_DOTS, {static_cast<int>(_intersectionFlags.size())}); 70 _memory->WriteEntityData<int>(id, NUM_DOTS, {static_cast<int>(_intersectionFlags.size())});
@@ -455,10 +445,6 @@ void PuzzleSerializer::WriteDecorations(const Puzzle& p, int id) {
455 } 445 }
456 } 446 }
457 447
458#ifndef NDEBUG
459 int maxDecorations = _memory->ReadEntityData<int>(id, NUM_DECORATIONS, 1)[0];
460 assert(decorations.size() < maxDecorations);
461#endif
462 _memory->WriteEntityData<int>(id, NUM_DECORATIONS, {static_cast<int>(decorations.size())}); 448 _memory->WriteEntityData<int>(id, NUM_DECORATIONS, {static_cast<int>(decorations.size())});
463 _memory->WriteArray<int>(id, DECORATIONS, decorations); 449 _memory->WriteArray<int>(id, DECORATIONS, decorations);
464} 450}
diff --git a/Source/PuzzleSerializer.h b/Source/PuzzleSerializer.h index 4ccd383..e1ee3e8 100644 --- a/Source/PuzzleSerializer.h +++ b/Source/PuzzleSerializer.h
@@ -1,11 +1,6 @@
1#pragma once 1#pragma once
2#include <memory>
3#include <unordered_map>
4
5#include "Puzzle.h" 2#include "Puzzle.h"
6 3
7class Memory;
8
9class PuzzleSerializer { 4class PuzzleSerializer {
10public: 5public:
11 PuzzleSerializer(const std::shared_ptr<Memory>& memory); 6 PuzzleSerializer(const std::shared_ptr<Memory>& memory);
diff --git a/Source/Random.cpp b/Source/Random.cpp index d9fe678..aee4d1a 100644 --- a/Source/Random.cpp +++ b/Source/Random.cpp
@@ -1,4 +1,4 @@
1#include <chrono> 1#include "pch.h"
2#include "Random.h" 2#include "Random.h"
3 3
4uint32_t Random::s_seed = static_cast<int>(time(nullptr)); // Seed from the time in milliseconds 4uint32_t Random::s_seed = static_cast<int>(time(nullptr)); // Seed from the time in milliseconds
diff --git a/Source/Random.h b/Source/Random.h index a2ad706..e809c1e 100644 --- a/Source/Random.h +++ b/Source/Random.h
@@ -1,5 +1,4 @@
1#pragma once 1#pragma once
2#include <typeinfo>
3 2
4class Random 3class Random
5{ 4{
diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 1427f4d..e70cf44 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp
@@ -91,14 +91,12 @@ Things to do for V2:
91 * 20 challenges with 20 consecutive seeds 91 * 20 challenges with 20 consecutive seeds
92 * Random *rotation* of desert laser redirect? 92 * Random *rotation* of desert laser redirect?
93*/ 93*/
94#include "pch.h"
94#include "Memory.h" 95#include "Memory.h"
95#include "Randomizer.h" 96#include "Randomizer.h"
96#include "ChallengeRandomizer.h" 97#include "ChallengeRandomizer.h"
97#include "Panels.h" 98#include "Panels.h"
98#include "Random.h" 99#include "Random.h"
99#include <string>
100#include <iostream>
101#include <numeric>
102 100
103template <class T> 101template <class T>
104int find(const std::vector<T> &data, T search, size_t startIndex = 0) { 102int find(const std::vector<T> &data, T search, size_t startIndex = 0) {
@@ -250,8 +248,8 @@ void Randomizer::RandomizeTown() {
250 // Ensure that we open the gate before the final puzzle (by swapping) 248 // Ensure that we open the gate before the final puzzle (by swapping)
251 int panel3Index = find(randomOrder, 3); 249 int panel3Index = find(randomOrder, 3);
252 int panel4Index = find(randomOrder, 4); 250 int panel4Index = find(randomOrder, 4);
253 randomOrder[min(panel3Index, panel4Index)] = 3; 251 randomOrder[std::min(panel3Index, panel4Index)] = 3;
254 randomOrder[max(panel3Index, panel4Index)] = 4; 252 randomOrder[std::max(panel3Index, panel4Index)] = 4;
255 ReassignTargets(orchard, randomOrder); 253 ReassignTargets(orchard, randomOrder);
256} 254}
257 255
diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 673468c..bd8895b 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h
@@ -1,6 +1,4 @@
1#pragma once 1#pragma once
2#include "Memory.h"
3#include <memory>
4 2
5class Randomizer { 3class Randomizer {
6public: 4public:
diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index f93e4fd..4f0bad0 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp
@@ -1,14 +1,11 @@
1#include "pch.h"
1#include "Randomizer2.h" 2#include "Randomizer2.h"
2#include "PuzzleSerializer.h" 3#include "PuzzleSerializer.h"
3#include "Randomizer2Core.h" 4#include "Randomizer2Core.h"
4#include "Puzzle.h" 5#include "Puzzle.h"
5#include "Random.h" 6#include "Random.h"
6#include "Solver.h" 7#include "Solver.h"
7 8#include "Windows.h"
8#include <cassert>
9#include <string>
10
11#pragma warning (disable: 26451)
12 9
13Randomizer2::Randomizer2(const PuzzleSerializer& serializer) : _serializer(serializer) {} 10Randomizer2::Randomizer2(const PuzzleSerializer& serializer) : _serializer(serializer) {}
14 11
@@ -229,6 +226,7 @@ void Randomizer2::RandomizeSymmetry() {
229 226
230 _serializer.WritePuzzle(p, 0x62); 227 _serializer.WritePuzzle(p, 0x62);
231 } 228 }
229 // TODO: Positioning is off, slightly -- which means you can start from the bottom left, if you peek around.
232 { // Back wall 5 230 { // Back wall 5
233 Puzzle p; 231 Puzzle p;
234 p.NewGrid(11, 8); 232 p.NewGrid(11, 8);
@@ -259,6 +257,28 @@ void Randomizer2::RandomizeSymmetry() {
259 257
260 _serializer.WritePuzzle(p, 0x5C); 258 _serializer.WritePuzzle(p, 0x5C);
261 } 259 }
260
261 { // Rotational 1
262 Puzzle p;
263 p.NewGrid(3, 3);
264 p.symmetry = Puzzle::Symmetry::XY;
265 p.grid[6][0].start = true;
266 p.grid[0][6].start = true;
267 p.grid[4][0].end = Cell::Dir::UP;
268 p.grid[2][6].end = Cell::Dir::DOWN;
269
270 p.grid[5][0].gap = Cell::Gap::BREAK;
271 p.grid[1][6].gap = Cell::Gap::BREAK;
272
273 for (Pos pos : Randomizer2Core::CutSymmetricalEdgePairs(p, 1)) {
274 std::string text = std::to_string(pos.x) + " " + std::to_string(pos.y);
275 OutputDebugStringA(text.c_str());
276 p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK;
277 Pos sym = p.GetSymmetricalPos(pos.x, pos.y);
278 p.grid[sym.x][sym.y].gap = Cell::Gap::BREAK;
279 }
280 _serializer.WritePuzzle(p, 0x8D);
281 }
262} 282}
263 283
264void Randomizer2::RandomizeKeep() { 284void Randomizer2::RandomizeKeep() {
diff --git a/Source/Randomizer2.h b/Source/Randomizer2.h index c8c3db5..34c89f5 100644 --- a/Source/Randomizer2.h +++ b/Source/Randomizer2.h
@@ -1,7 +1,6 @@
1#pragma once 1#pragma once
2#include "PuzzleSerializer.h" 2#include "PuzzleSerializer.h"
3 3
4class Puzzle;
5class Randomizer2 { 4class Randomizer2 {
6public: 5public:
7 Randomizer2(const PuzzleSerializer& serializer); 6 Randomizer2(const PuzzleSerializer& serializer);
diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index eaefa9a..89294ef 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp
@@ -1,11 +1,8 @@
1#include "pch.h"
1#include "Randomizer2Core.h" 2#include "Randomizer2Core.h"
2#include "Puzzle.h" 3#include "Puzzle.h"
3#include "Random.h" 4#include "Random.h"
4 5
5#include <string>
6#include <iostream>
7#include <cassert>
8
9std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) { 6std::vector<Pos> Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) {
10 return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges); 7 return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges);
11} 8}
@@ -16,17 +13,20 @@ std::vector<Pos> Randomizer2Core::CutInsideEdges(const Puzzle& p, size_t numEdge
16 13
17std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) { 14std::vector<Pos> Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) {
18 Puzzle copy = p; 15 Puzzle copy = p;
19 assert(p.symmetry != Puzzle::Symmetry::NONE); 16 // Prevent cuts from landing on the midline
20 if (p.symmetry == Puzzle::Symmetry::X) { 17 if (p.symmetry == Puzzle::Symmetry::X) {
21 // Prevent cuts from landing on the midline
22 for (int y=0; y<p.height; y++) { 18 for (int y=0; y<p.height; y++) {
23 copy.grid[p.width/2][y].gap = Cell::Gap::FULL; 19 copy.grid[p.width/2][y].gap = Cell::Gap::FULL;
24 } 20 }
25 21 } else if (p.symmetry == Puzzle::Symmetry::Y) {
26 return CutEdgesInternal(copy, 0, (p.width-1)/2, 0, p.height, numEdges); 22 for (int x=0; x<p.width; x++) {
23 copy.grid[x][p.height/2].gap = Cell::Gap::FULL;
24 }
25 } else {
26 assert(p.symmetry == Puzzle::Symmetry::XY);
27 // Pass, I think? Maybe this matters for odd numbers.
27 } 28 }
28 assert(false); 29 return CutEdgesInternal(copy, 0, (p.width-1)/2, 0, p.height, numEdges);
29 return {};
30} 30}
31 31
32std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) { 32std::vector<Pos> Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) {
diff --git a/Source/Randomizer2Core.h b/Source/Randomizer2Core.h index 674e4ea..df98de8 100644 --- a/Source/Randomizer2Core.h +++ b/Source/Randomizer2Core.h
@@ -1,8 +1,4 @@
1#pragma once 1#pragma once
2#include <vector>
3
4struct Pos;
5class Puzzle;
6 2
7class Randomizer2Core { 3class Randomizer2Core {
8public: 4public:
diff --git a/Source/Solver.cpp b/Source/Solver.cpp index c0b35ef..e09cba2 100644 --- a/Source/Solver.cpp +++ b/Source/Solver.cpp
@@ -1,3 +1,4 @@
1#include "pch.h"
1#include "Solver.h" 2#include "Solver.h"
2#include "Puzzle.h" 3#include "Puzzle.h"
3#include "Validator.h" 4#include "Validator.h"
diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 5aaa0b0..c63c664 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj
@@ -84,7 +84,7 @@
84 </PropertyGroup> 84 </PropertyGroup>
85 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 85 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86 <ClCompile> 86 <ClCompile>
87 <PrecompiledHeader>NotUsing</PrecompiledHeader> 87 <PrecompiledHeader>Create</PrecompiledHeader>
88 <WarningLevel>Level3</WarningLevel> 88 <WarningLevel>Level3</WarningLevel>
89 <Optimization>Disabled</Optimization> 89 <Optimization>Disabled</Optimization>
90 <SDLCheck>true</SDLCheck> 90 <SDLCheck>true</SDLCheck>
@@ -92,6 +92,7 @@
92 <ConformanceMode>true</ConformanceMode> 92 <ConformanceMode>true</ConformanceMode>
93 <LanguageStandard>stdcpp17</LanguageStandard> 93 <LanguageStandard>stdcpp17</LanguageStandard>
94 <TreatWarningAsError>true</TreatWarningAsError> 94 <TreatWarningAsError>true</TreatWarningAsError>
95 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
95 </ClCompile> 96 </ClCompile>
96 <Link> 97 <Link>
97 <SubSystem>Windows</SubSystem> 98 <SubSystem>Windows</SubSystem>
@@ -100,7 +101,7 @@
100 </ItemDefinitionGroup> 101 </ItemDefinitionGroup>
101 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 102 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102 <ClCompile> 103 <ClCompile>
103 <PrecompiledHeader>NotUsing</PrecompiledHeader> 104 <PrecompiledHeader>Create</PrecompiledHeader>
104 <WarningLevel>Level3</WarningLevel> 105 <WarningLevel>Level3</WarningLevel>
105 <Optimization>Disabled</Optimization> 106 <Optimization>Disabled</Optimization>
106 <SDLCheck>true</SDLCheck> 107 <SDLCheck>true</SDLCheck>
@@ -109,6 +110,7 @@
109 <LanguageStandard>stdcpp17</LanguageStandard> 110 <LanguageStandard>stdcpp17</LanguageStandard>
110 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 111 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
111 <TreatWarningAsError>true</TreatWarningAsError> 112 <TreatWarningAsError>true</TreatWarningAsError>
113 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
112 </ClCompile> 114 </ClCompile>
113 <Link> 115 <Link>
114 <SubSystem>Windows</SubSystem> 116 <SubSystem>Windows</SubSystem>
@@ -117,7 +119,7 @@
117 </ItemDefinitionGroup> 119 </ItemDefinitionGroup>
118 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 120 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
119 <ClCompile> 121 <ClCompile>
120 <PrecompiledHeader>NotUsing</PrecompiledHeader> 122 <PrecompiledHeader>Create</PrecompiledHeader>
121 <WarningLevel>Level3</WarningLevel> 123 <WarningLevel>Level3</WarningLevel>
122 <Optimization>MaxSpeed</Optimization> 124 <Optimization>MaxSpeed</Optimization>
123 <FunctionLevelLinking>true</FunctionLevelLinking> 125 <FunctionLevelLinking>true</FunctionLevelLinking>
@@ -127,6 +129,7 @@
127 <ConformanceMode>true</ConformanceMode> 129 <ConformanceMode>true</ConformanceMode>
128 <LanguageStandard>stdcpp17</LanguageStandard> 130 <LanguageStandard>stdcpp17</LanguageStandard>
129 <TreatWarningAsError>true</TreatWarningAsError> 131 <TreatWarningAsError>true</TreatWarningAsError>
132 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
130 </ClCompile> 133 </ClCompile>
131 <Link> 134 <Link>
132 <SubSystem>Windows</SubSystem> 135 <SubSystem>Windows</SubSystem>
@@ -137,7 +140,7 @@
137 </ItemDefinitionGroup> 140 </ItemDefinitionGroup>
138 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 141 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
139 <ClCompile> 142 <ClCompile>
140 <PrecompiledHeader>NotUsing</PrecompiledHeader> 143 <PrecompiledHeader>Create</PrecompiledHeader>
141 <WarningLevel>Level3</WarningLevel> 144 <WarningLevel>Level3</WarningLevel>
142 <Optimization>MaxSpeed</Optimization> 145 <Optimization>MaxSpeed</Optimization>
143 <FunctionLevelLinking>true</FunctionLevelLinking> 146 <FunctionLevelLinking>true</FunctionLevelLinking>
@@ -148,6 +151,7 @@
148 <LanguageStandard>stdcpp17</LanguageStandard> 151 <LanguageStandard>stdcpp17</LanguageStandard>
149 <TreatWarningAsError>true</TreatWarningAsError> 152 <TreatWarningAsError>true</TreatWarningAsError>
150 <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 153 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
154 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
151 </ClCompile> 155 </ClCompile>
152 <Link> 156 <Link>
153 <SubSystem>Windows</SubSystem> 157 <SubSystem>Windows</SubSystem>
@@ -160,6 +164,7 @@
160 <ClInclude Include="ChallengeRandomizer.h" /> 164 <ClInclude Include="ChallengeRandomizer.h" />
161 <ClInclude Include="Memory.h" /> 165 <ClInclude Include="Memory.h" />
162 <ClInclude Include="MemoryException.h" /> 166 <ClInclude Include="MemoryException.h" />
167 <ClInclude Include="pch.h" />
163 <ClInclude Include="Puzzle.h" /> 168 <ClInclude Include="Puzzle.h" />
164 <ClInclude Include="Panels.h" /> 169 <ClInclude Include="Panels.h" />
165 <ClInclude Include="PuzzleSerializer.h" /> 170 <ClInclude Include="PuzzleSerializer.h" />
diff --git a/Source/Validator.cpp b/Source/Validator.cpp index e71dc34..cb0ffa8 100644 --- a/Source/Validator.cpp +++ b/Source/Validator.cpp
@@ -1,3 +1,4 @@
1#include "pch.h"
1#include "Validator.h" 2#include "Validator.h"
2#include "Puzzle.h" 3#include "Puzzle.h"
3 4
@@ -10,7 +11,7 @@ void Validator::Validate(Puzzle& p) {
10 bool puzzleHasSymbols = false; 11 bool puzzleHasSymbols = false;
11 bool puzzleHasStart = false; 12 bool puzzleHasStart = false;
12 bool puzzleHasEnd = false; 13 bool puzzleHasEnd = false;
13 // Validate gap failures as an early exit. 14 // Validate gap failures as an early exit.
14 for (int x = 0; x < p.width; x++) { 15 for (int x = 0; x < p.width; x++) {
15 for (int y = 0; y < p.height; y++) { 16 for (int y = 0; y < p.height; y++) {
16 Cell cell = p.grid[x][y]; 17 Cell cell = p.grid[x][y];
diff --git a/Source/pch.h b/Source/pch.h new file mode 100644 index 0000000..d431d61 --- /dev/null +++ b/Source/pch.h
@@ -0,0 +1,26 @@
1#pragma once
2
3#define WIN32_LEAN_AND_MEAN 1
4#define VC_EXTRALEAN 1
5#include <windows.h>
6#undef min
7#undef max
8
9#include <algorithm>
10#include <cassert>
11#include <chrono>
12#include <exception>
13#include <functional>
14#include <iostream>
15#include <map>
16#include <memory>
17#include <numeric>
18#include <string>
19#include <thread>
20#include <vector>
21
22#pragma warning (disable: 26451) // Potential arithmetic overflow
23
24#include "MemoryException.h"
25#include "Memory.h"
26#include "Puzzle.h"
diff --git a/Test/RandomTests.cpp b/Test/RandomTests.cpp index 20a86e5..7730a4f 100644 --- a/Test/RandomTests.cpp +++ b/Test/RandomTests.cpp
@@ -1,3 +1,4 @@
1#include "pch.h"
1#include "gtest/gtest.h" 2#include "gtest/gtest.h"
2#include "Random.h" 3#include "Random.h"
3 4
diff --git a/Test/Temp.cpp b/Test/Temp.cpp index 3b31539..bf6a09a 100644 --- a/Test/Temp.cpp +++ b/Test/Temp.cpp
@@ -1,3 +1,4 @@
1#include "pch.h"
1#include "gtest/gtest.h" 2#include "gtest/gtest.h"
2#include "Randomizer.h" 3#include "Randomizer.h"
3#include <iostream> 4#include <iostream>
diff --git a/Test/Test.vcxproj b/Test/Test.vcxproj index 857cdd4..4d00c77 100644 --- a/Test/Test.vcxproj +++ b/Test/Test.vcxproj
@@ -51,7 +51,7 @@
51 </ImportGroup> 51 </ImportGroup>
52 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 52 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
53 <ClCompile> 53 <ClCompile>
54 <PrecompiledHeader>NotUsing</PrecompiledHeader> 54 <PrecompiledHeader>Create</PrecompiledHeader>
55 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> 55 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
56 <Optimization>Disabled</Optimization> 56 <Optimization>Disabled</Optimization>
57 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 57 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -72,7 +72,7 @@
72 </ItemDefinitionGroup> 72 </ItemDefinitionGroup>
73 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 73 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74 <ClCompile> 74 <ClCompile>
75 <PrecompiledHeader>NotUsing</PrecompiledHeader> 75 <PrecompiledHeader>Create</PrecompiledHeader>
76 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> 76 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
77 <Optimization>Disabled</Optimization> 77 <Optimization>Disabled</Optimization>
78 <PreprocessorDefinitions>X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 78 <PreprocessorDefinitions>X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -93,7 +93,7 @@
93 </ItemDefinitionGroup> 93 </ItemDefinitionGroup>
94 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 94 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
95 <ClCompile> 95 <ClCompile>
96 <PrecompiledHeader>NotUsing</PrecompiledHeader> 96 <PrecompiledHeader>Create</PrecompiledHeader>
97 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> 97 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
98 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 98 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
99 <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 99 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -114,7 +114,7 @@
114 </ItemDefinitionGroup> 114 </ItemDefinitionGroup>
115 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 115 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
116 <ClCompile> 116 <ClCompile>
117 <PrecompiledHeader>NotUsing</PrecompiledHeader> 117 <PrecompiledHeader>Create</PrecompiledHeader>
118 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> 118 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
119 <PreprocessorDefinitions>X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 119 <PreprocessorDefinitions>X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120 <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 120 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>