/
grid.h
58 lines (44 loc) · 1.26 KB
/
grid.h
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
#ifndef GRID_H
#define GRID_H
#include <QFile>
#include <QTextStream>
#include <QStringList>
#include <QSet>
#include <QHash>
#include <QQueue>
#include <QStack>
#include <stdexcept>
#include "cell.h"
#include "exception.h"
#include "logger.h"
#include "historyframe.h"
class Grid
{
public:
Grid(int size);
~Grid();
static Grid* parse(const QString filename);
static const QString alphabet(int base);
int size() const;
Cell* cellAt(int row, int column) const;
QSet<char> fullDomain() const;
const QString alphabet() const;
Cell* getSafestCell() const;
QQueue<char> getSafestValues(Cell* target);
QHash<Cell*, QSet<char> > fixArcConsistency(Cell* dirtyCell = nullptr);
void unfixArcConsistency( QHash<Cell*, QSet<char> > diff );
QHash<Cell*, QSet<char> > broadenDomains(Cell* unsetCell);
QList<Cell *> solve(bool guess = false);
HistoryFrame* undo(Cell *rewindTarget = nullptr);
bool setCellAndUpdate(Cell* cell, char newValue, QQueue<char> otherOptions = QQueue<char>());
bool setCellAndUpdate(HistoryFrame* frame);
QSet<Cell*> unwindHistorySince(HistoryFrame* frame = nullptr);
private:
int _size;
QList<Cell*> cells;
QList<QList<Cell*> > rows;
QList<QList<Cell*> > columns;
QList<QList<Cell*> > blocks;
QStack<HistoryFrame*> history;
};
#endif // GRID_H