about summary refs log tree commit diff stats
path: root/Source/Puzzle.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Puzzle.h')
-rw-r--r--Source/Puzzle.h76
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 {
62struct Negation {}; 62struct Negation {};
63struct Pos {int x; int y;}; 63struct Pos {int x; int y;};
64 64
65#include <cassert> // TODO: Move this + impl to cpp
66class Puzzle { 65class Puzzle {
67public: 66public:
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
109private: 89private:
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
122class PuzzleSerializer {
123public:
124 PuzzleSerializer(const std::shared_ptr<Memory>& memory);
125 Puzzle ReadPuzzle(int id);
126 void WritePuzzle(const Puzzle& p, int id);
127
128private:
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};