-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart.cpp
112 lines (93 loc) · 2.93 KB
/
Smart.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
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
#include "SetUp.h"
using namespace std;
bool Soduko::SortArray()
{
blockValues temp;
for(int x=0; x<81; x++)
{
for(int y=0; y<81; y++)
{
if(x!=y)
{
if(listOfValues[x].values.size() > listOfValues[y].values.size())
{
CopyBlockValues(temp, listOfValues[x]);
CopyBlockValues(listOfValues[x], listOfValues[y]);
CopyBlockValues(listOfValues[y], temp);
}
}
}
}
return true;
}
bool Soduko::SmartGuessing(list<Matrix>& listOfMatrices)
{
list<Matrix>::iterator itr;
list<Matrix>::iterator start = listOfMatrices.begin();
Matrix temp, try1;
int x=0;
bool done = false, real = true;
while(x<81)
{
//x = ReturnCurrentX(row, col);
if(listOfValues[x].realValue == 0)
{
for(itr = start; itr != listOfMatrices.end(); itr++)
{
CopyMatrix(temp, *itr);
UpDate(temp);
//SortArray();
//FindEasyStates(temp);
//UpDate(temp);
for(int counter =0; counter < listOfValues[x].values.size(); counter++)
{
listOfValues[x].realValue = listOfValues[x].values[counter];
temp.setSpecific(listOfValues[x].idx, listOfValues[x].idy, listOfValues[x].realValue);
real = CheckIfReal(temp, x);
done = CheckIfEnd(temp);
if(real == true)
{
listOfMatrices.push_back(temp);
start = itr;
if(done == true)
return true;
}
}
}
//flag = false;
}
x++;
}
//closeList.clear();
return false;
}
bool Soduko::SmartControl(list<Matrix>& listOfMatrices)
{
bool done = false;
ofstream outFile;
outFile.open("SmartSolution.txt");
outFile << "Original Puzzle" << endl;
outFile << "------------------------" << endl;
listOfMatrices.front().getMatrix(outFile);
outFile << endl;
UpDate(listOfMatrices.front());
FindEasyStates(listOfMatrices.front());
SortArray();
SmartGuessing(listOfMatrices);
list<Matrix>::iterator itr = listOfMatrices.end();
itr--;
//itr->getMatrix();
done = CheckIfEnd(*itr);
if(done == true)
{
outFile << "\nSolved Puzzle" << endl;
outFile << "------------------------" << endl;
itr->getMatrix(outFile);
outFile.close();
listOfMatrices.clear();
cout << "The Smart Solver has found a solution. Please look in the SmartSolution.txt file" << endl;
return true;
}
//getBlock();
return false;
}