-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNaive.cpp
90 lines (79 loc) · 2.65 KB
/
Naive.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
#include "SetUp.h"
using namespace std;
bool Soduko::StartGuessing(list<Matrix>& listOfMatrices)
{
list<Matrix>::iterator itr;
list<Matrix>::iterator start = listOfMatrices.begin();
Matrix temp, try1;
int x=0;
bool done = false, real = true;
for(int row=0; row<9; row++)
{
for(int col=0; col<9; col++)
{
x = ReturnCurrentX(row, col);
if(listOfValues[x].realValue == 0)
{
for(itr = start; itr != listOfMatrices.end(); itr++)
{
CopyMatrix(temp, *itr);
UpDate(temp);
//FindEasyStates(temp);
//UpDate(temp);
for(int counter =0; counter < listOfValues[x].values.size(); counter++)
{
listOfValues[x].realValue = listOfValues[x].values[counter];
temp.setSpecific(row, col, 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;
}
if(x == 80)
return true;
//same = false;
}
}
//closeList.clear();
return false;
}
bool Soduko::NaiveControl(list<Matrix>& listOfMatrices)
{
bool done = true;
ofstream outFile;
outFile.open("NaiveSolution.txt");
outFile << "Original Puzzle" << endl;
outFile << "------------------------" << endl;
listOfMatrices.front().getMatrix(outFile);
outFile << endl;
for(list<Matrix>::iterator itr = listOfMatrices.begin(); itr != listOfMatrices.end(); itr++)
{
UpDate(*itr);
FindEasyStates(*itr);
done = CheckIfEnd(*itr);
UpDate(*itr);
}
StartGuessing(listOfMatrices);
list<Matrix>::iterator itr = listOfMatrices.end();
itr--;
done = CheckIfEnd(*itr);
if(done == true)
{
outFile << "\nSolved Puzzle" << endl;
outFile << "------------------------" << endl;
itr->getMatrix(outFile);
outFile.close();
listOfMatrices.clear();
cout << "The Naive Solver has found a solution. Please look in the NaiveSolution.txt file" << endl;
return true;
}
return false;
}