-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.h
45 lines (31 loc) · 854 Bytes
/
field.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
#ifndef FIELD_H
#define FIELD_H
#include <QAbstractListModel>
#include <vector>
class Field : public QAbstractListModel
{
Q_OBJECT
public:
explicit Field(QObject *parent = nullptr);
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Q_INVOKABLE void shuffle();
Q_INVOKABLE void move(const int index);
Q_SIGNALS:
void showWinMsg() const;
void closeWinMsg() const;
public:
using Cell = int;
private:
const size_t field_size;
size_t blank_pos { 0 };
std::vector<Cell> cells;
private:
void addCells();
bool isSolvable() const;
bool isSolved() const;
size_t getInvertionsCount() const;
size_t findBlankRow() const;
};
#endif // FIELD_H