From ba04ac934dea549497e2e89fa7a9e5bc8723f5f8 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Aug 2021 17:18:02 -0400 Subject: Cleaned up a bunch of stuff I'm not using --- Source/ChallengeRandomizer.cpp | 108 ------------------ Source/ChallengeRandomizer.h | 13 --- Source/Randomizer.cpp | 251 ++--------------------------------------- Source/Randomizer.h | 31 ----- Source/Solver.cpp | 76 ------------- Source/Solver.h | 13 --- Source/Source.vcxproj | 6 - Source/Validator.cpp | 97 ---------------- Source/Validator.h | 27 ----- 9 files changed, 8 insertions(+), 614 deletions(-) delete mode 100644 Source/ChallengeRandomizer.cpp delete mode 100644 Source/ChallengeRandomizer.h delete mode 100644 Source/Solver.cpp delete mode 100644 Source/Solver.h delete mode 100644 Source/Validator.cpp delete mode 100644 Source/Validator.h (limited to 'Source') diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp deleted file mode 100644 index 976374e..0000000 --- a/Source/ChallengeRandomizer.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "pch.h" -#include "ChallengeRandomizer.h" - -// Modify an opcode to use RNG2 instead of main RNG -void ChallengeRandomizer::AdjustRng(int offset) { - int currentRng = _memory->ReadData({offset}, 0x1)[0]; - _memory->WriteData({offset}, {currentRng + 0x20}); -} - -// Overwrite the pointer for the lightmap_generator (which is unused, afaict) to point to a secondary RNG. -// Then, adjust all the RNG functions in challenge/doors to use this RNG. -ChallengeRandomizer::ChallengeRandomizer(const std::shared_ptr& memory, int seed) : _memory(memory) -{ - RNG_ADDR = _memory->ReadData({GLOBALS + 0x10}, 1)[0]; - RNG2_ADDR = _memory->ReadData({GLOBALS + 0x30}, 1)[0]; - bool alreadyInjected = (RNG2_ADDR == RNG_ADDR + 4); - - if (!alreadyInjected) _memory->WriteData({GLOBALS + 0x30}, {RNG_ADDR + 4}); - _memory->WriteData({GLOBALS + 0x30, 0}, {seed}); - - // do_success_side_effects - _memory->AddSigScan({0xFF, 0xC8, 0x99, 0x2B, 0xC2, 0xD1, 0xF8, 0x8B, 0xD0}, [&](int index) { - if (GLOBALS == 0x5B28C0) { // Version differences. - index += 0x3E; - } else if (GLOBALS == 0x62D0A0) { - index += 0x42; - } - // Overwritten bytes start just after the movsxd rax, dword ptr ds:[rdi + 0x230] - // aka test eax, eax; jle 2C; imul rcx, rax, 34 - _memory->WriteData({index}, { - 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, // mov ecx, [0x00000000] ;This is going to be the address of the custom RNG - 0x67, 0xC7, 0x01, 0x00, 0x00, 0x00, 0x00, // mov dword ptr ds:[ecx], 0x00000000 ;This is going to be the seed value - 0x48, 0x83, 0xF8, 0x02, // cmp rax, 0x2 ;This is the short solve on the record player (which turns it off) - 0x90, 0x90, 0x90 // nop nop nop - }); - int target = (GLOBALS + 0x30) - (index + 0x6); // +6 is for the length of the line - _memory->WriteData({index + 0x2}, {target}); - _memory->WriteData({index + 0x9}, {seed}); // Because we're resetting seed every challenge, we need to run this injection every time. - }); - - if (!alreadyInjected) { - // shuffle_integers - _memory->AddSigScan({0x48, 0x89, 0x5C, 0x24, 0x10, 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x63, 0xDA, 0x48, 0x8B, 0xF1, 0x83, 0xFB, 0x01}, [&](int index) { - AdjustRng(index + 0x23); - }); - // shuffle - _memory->AddSigScan({0x33, 0xF6, 0x48, 0x8B, 0xD9, 0x39, 0x31, 0x7E, 0x51}, [&](int index) { - AdjustRng(index - 0x4); - }); - // cut_random_edges - _memory->AddSigScan({0x89, 0x44, 0x24, 0x3C, 0x33, 0xC0, 0x85, 0xC0, 0x75, 0xFA}, [&](int index) { - AdjustRng(index + 0x3B); - }); - // get_empty_decoration_slot - _memory->AddSigScan({0x42, 0x83, 0x3C, 0x80, 0x00, 0x75, 0xDF}, [&](int index) { - AdjustRng(index - 0x17); - }); - // get_empty_dot_spot - _memory->AddSigScan({0xF7, 0xF3, 0x85, 0xD2, 0x74, 0xEC}, [&](int index) { - AdjustRng(index - 0xB); - }); - // add_exactly_this_many_bisection_dots - _memory->AddSigScan({0x48, 0x8B, 0xB4, 0x24, 0xB8, 0x00, 0x00, 0x00, 0x48, 0x8B, 0xBC, 0x24, 0xB0, 0x00, 0x00, 0x00}, [&](int index) { - AdjustRng(index - 0x4); - }); - // make_a_shaper - _memory->AddSigScan({0xF7, 0xE3, 0xD1, 0xEA, 0x8D, 0x0C, 0x52}, [&](int index) { - AdjustRng(index - 0x10); - AdjustRng(index + 0x1C); - AdjustRng(index + 0x49); - }); - // Entity_Machine_Panel::init_pattern_data_lotus - _memory->AddSigScan({0x40, 0x55, 0x56, 0x48, 0x8D, 0x6C, 0x24, 0xB1}, [&](int index) { - AdjustRng(index + 0x433); - AdjustRng(index + 0x45B); - AdjustRng(index + 0x5A7); - AdjustRng(index + 0x5D6); - AdjustRng(index + 0x6F6); - AdjustRng(index + 0xD17); - AdjustRng(index + 0xFDA); - }); - // Entity_Record_Player::reroll_lotus_eater_stuff - _memory->AddSigScan({0xB8, 0xAB, 0xAA, 0xAA, 0xAA, 0x41, 0xC1, 0xE8}, [&](int index) { - AdjustRng(index - 0x13); - AdjustRng(index + 0x34); - }); - - // These disable the random locations on timer panels, which would otherwise increment the RNG. - // I'm writing 31 C0 (xor eax, eax), then 3 NOPs, which pretends the RNG returns 0. - // do_lotus_minutes - _memory->AddSigScan({0x0F, 0xBE, 0x6C, 0x08, 0xFF, 0x45}, [&](int index) { - _memory->WriteData({index + 0x410}, {0x31, 0xC0, 0x90, 0x90, 0x90}); - }); - // do_lotus_tenths - _memory->AddSigScan({0x00, 0x04, 0x00, 0x00, 0x41, 0x8D, 0x50, 0x09}, [&](int index) { - _memory->WriteData({index + 0xA2}, {0x31, 0xC0, 0x90, 0x90, 0x90}); - }); - // do_lotus_eighths - _memory->AddSigScan({0x75, 0xF5, 0x0F, 0xBE, 0x44, 0x08, 0xFF}, [&](int index) { - _memory->WriteData({index + 0x1AE}, {0x31, 0xC0, 0x90, 0x90, 0x90}); - }); - } - - int failed = _memory->ExecuteSigScans(); - if (failed != 0) { - std::cout << "Failed " << failed << " sigscans"; - } -} diff --git a/Source/ChallengeRandomizer.h b/Source/ChallengeRandomizer.h deleted file mode 100644 index b06be81..0000000 --- a/Source/ChallengeRandomizer.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -class ChallengeRandomizer { -public: - ChallengeRandomizer(const std::shared_ptr& memory, int seed); - -private: - void AdjustRng(int offset); - std::shared_ptr _memory; - - int RNG_ADDR; - int RNG2_ADDR; -}; diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 74166af..5239cd6 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -93,7 +93,6 @@ Things to do for V2: */ #include "pch.h" #include "Randomizer.h" -#include "ChallengeRandomizer.h" #include "Panels.h" #include "Random.h" @@ -124,14 +123,6 @@ void Randomizer::Randomize() { } _memory->WriteData({index}, {0xEB}); // jz -> jmp }); - // Sig scans will be run during challenge randomization. - - // Seed challenge first for future-proofing - MEMORY_CATCH(RandomizeChallenge()); - - // Content swaps -- must happen before squarePanels - //MEMORY_CATCH(Randomize(upDownPanels, SWAP::LINES | SWAP::COLORS)); - //MEMORY_CATCH(Randomize(leftForwardRightPanels, SWAP::LINES | SWAP::COLORS)); // Tutorial Bend for (int panel : utmPerspective) { @@ -141,220 +132,23 @@ void Randomizer::Randomize() { for (int panel : squarePanels) { Tutorialise(panel, 0x00064); } - //Randomize(squarePanels, SWAP::LINES | SWAP::COLORS); - - // Individual area modifications - MEMORY_CATCH(RandomizeTutorial()); - MEMORY_CATCH(RandomizeDesert()); - MEMORY_CATCH(RandomizeQuarry()); - MEMORY_CATCH(RandomizeTreehouse()); - MEMORY_CATCH(RandomizeKeep()); - MEMORY_CATCH(RandomizeShadows()); - MEMORY_CATCH(RandomizeMonastery()); - MEMORY_CATCH(RandomizeBunker()); - MEMORY_CATCH(RandomizeJungle()); - MEMORY_CATCH(RandomizeSwamp()); - MEMORY_CATCH(RandomizeMountain()); - MEMORY_CATCH(RandomizeTown()); - MEMORY_CATCH(RandomizeSymmetry()); - // RandomizeAudioLogs(); -} - -void Randomizer::AdjustSpeed() { - // Desert Surface Final Control - _memory->WriteEntityData(0x09F95, OPEN_RATE, {0.04f}); // 4x - // Swamp Sliding Bridge - _memory->WriteEntityData(0x0061A, OPEN_RATE, {0.1f}); // 4x - // Mountain 2 Elevator - _memory->WriteEntityData(0x09EEC, OPEN_RATE, {0.075f}); // 3x -} - -void Randomizer::RandomizeLasers() { - Randomize(lasers, SWAP::TARGETS); - // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = _memory->ReadEntityData(0x0360E, TARGET, 1); - _memory->WriteEntityData(0x03317, TARGET, keepFrontLaserTarget); -} -void Randomizer::PreventSnipes() -{ - // Distance-gate swamp snipe 1 to prevent RNG swamp snipe - //_memory->WriteEntityData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); - // Distance-gate shadows laser to prevent sniping through the bars - //_memory->WriteEntityData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); -} - -// Private methods -void Randomizer::RandomizeTutorial() { // Disable tutorial cursor speed modifications (not working?) - _memory->WriteEntityData(0x00295, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x00293, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); -} - -void Randomizer::RandomizeSymmetry() { - /*std::vector randomOrder(transparent.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 1, 5); - ReassignTargets(transparent, randomOrder);*/ -} - -void Randomizer::RandomizeDesert() { - //Randomize(desertPanels, SWAP::LINES); - - // Turn off desert surface 8 - /*_memory->WriteEntityData(0x09F94, POWER, {0.0, 0.0}); - // Turn off desert flood final - _memory->WriteEntityData(0x18076, POWER, {0.0, 0.0}); - // Change desert floating target to desert flood final - _memory->WriteEntityData(0x17ECA, TARGET, {0x18077});*/ -} - -void Randomizer::RandomizeQuarry() { -} + _memory->WriteEntityData(0x00295, CURSOR_SPEED_SCALE, { 1.0 }); + _memory->WriteEntityData(0x0C373, CURSOR_SPEED_SCALE, { 1.0 }); + _memory->WriteEntityData(0x00293, CURSOR_SPEED_SCALE, { 1.0 }); + _memory->WriteEntityData(0x002C2, CURSOR_SPEED_SCALE, { 1.0 }); -void Randomizer::RandomizeTreehouse() { // Ensure that whatever pivot panels we have are flagged as "pivotable" // @Bug: Can return {}, be careful! int panelFlags = _memory->ReadEntityData(0x17DD1, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); + _memory->WriteEntityData(0x17DD1, STYLE_FLAGS, { panelFlags | 0x8000 }); panelFlags = _memory->ReadEntityData(0x17CE3, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); + _memory->WriteEntityData(0x17CE3, STYLE_FLAGS, { panelFlags | 0x8000 }); panelFlags = _memory->ReadEntityData(0x17DB7, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); + _memory->WriteEntityData(0x17DB7, STYLE_FLAGS, { panelFlags | 0x8000 }); panelFlags = _memory->ReadEntityData(0x17E52, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); -} - -void Randomizer::RandomizeKeep() { -} - -void Randomizer::RandomizeShadows() { - // Change the shadows tutorial cable to only activate avoid - _memory->WriteEntityData(0x319A8, CABLE_TARGET_2, {0}); - // Change shadows avoid 8 to power shadows follow - _memory->WriteEntityData(0x1972F, TARGET, {0x1C34C}); - - /*std::vector randomOrder(shadowsPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 0, 8); // Tutorial - RandomizeRange(randomOrder, SWAP::NONE, 8, 16); // Avoid - RandomizeRange(randomOrder, SWAP::NONE, 16, 21); // Follow - ReassignTargets(shadowsPanels, randomOrder); - // Turn off original starting panel - _memory->WriteEntityData(shadowsPanels[0], POWER, {0.0f, 0.0f}); - // Turn on new starting panel - _memory->WriteEntityData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f});*/ -} - -void Randomizer::RandomizeTown() { - // @Hack...? To open the gate at the end - /*std::vector randomOrder(orchard.size() + 1, 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 1, 5); - // Ensure that we open the gate before the final puzzle (by swapping) - int panel3Index = find(randomOrder, 3); - int panel4Index = find(randomOrder, 4); - randomOrder[std::min(panel3Index, panel4Index)] = 3; - randomOrder[std::max(panel3Index, panel4Index)] = 4; - ReassignTargets(orchard, randomOrder);*/ -} - -void Randomizer::RandomizeMonastery() { - /*std::vector randomOrder(monasteryPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 3, 9); // Outer 2 & 3, Inner 1-4 - ReassignTargets(monasteryPanels, randomOrder);*/ -} - -void Randomizer::RandomizeBunker() { - /*std::vector randomOrder(bunkerPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1 - // Tutorial 1 cannot be randomized, since no other panel can start on - // Glass 1 will become door + glass 1, due to the targetting system - RandomizeRange(randomOrder, SWAP::NONE, 1, 10); - // Randomize Glass 1-3 into everything after the door/glass 1 - const size_t glass1Index = find(randomOrder, 9); - RandomizeRange(randomOrder, SWAP::NONE, glass1Index + 1, 12); - ReassignTargets(bunkerPanels, randomOrder);*/ -} - -void Randomizer::RandomizeJungle() { - /*std::vector randomOrder(junglePanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - // Waves 1 cannot be randomized, since no other panel can start on - RandomizeRange(randomOrder, SWAP::NONE, 1, 7); // Waves 2-7 - RandomizeRange(randomOrder, SWAP::NONE, 8, 13); // Pitches 1-6 - ReassignTargets(junglePanels, randomOrder);*/ - - // Fix the wall's target to point back to the cable, and the cable to point to the pitches panel. - // auto wallTarget = _memory->ReadPanelData(junglePanels[7], TARGET, 1); - // _memory->WritePanelData(junglePanels[7], TARGET, {0x3C113}); - // _memory->WritePanelData(0x3C112, CABLE_TARGET_1, wallTarget); -} - -void Randomizer::RandomizeSwamp() { -} - -void Randomizer::RandomizeMountain() { - // Randomize multipanel - //Randomize(mountainMultipanel, SWAP::LINES | SWAP::COLORS); - - // Randomize final pillars order - /*std::vector targets = {pillars[0] + 1}; - for (const int pillar : pillars) { - int target = _memory->ReadEntityData(pillar, TARGET, 1)[0]; - targets.push_back(target); - } - targets[5] = pillars[5] + 1; - - std::vector randomOrder(pillars.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 0, 4); // Left Pillars 1-4 - RandomizeRange(randomOrder, SWAP::NONE, 5, 9); // Right Pillars 1-4 - ReassignTargets(pillars, randomOrder, targets); - // Turn off original starting panels - _memory->WriteEntityData(pillars[0], POWER, {0.0f, 0.0f}); - _memory->WriteEntityData(pillars[5], POWER, {0.0f, 0.0f}); - // Turn on new starting panels - _memory->WriteEntityData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); - _memory->WriteEntityData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f});*/ -} - -void Randomizer::RandomizeChallenge() { - /*ChallengeRandomizer cr(_memory, Random::RandInt(1, 0x7FFFFFFF)); // 0 will trigger an "RNG not initialized" block - for (int panel : challengePanels) { - _memory->WriteEntityData(panel, POWER_OFF_ON_FAIL, {0}); - }*/ -} - -void Randomizer::RandomizeAudioLogs() { - std::vector randomOrder(audiologs.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - Randomize(randomOrder, SWAP::NONE); - ReassignNames(audiologs, randomOrder); -} - -void Randomizer::Randomize(std::vector& panels, int flags) { - return RandomizeRange(panels, flags, 0, panels.size()); -} - -// Range is [start, end) -void Randomizer::RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex) { - if (panels.size() == 0) return; - if (startIndex >= endIndex) return; - if (endIndex >= panels.size()) endIndex = static_cast(panels.size()); - for (size_t i = 0; i < panels.size(); i++) { - /*const int target = Random::RandInt(static_cast(startIndex), static_cast(i)); - if (i != target) { - // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; - SwapPanels(panels[i], panels[target], flags); - //std::swap(panels[i], panels[target]); // Panel indices in the array - }*/ - - } + _memory->WriteEntityData(0x17E52, STYLE_FLAGS, { panelFlags | 0x8000 }); } void Randomizer::Tutorialise(int panel1, int tutorialStraight) { @@ -421,32 +215,3 @@ void Randomizer::Tutorialise(int panel1, int tutorialStraight) { //arrays.push_back(SPECULAR_TEXTURE); } - -void Randomizer::ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets) { - if (targets.empty()) { - // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) - // The first panel may not have a wire to power it, so we use the panel ID itself. - targets = {panels[0] + 1}; - for (const int panel : panels) { - int target = _memory->ReadEntityData(panel, TARGET, 1)[0]; - targets.push_back(target); - } - } - - for (size_t i=0; iWriteEntityData(panels[order[i]], TARGET, {panelTarget}); - } -} - -void Randomizer::ReassignNames(const std::vector& panels, const std::vector& order) { - std::vector names; - for (const int panel : panels) { - names.push_back(_memory->ReadEntityData(panel, AUDIO_LOG_NAME, 1)[0]); - } - - for (int i=0; iWriteEntityData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); - } -} diff --git a/Source/Randomizer.h b/Source/Randomizer.h index ae89dc9..a26acab 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -4,42 +4,11 @@ class Randomizer { public: Randomizer(const std::shared_ptr& memory); void Randomize(); - void RandomizeChallenge(); - - void AdjustSpeed(); - void RandomizeLasers(); - void PreventSnipes(); - - enum SWAP { - NONE = 0, - TARGETS = 1, - LINES = 2, - AUDIO_NAMES = 4, - COLORS = 8, - }; private: int _lastRandomizedFrame = 1 << 30; - void RandomizeTutorial(); - void RandomizeSymmetry(); - void RandomizeDesert(); - void RandomizeQuarry(); - void RandomizeTreehouse(); - void RandomizeKeep(); - void RandomizeShadows(); - void RandomizeTown(); - void RandomizeMonastery(); - void RandomizeBunker(); - void RandomizeJungle(); - void RandomizeSwamp(); - void RandomizeMountain(); - void RandomizeAudioLogs(); - void Randomize(std::vector& panels, int flags); - void RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex); void Tutorialise(int panel1, int copyFrom); - void ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets = {}); - void ReassignNames(const std::vector& panels, const std::vector& order); std::shared_ptr _memory; diff --git a/Source/Solver.cpp b/Source/Solver.cpp deleted file mode 100644 index 74fa099..0000000 --- a/Source/Solver.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "pch.h" -#include "Solver.h" -#include "Validator.h" - -int Solver::MAX_SOLUTIONS = 10000; - -std::vector Solver::Solve(Puzzle& p) { - std::vector solutions; - // var start = (new Date()).getTime() - for (int x = 0; x < p.width; x++) { - for (int y = 0; y < p.height; y++) { - Cell cell = p.grid[x][y]; - if (cell.start) { - SolveLoop(p, x, y, solutions); - } - } - } - // var end = (new Date()).getTime() - // console.info('Solved', puzzle, 'in', (end-start)/1000, 'seconds') - return solutions; -} - -void Solver::SolveLoop(Puzzle& p, int x, int y, std::vector& solutions) { - // Stop trying to solve once we reach our goal - if (solutions.size() >= MAX_SOLUTIONS) return; - Cell cell = p.GetCell(x, y); - if (cell.undefined) return; - if (cell.gap != Cell::Gap::NONE) return; - - if (p.symmetry == Puzzle::Symmetry::NONE) { - if (cell.color != Cell::Color::NONE) return; // Collided with ourselves - p.grid[x][y].color = Cell::Color::BLACK; // Otherwise, mark this cell as visited - } else { - // Get the symmetrical position, and try coloring it - auto sym = p.GetSymmetricalPos(x, y); - Cell::Color oldColor = p.GetLine(sym.x, sym.y); - p.grid[sym.x][sym.y].color = Cell::Color::YELLOW; - - // Collided with ourselves or our reflection - if (cell.color != Cell::Color::NONE) { - p.grid[sym.x][sym.y].color = oldColor; - return; - } - p.grid[x][y].color = Cell::Color::BLUE; // Otherwise, mark this cell as visited - } - p.sequence.emplace_back(x, y); - - if (cell.end != Cell::Dir::NONE) { - // Reached an endpoint, validate solution and keep going -- there may be other endpoints - Validator::Validate(p); - if (p.valid) { - Puzzle clone = p; - solutions.push_back(clone); - } - } - - // Recursion order (LRUD) is optimized for BL->TR and mid-start puzzles - // Extend path left and right - if (y % 2 == 0) { - SolveLoop(p, x - 1, y, solutions); - SolveLoop(p, x + 1, y, solutions); - } - // Extend path up and down - if (x % 2 == 0) { - SolveLoop(p, x, y - 1, solutions); - SolveLoop(p, x, y + 1, solutions); - } - - // Tail recursion: Back out of this cell - p.grid[x][y].color = Cell::Color::NONE; - p.sequence.pop_back(); - if (p.symmetry != Puzzle::Symmetry::NONE) { - auto sym = p.GetSymmetricalPos(x, y); - p.grid[sym.x][sym.y].color = Cell::Color::NONE; - } -} diff --git a/Source/Solver.h b/Source/Solver.h deleted file mode 100644 index 455d1eb..0000000 --- a/Source/Solver.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -class Puzzle; -class Solver { -public: - static int MAX_SOLUTIONS; - static std::vector Solve(Puzzle& p); - -private: - static void SolveLoop(Puzzle& p, int x, int y, std::vector& solutions); -}; - diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 8d6104c..7d6b20a 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -161,7 +161,6 @@ - @@ -172,11 +171,8 @@ - - - Create @@ -188,8 +184,6 @@ - - diff --git a/Source/Validator.cpp b/Source/Validator.cpp deleted file mode 100644 index 3b4020b..0000000 --- a/Source/Validator.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "pch.h" -#include "Validator.h" - -void Validator::Validate(Puzzle& p) { - // console.log('Validating', puzzle); - p.valid = true; // Assume valid until we find an invalid element - p.invalidElements.clear(); - p.negations.clear(); - - bool puzzleHasSymbols = false; - bool puzzleHasStart = false; - bool puzzleHasEnd = false; - // Validate gap failures as an early exit. - for (int x = 0; x < p.width; x++) { - for (int y = 0; y < p.height; y++) { - const Cell& cell = p.grid[x][y]; - const auto& decoration = cell.decoration; - if (decoration) { - if (decoration->type == Type::Stone || - decoration->type == Type::Star || - decoration->type == Type::Nega || - decoration->type == Type::Poly || - decoration->type == Type::Ylop) { - puzzleHasSymbols = true; - continue; - } - if (decoration->type == Type::Triangle) { - int actualCount = 0; - if (p.GetLine(x - 1, y) != Cell::Color::NONE) actualCount++; - if (p.GetLine(x + 1, y) != Cell::Color::NONE) actualCount++; - if (p.GetLine(x, y - 1) != Cell::Color::NONE) actualCount++; - if (p.GetLine(x, y + 1) != Cell::Color::NONE) actualCount++; - if (decoration->count != actualCount) { - // console.log('Triangle at grid['+x+']['+y+'] has', actualCount, 'borders') - p.invalidElements.emplace_back(x, y); - } - } - } - if (cell.gap != Cell::Gap::NONE && cell.color != Cell::Color::NONE) { - // console.log('Gap at', x, y, 'is covered') - p.valid = false; - } - if (cell.dot != Cell::Dot::NONE) { - if (cell.color == Cell::Color::NONE) { - // console.log('Dot at', x, y, 'is not covered') - p.invalidElements.emplace_back(x, y); - } else if (cell.color == Cell::Color::BLUE && cell.dot == Cell::Dot::YELLOW) { - // console.log('Yellow dot at', x, y, 'is covered by blue line') - p.valid = false; - } else if (cell.color == Cell::Color::YELLOW && cell.dot == Cell::Dot::BLUE) { - // console.log('Blue dot at', x, y, 'is covered by yellow line') - p.valid = false; - } - } - if (cell.color != Cell::Color::NONE) { - if (cell.start == true) puzzleHasStart = true; - if (cell.end != Cell::Dir::NONE) puzzleHasEnd = true; - } - } - } - if (!puzzleHasStart || !puzzleHasEnd) { - // console.log('There is no covered start or endpoint') - p.valid = false; - } - - // Perf optimization: We can skip computing regions if the grid has no symbols. - if (!puzzleHasSymbols) { // No additional symbols, and we already checked dots & gaps - p.valid &= (p.invalidElements.size() == 0); - } else { // Additional symbols, so we need to discard dots & divide them by region - /* - p.invalidElements.clear(); - std::vector regions = p.GetRegions(); - // console.log('Found', regions.length, 'regions'); - // console.debug(regions); - - for (const Region& region : regions) { - std::string key = region.grid.ToString(); - auto regionData = puzzle.regionCache[key]; - if (regionData == undefined) { - console.log('Cache miss for region', region, 'key', key); - regionData = _regionCheckNegations(puzzle, region); - // Entirely for convenience - regionData.valid = (regionData.invalidElements.size() == 0) - // console.log('Region valid:', regionData.valid); - - if (!DISABLE_CACHE) { - p.regionCache[key] = regionData; - } - } - p.negations = p.negations.concat(regionData.negations); - p.invalidElements = p.invalidElements.concat(regionData.invalidElements); - p.valid = p.valid && regionData.valid; - } - */ - } - // console.log('Puzzle has', puzzle.invalidElements.length, 'invalid elements') -} diff --git a/Source/Validator.h b/Source/Validator.h deleted file mode 100644 index 2a102dd..0000000 --- a/Source/Validator.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include -#include - -#ifndef NEGATIONS_CANCEL_NEGATIONS -#define NEGATIONS_CANCEL_NEGATIONS true -#endif - -#ifndef SIMPLE_POLYOMINOS -#define SIMPLE_POLYOMINOS true -#endif - -#ifndef DISABLE_CACHE -#define DISABLE_CACHE false -#endif - -struct Region{}; -class Puzzle; -struct Pos; -class Validator { -public: - static void Validate(Puzzle& p); - -private: - static void RegionCheckNegations(Puzzle& p, const Region& r); - static std::vector RegionCheck(Puzzle& p, const Region& r); -}; -- cgit 1.4.1