From d5bce3bba23a5ba4c296f1783ba277bcc206736c Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 20 Nov 2019 20:30:25 -0800 Subject: Some progress on symmetry. --- App/Main.cpp | 2 +- Source/Puzzle.cpp | 19 +++++++++++++++ Source/Puzzle.h | 11 +++++---- Source/PuzzleSerializer.cpp | 58 ++++++++++++++++++++++++++++++--------------- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/App/Main.cpp b/App/Main.cpp index 55074ed..8df3e6e 100644 --- a/App/Main.cpp +++ b/App/Main.cpp @@ -268,7 +268,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance // WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, // 200, 80, 200, 200, g_hwnd, NULL, g_hInstance, NULL); - g_panelId = CreateText(200, 100, 100, L"86"); + g_panelId = CreateText(200, 100, 100, L"59"); CreateButton(200, 130, 100, L"Read", TMP1); CreateButton(200, 160, 100, L"Write", TMP2); CreateButton(200, 190, 100, L"Solve", TMP3); diff --git a/Source/Puzzle.cpp b/Source/Puzzle.cpp index d0ede27..2f399a7 100644 --- a/Source/Puzzle.cpp +++ b/Source/Puzzle.cpp @@ -27,6 +27,25 @@ void Puzzle::NewGrid(int newWidth, int newHeight) { for (int x=0; x> grid; diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 132ebb7..e7381d8 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp @@ -8,8 +8,8 @@ PuzzleSerializer::PuzzleSerializer(const std::shared_ptr& memory) : _memory(memory) {} Puzzle PuzzleSerializer::ReadPuzzle(int id) { - int width = 2 * _memory->ReadEntityData(id, GRID_SIZE_X, 1)[0] - 1; - int height = 2 * _memory->ReadEntityData(id, GRID_SIZE_Y, 1)[0] - 1; + int width = _memory->ReadEntityData(id, GRID_SIZE_X, 1)[0] - 1; + int height = _memory->ReadEntityData(id, GRID_SIZE_Y, 1)[0] - 1; if (width == 0) width = height; if (height == 0) height = width; if (width < 0 || height < 0) return Puzzle(); // @Error: Grid size should be always positive? Looks like the starting panels break this rule, though. @@ -45,11 +45,12 @@ void PuzzleSerializer::WritePuzzle(const Puzzle& p, int id) { VERTI_GAP_SIZE = HEIGHT_INTERVAL / 2; WriteIntersections(p); + WriteEndpoints(p); WriteDots(p); WriteGaps(p); - WriteEndpoints(p); WriteDecorations(p, id); WriteSequence(p, id); + WriteSymmetry(p, id); #ifndef NDEBUG int maxDots = _memory->ReadEntityData(id, NUM_DOTS, 1)[0]; @@ -190,9 +191,9 @@ void PuzzleSerializer::ReadSymmetry(Puzzle& p, int id) { Pos p1 = loc_to_xy(p, reflectionData[0]); Pos p2 = loc_to_xy(p, reflectionData[reflectionData[0]]); if (p1.x != p2.x) { - p.symmetry = Puzzle::Symmetry::Y; - } else if (p1.y != p2.y) { p.symmetry = Puzzle::Symmetry::X; + } else if (p1.y != p2.y) { + p.symmetry = Puzzle::Symmetry::Y; } else { p.symmetry = Puzzle::Symmetry::XY; } @@ -260,6 +261,12 @@ void PuzzleSerializer::WriteIntersections(const Puzzle& p) { } void PuzzleSerializer::WriteEndpoints(const Puzzle& p) { + // int xMin, xMax, yMin, yMax; + // + // if (p.symmetry == Puzzle::Symmetry::NONE) { + // xMin = + // } + for (int x=0; x reflectionData; + reflectionData.resize(_intersectionFlags.size()); + + // Wow, what a horrible solution. But hey, whatever, if it works. + for (int x=0; x PuzzleSerializer::loc_to_xy(const Puzzle& p, int location) const { @@ -457,6 +475,8 @@ std::tuple PuzzleSerializer::loc_to_xy(const Puzzle& p, int location) } int PuzzleSerializer::xy_to_loc(const Puzzle& p, int x, int y) const { + assert(x%2 == 0); + assert(y%2 == 0); int height2 = (p.height - 1) / 2; int width2 = (p.width + 1) / 2; -- cgit 1.4.1