-
Notifications
You must be signed in to change notification settings - Fork 2
/
sokogenerator.h
129 lines (106 loc) · 3.86 KB
/
sokogenerator.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef SOKOGENERATOR_H
#define SOKOGENERATOR_H
#include <QObject>
#include <QThread>
#include <QString>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <tuple>
#include <chrono>
#include <random>
#include "solvercpp/solver.h"
class DifficultyAnalyser;
using namespace std;
#define WALL '#'
#define FLOOR ' '
#define GOAL '.'
#define BOX '$'
#define BOXONGOAL '*'
#define PLAYER '@'
#define PONGOAL '+'
#define DEADFIELD 'x'
class SokoGenerator : public QObject{
Q_OBJECT
typedef vector<vector<char>> TwoDVector_char;
typedef vector<vector<int>> TwoDVector_int;
typedef unsigned long long ull;
public:
struct Level {
TwoDVector_char grid;
string solution;
int generationTime;
QString difficulty;
};
explicit SokoGenerator(QObject *parent = 0);
~SokoGenerator();
Solver solver;
DifficultyAnalyser* diffAnalyser;
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution;
void setupForThread(QThread &thread);
void initialSetup();
void setRoomWidth(int value){ roomWidth = value; }
void setRoomHeight(int value){ roomHeight = value; }
void setBoxes(int value){ noOfBoxes = value; }
void setLevels(int value){ noOfLevels = value; }
void setDifficulty(int value){ difficulty = value; }
void setPercentage(int value){ percentage = value; }
void setTimeout(float timeLimit){ timeout = timeLimit; }
void setRegenerate(bool value, int lvlNum) { regenLevel = value; regenLvlNum = lvlNum; }
void setGenerateSeed(int seed){ genSeed = seed; }
void updatePercentage(float value){ emit changeProgressBar(value); }
void listLevelSet(std::vector<Level>){ for(size_t i = 0; i < levels.size(); i++){ emit addToList(i + 1); } }
void generateLevel();
void generateLevel(int roomWidth, int roomHeight, int noOfBoxes, int difficulty);
void clearVectors(){ levels.clear(); }
void regenerateLevel(int lvlNum);
ull randomNumber(ull min, ull max, int divisor = 1);
void initLevel(Level &level, int roomWidth, int roomHeight);
void placePatterns(SokoGenerator::Level &level, int roomWidth, int roomHeight);
void rotatePattern(TwoDVector_char &pattern, int rotation);
bool checkConnectivity(SokoGenerator::Level &level, int roomWidth, int roomHeight, int noOfBoxes);
bool placeGoalsAndBoxes(SokoGenerator::Level &level, int roomWidth, int roomHeight, int noOfBoxes);
bool placePlayer(SokoGenerator::Level &level, int roomWidth, int roomHeight);
TwoDVector_char getLevel(int level) { return levels[level].grid; }
vector<Level> getLevels() { return levels; }
int getGenSeed(){ return genSeed; }
void floodfill(TwoDVector_int &level, int row, int column, int roomWidth, int roomHeigh);
int neighbourCheck(SokoGenerator::Level &level, int yCoord, int xCoord);
level LevelToCLevel(SokoGenerator::Level lvl);
string cSolToString(struct solution sol);
Level calcDeadFields(SokoGenerator::Level level);
void printLevel(SokoGenerator::Level level);
void deleteLevel(int lvlNum){ levels.erase(levels.begin() + lvlNum); }
bool isTimeout(clock_t start, float timeout);
private:
int roomWidth;
int roomHeight;
int noOfBoxes;
int noOfLevels;
int difficulty;
int percentage;
int genSeed;
float timeout;
bool regenLevel = false;
int regenLvlNum = 0;
QString difficulties[6] = { "None", "Very Easy", "Easy", "Medium", "Hard", "Very Hard" };
std::vector<Level> levels;
std::vector<Level> patterns;
public:
bool stopThread = 0;
signals:
void changeProgressBar(float);
void addToList(int);
void updateTimer();
void threadFinished();
void regenFinished(int);
void resetGUI();
void displayGenSeed();
private slots:
void startThreadWork();
};
#endif // SOKOGENERATOR_H