-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoproblemsolvethread.cpp
81 lines (74 loc) · 2.42 KB
/
autoproblemsolvethread.cpp
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
#include "autoproblemsolvethread.h"
AutoProblemSolveThread::AutoProblemSolveThread()
{
}
AutoProblemSolveThread::AutoProblemSolveThread(int** gameMap_0,int rowSize,int columnSize,bool showProgress,int sleepTime)
{
stopped=false;
this->gameMap=gameMap_0;
this->showProgress=showProgress;
this->sleepTime=sleepTime;
this->rowSize=rowSize;
this->columnSize=columnSize;
}
void AutoProblemSolveThread::stop(){
stopped=true;
}
void AutoProblemSolveThread::run(){
// for(int i=0;i<rowSize;i++){
// for(int j=0;j<columnSize;j++){
// cout<<gameMap[i][j]<<" ";
// }
// cout<<endl;
// }
while(!allCleared(gameMap,rowSize,columnSize)){
if(stopped) break;
bool hasSollution=false;
for(int i=1;i<=rowSize-2;i++){
if(stopped) break;
for(int j=1;j<=columnSize-2;j++){
if(stopped) break;
if(gameMap[i][j]!=0){
for (int m=1;m<=rowSize-2;m++) {
if(stopped) break;
for(int n=1;n<=columnSize-2;n++){
if(stopped) break;
if(gameMap[m][n]!=0&&gameMap[i][j]==gameMap[m][n]){
QList<Vertex> *list=new QList<Vertex>();
int turnNum = map.canLink_2(gameMap,i,j,m,n,*list);
if(!stopped&&turnNum!=-1){
hasSollution=true;
Sleep(sleepTime);
gameMap[i][j]=0;
gameMap[m][n]=0;
emit drawPathLine(i,j,m,n,list);
Sleep(300);
emit hideButton(i,j,m,n);
}
}
}
}
}
}
}
if(!hasSollution) {
// cout<<"ÎÞ½â AutoProblemSolveThread"<<endl;
break;
}
if(!showProgress){
break;
}
}
emit autoSolveFinish();
stopped=false;
}
bool AutoProblemSolveThread::allCleared(int** gameMap,int rowSize,int columnSize)
{
for(int i=1;i<rowSize-1;i++){
for(int j=1;j<columnSize-1;j++){
if(gameMap[i][j] != 0)
return false;
}
}
return true;
}