blob: f0664c7b0a9fefff5f26331d980f885c8757f468 (
plain) (
blame)
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
|
#include "pch.h"
#include "Puzzle.h"
Cell Puzzle::GetCell(int x, int y) const {
x = Mod(x);
if (!SafeCell(x, y)) return Cell::Undefined();
return grid[x][y];
}
Cell::Color Puzzle::GetLine(int x, int y) const {
return grid[x][y].color;
}
void Puzzle::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<width; x++) grid[x].resize(height);
}
Pos Puzzle::GetSymmetricalPos(int x, int y) const {
if (symmetry != Symmetry::NONE) {
if (pillar) {
x += width/2;
if (symmetry & Symmetry::X) {
x = width - x;
}
} else {
if (symmetry & Symmetry::X) {
x = (width-1) - x;
}
}
if (symmetry & Symmetry::Y) {
y = (height-1) - y;
}
}
return Pos{x, y};
}
int Puzzle::Mod(int x) const {
if (!pillar) return x;
return (x + width * height * 2) % width;
}
bool Puzzle::SafeCell(int x, int y) const {
if (x < 0 || x >= width) return false;
if (y < 0 || y >= height) return false;
return true;
}
|