about summary refs log tree commit diff stats
path: root/Source/Puzzle.cpp
blob: d0ede27448ad2d78b9602864c03fbbf3c1ea3317 (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
#include "Puzzle.h"
#include "Memory.h"
#include <cassert>

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);
}

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;
}