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. --- Source/PuzzleSerializer.cpp | 58 ++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'Source/PuzzleSerializer.cpp') 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