diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-14 09:12:38 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-14 09:12:38 -0800 |
commit | 0d0abe2ee56382c5751dd12fbca75af87773879f (patch) | |
tree | 3a1926ea915cf8b222769ca16c8fc83778738519 /Source/Puzzle.h | |
parent | 1b833a86102981ce178119fc3526f354b7622170 (diff) | |
download | witness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.tar.gz witness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.tar.bz2 witness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.zip |
Refactoring - split out puzzle from serializer
Diffstat (limited to 'Source/Puzzle.h')
-rw-r--r-- | Source/Puzzle.h | 76 |
1 files changed, 5 insertions, 71 deletions
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 { | |||
62 | struct Negation {}; | 62 | struct Negation {}; |
63 | struct Pos {int x; int y;}; | 63 | struct Pos {int x; int y;}; |
64 | 64 | ||
65 | #include <cassert> // TODO: Move this + impl to cpp | ||
66 | class Puzzle { | 65 | class Puzzle { |
67 | public: | 66 | public: |
68 | int16_t height; | 67 | int16_t height; |
@@ -77,28 +76,9 @@ public: | |||
77 | std::vector<Negation> negations; | 76 | std::vector<Negation> negations; |
78 | std::vector<Pos> invalidElements; | 77 | std::vector<Pos> invalidElements; |
79 | 78 | ||
80 | inline Cell GetCell(int x, int y) const { | 79 | inline Cell GetCell(int x, int y) const; |
81 | x = Mod(x); | 80 | inline Cell::Color GetLine(int x, int y) const; |
82 | if (!SafeCell(x, y)) return Cell::Undefined(); | 81 | inline void NewGrid(int newWidth, int newHeight); |
83 | return grid[x][y]; | ||
84 | } | ||
85 | inline Cell::Color GetLine(int x, int y) const { | ||
86 | return grid[x][y].color; | ||
87 | } | ||
88 | inline void NewGrid(int newWidth, int newHeight) { | ||
89 | if (newWidth == 0) { | ||
90 | assert(false); | ||
91 | newWidth = width; | ||
92 | newHeight = height; | ||
93 | } else { | ||
94 | // @Cleanup! This should be in the ctor... | ||
95 | width = 2*newWidth + 1; | ||
96 | height = 2*newHeight + 1; | ||
97 | } | ||
98 | grid.clear(); | ||
99 | grid.resize(width); | ||
100 | for (int x=0; x<width; x++) grid[x].resize(height); | ||
101 | } | ||
102 | 82 | ||
103 | // @TODO: | 83 | // @TODO: |
104 | Pos GetSymmetricalPos(int x, int y); | 84 | Pos GetSymmetricalPos(int x, int y); |
@@ -107,52 +87,6 @@ public: | |||
107 | std::vector<std::vector<Cell>> grid; | 87 | std::vector<std::vector<Cell>> grid; |
108 | 88 | ||
109 | private: | 89 | private: |
110 | inline int Mod(int x) const { | 90 | inline int Mod(int x) const; |
111 | if (!pillar) return x; | 91 | inline bool SafeCell(int x, int y) const; |
112 | return (x + width * height * 2) % width; | ||
113 | } | ||
114 | |||
115 | inline bool SafeCell(int x, int y) const { | ||
116 | if (x < 0 || x >= width) return false; | ||
117 | if (y < 0 || y >= height) return false; | ||
118 | return true; | ||
119 | } | ||
120 | }; | ||
121 | |||
122 | class PuzzleSerializer { | ||
123 | public: | ||
124 | PuzzleSerializer(const std::shared_ptr<Memory>& memory); | ||
125 | Puzzle ReadPuzzle(int id); | ||
126 | void WritePuzzle(const Puzzle& p, int id); | ||
127 | |||
128 | private: | ||
129 | // @Bug: Blue and orange are swapped? | ||
130 | enum Flags { | ||
131 | IS_ENDPOINT = 0x1, | ||
132 | IS_STARTPOINT = 0x2, | ||
133 | IS_FULL_GAP = 0x8, | ||
134 | HAS_DOT = 0x20, | ||
135 | DOT_IS_BLUE = 0x100, | ||
136 | DOT_IS_ORANGE = 0x200, | ||
137 | DOT_IS_INVISIBLE = 0x1000, | ||
138 | HAS_ONE_CONN = 0x100000, | ||
139 | HAS_VERTI_CONN = 0x200000, | ||
140 | HAS_HORIZ_CONN = 0x400000, | ||
141 | }; | ||
142 | |||
143 | void ReadIntersections(Puzzle& p, int id); | ||
144 | void ReadDecorations(Puzzle& p, int id); | ||
145 | void WriteIntersections(const Puzzle& p, int id); | ||
146 | void WriteDecorations(const Puzzle& p, int id); | ||
147 | |||
148 | std::tuple<int, int> loc_to_xy(const Puzzle& p, int location) const; | ||
149 | int xy_to_loc(const Puzzle& p, int x, int y) const; | ||
150 | // Decoration location | ||
151 | std::tuple<int, int> dloc_to_xy(const Puzzle& p, int location) const; | ||
152 | int xy_to_dloc(const Puzzle& p, int x, int y) const; | ||
153 | Cell::Dot FlagsToDot(int flags) const; | ||
154 | // Iterate connection lists for another location which is connected to us; return that other location. | ||
155 | int FindConnection(int i, const std::vector<int>& connections_a, const std::vector<int>& connections_b) const; | ||
156 | |||
157 | std::shared_ptr<Memory> _memory; | ||
158 | }; | 92 | }; |