-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchthread.h
394 lines (350 loc) · 15 KB
/
searchthread.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#ifndef SEARCHTHREAD_H
#define SEARCHTHREAD_H
#include <QThread>
#include "algorithm.h"
using namespace grcube3;
class RunSearch : public QObject
{
Q_OBJECT
public:
RunSearch() : QObject()
{
FinishingThread = false;
CurrentSearchMaxDepthPointer = nullptr;
moveToThread(&t);
t.start();
}
~RunSearch()
{
FinishingThread = true;
Skip();
t.quit();
t.wait();
}
void Skip() { if (CurrentSearchMaxDepthPointer != nullptr) *CurrentSearchMaxDepthPointer = 0u; }
// Layer by layer search
void doStartSearchLBL(const QString Scramble, const int CrossLayerIndex, const int NumCores, const int MetricIndex)
{
QMetaObject::invokeMethod(this, "startSearchLBL",
Q_ARG(QString, Scramble),
Q_ARG(int, CrossLayerIndex),
Q_ARG(int, NumCores),
Q_ARG(int, MetricIndex));
}
// CFOP search
void doStartSearchCFOP(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchCFOP",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// Roux search
void doStartSearchRoux(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchRoux",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// Petrus search
void doStartSearchPetrus(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchPetrus",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// ZZ search
void doStartSearchZZ(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchZZ",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// CEOR search
void doStartSearchCEOR(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchCEOR",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// Mehta search
void doStartSearchMehta(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchMehta",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// Nautilus search
void doStartSearchNautilus(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchNautilus",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// LEOR search
void doStartSearchLEOR(const QString Scramble,
const int NumCores,
const bool CacheEnabled,
const int VariantIndex,
const int OptionIndex,
const int SpeedIndex,
const int OrientIndex,
const int AmountIndex,
const int MetricIndex,
const bool RegripsEnabled,
const bool CancellationsEnabled)
{
int BitConfig = 0;
if (CacheEnabled) BitConfig += 1;
if (RegripsEnabled) BitConfig += 2;
if (CancellationsEnabled) BitConfig += 4;
QMetaObject::invokeMethod(this, "startSearchLEOR",
Q_ARG(QString, Scramble),
Q_ARG(int, NumCores),
Q_ARG(int, BitConfig),
Q_ARG(int, VariantIndex),
Q_ARG(int, OptionIndex),
Q_ARG(int, SpeedIndex),
Q_ARG(int, OrientIndex),
Q_ARG(int, AmountIndex),
Q_ARG(int, MetricIndex));
}
// static functions
static uint GetSearchSpins(std::vector<grcube3::Spn>&, const int);
static uint GetCrossLayers(std::vector<Lyr>&, int);
public slots:
void startSearchLBL(const QString, const int, const int, const int);
void startSearchCFOP(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchRoux(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchPetrus(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchZZ(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchCEOR(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchMehta(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchNautilus(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
void startSearchLEOR(const QString, const int, const int, const int, const int, const int, const int, const int, const int);
signals:
void msgLBLStartCross();
void msgLBLStartFL();
void msgLBLStartSL();
void msgLBLStartLL();
void finishLBL_Solves(const QString, const QString, const QString); // Scramble, Cross layer, Solve
void finishLBL_NoSolves();
void finishMethod_Solves(const QString, const QString); // Scramble, Solves
void finishMethod_Best(const QString); // Best solve
void finishMethod_Time(const QString);
void finishMethod_NoSolves();
void msgCFOPStartCross();
void msgCFOPStartF2L();
void msgCFOPStartLL();
void msgRouxStartFB();
void msgRouxStartSB();
void msgRouxStartCMLL();
void msgRouxStartCOLL();
void msgRouxStartL6E();
void msgPetrusStartFB();
void msgPetrusStartEB();
void msgPetrusStartEO();
void msgPetrusStartF2L();
void msgPetrusStartLL();
void msgZZStartEOX();
void msgZZStartF2L();
void msgZZStartLL();
void msgCEORStartLines();
void msgCEORStartCP();
void msgCEORStartCPLines();
void msgCEORStartpEO();
void msgCEORStartEOBF();
void msgCEORStartF2L();
void msgCEORStartLL();
void msgMehtaStartFB();
void msgMehtaStart3QB();
void msgMehtaStartEOLE();
void msgMehtaStart6CO();
void msgMehtaStart6CP();
void msgMehtaStartL5EP();
void msgMehtaStartAPDR();
void msgMehtaStartPLL();
void msgMehtaStartDCAL();
void msgMehtaStartCDRLL();
void msgMehtaStartJTLE();
void msgMehtaStartTDR();
void msgMehtaStartZBLL();
void msgNautilusStartFB();
void msgNautilusStartSB();
void msgNautilusStartdFR();
void msgNautilusStartNCLL();
void msgNautilusStartNCOLL();
void msgNautilusStartTNCLL();
void msgNautilusStartL5E();
void msgNautilusStartEODF();
void msgNautilusStartF2L();
void msgNautilusStartLL();
void msgLEORStartFB();
void msgLEORStartEOStripe();
void msgLEORStartFLPair();
void msgLEORStartEODF();
void msgLEORStartSB();
void msgLEORStartLL();
void msgCache();
private:
QThread t;
uint* CurrentSearchMaxDepthPointer;
bool FinishingThread;
// Information to store about a solve search for the cache
struct CacheUnit
{
Algorithm Scramble;
uint Depth;
double Time;
std::vector<Algorithm> Solves;
void Reset() { Scramble.Clear(); Depth = 0u; Time = 0.0; Solves.clear(); }
};
std::vector<CacheUnit> Cache; // Solves cache
};
#endif // SEARCHTHREAD_H