From 0d0abe2ee56382c5751dd12fbca75af87773879f Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Thu, 14 Nov 2019 09:12:38 -0800 Subject: Refactoring - split out puzzle from serializer --- Source/Puzzle.h | 76 ++++----------------------------------------------------- 1 file changed, 5 insertions(+), 71 deletions(-) (limited to 'Source/Puzzle.h') diff --git a/Source/Puzzle.h b/Source/Puzzle.h index 94cb4b0..3a8e73b 100644 --- a/Source/Puzzle.h +++ b/Source/Puzzle.h @@ -62,7 +62,6 @@ struct Cell { struct Negation {}; struct Pos {int x; int y;}; -#include // TODO: Move this + impl to cpp class Puzzle { public: int16_t height; @@ -77,28 +76,9 @@ public: std::vector negations; std::vector invalidElements; - inline Cell GetCell(int x, int y) const { - x = Mod(x); - if (!SafeCell(x, y)) return Cell::Undefined(); - return grid[x][y]; - } - inline Cell::Color GetLine(int x, int y) const { - return grid[x][y].color; - } - inline void NewGrid(int newWidth, int newHeight) { - if (newWidth == 0) { - assert(false); - newWidth = width; - newHeight = height; - } else { - // @Cleanup! This should be in the ctor... - width = 2*newWidth + 1; - height = 2*newHeight + 1; - } - grid.clear(); - grid.resize(width); - for (int x=0; x> grid; private: - inline int Mod(int x) const { - if (!pillar) return x; - return (x + width * height * 2) % width; - } - - inline bool SafeCell(int x, int y) const { - if (x < 0 || x >= width) return false; - if (y < 0 || y >= height) return false; - return true; - } -}; - -class PuzzleSerializer { -public: - PuzzleSerializer(const std::shared_ptr& memory); - Puzzle ReadPuzzle(int id); - void WritePuzzle(const Puzzle& p, int id); - -private: - // @Bug: Blue and orange are swapped? - enum Flags { - IS_ENDPOINT = 0x1, - IS_STARTPOINT = 0x2, - IS_FULL_GAP = 0x8, - HAS_DOT = 0x20, - DOT_IS_BLUE = 0x100, - DOT_IS_ORANGE = 0x200, - DOT_IS_INVISIBLE = 0x1000, - HAS_ONE_CONN = 0x100000, - HAS_VERTI_CONN = 0x200000, - HAS_HORIZ_CONN = 0x400000, - }; - - void ReadIntersections(Puzzle& p, int id); - void ReadDecorations(Puzzle& p, int id); - void WriteIntersections(const Puzzle& p, int id); - void WriteDecorations(const Puzzle& p, int id); - - std::tuple loc_to_xy(const Puzzle& p, int location) const; - int xy_to_loc(const Puzzle& p, int x, int y) const; - // Decoration location - std::tuple dloc_to_xy(const Puzzle& p, int location) const; - int xy_to_dloc(const Puzzle& p, int x, int y) const; - Cell::Dot FlagsToDot(int flags) const; - // Iterate connection lists for another location which is connected to us; return that other location. - int FindConnection(int i, const std::vector& connections_a, const std::vector& connections_b) const; - - std::shared_ptr _memory; + inline int Mod(int x) const; + inline bool SafeCell(int x, int y) const; }; -- cgit 1.4.1