1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#pragma once
#include <memory>
#include <unordered_map>
#include "Puzzle.h"
class Memory;
class PuzzleSerializer {
public:
PuzzleSerializer(const std::shared_ptr<Memory>& 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,
HAS_NO_CONN = 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);
void ReadExtras(Puzzle& p);
void ReadDecorations(Puzzle& p, int id);
void ReadSequence(Puzzle& p, int id);
void ReadSymmetry(Puzzle& p, int id);
void WriteIntersections(const Puzzle& p);
void WriteDots(const Puzzle& p);
void WriteGaps(const Puzzle& p);
void WriteEndpoints(const Puzzle& p);
void WriteDecorations(const Puzzle& p, int id);
void WriteSequence(const Puzzle& p, int id);
void WriteSymmetry(const Puzzle& p, int id);
std::tuple<int, int> loc_to_xy(const Puzzle& p, int location) const;
int xy_to_loc(const Puzzle& p, int x, int y) const;
int extra_xy_to_loc(const Puzzle& p, int x, int y) const;
// Decoration location
std::tuple<int, int> dloc_to_xy(const Puzzle& p, int location) const;
int xy_to_dloc(const Puzzle& p, int x, int y) const;
// Grid coordinates
std::tuple<float, float> xy_to_pos(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 location) const;
void AddIntersection(const Puzzle& p, int x, int y, float xPos, float yPos, int flags);
std::shared_ptr<Memory> _memory;
int _numGridLocations;
int _numIntersections;
std::vector<int> _intersectionFlags;
std::vector<int> _connectionsA;
std::vector<int> _connectionsB;
std::vector<float> _intersectionLocations;
// Locations of non-grid points, i.e. dots, gaps, and endpoints
std::unordered_map<int, int> _extraLocations;
float MIN, MAX, INTERVAL;
int X_OFF, Y_OFF;
};
|