fixed backtrack bug in logslasher function

This commit is contained in:
Raphael Maenle 2018-01-20 22:31:56 +01:00
parent bc1a7eb6b5
commit cefa63da54
2 changed files with 27 additions and 32 deletions

View File

@ -140,7 +140,7 @@ bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
//if more pieces possible, tset piece as not logged
if((log.back().PieceCollector.size())>1)
{
cout << " next piece" << endl;
//unset puzzlepieces
int count =0;
for(int i=0;i<puzzleMat.p_myBox.size();i++)
{
@ -150,26 +150,23 @@ bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
count++;
}
}
cout << "removed " << count << endl;
if (count !=4)
cerr << "incorrect set set" << endl;
//remove similar in log
Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part
log.back().PieceCollector.erase(log.back().PieceCollector.begin());//removes bad part from log
puzzleMat.removeSimilar(log.back().PieceCollector,myPart); //removes all pieces from log that are similar to bad part
//TODO remove this when further layers are added!!!
if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement
{
cout << " next piece" << endl;
if(log.back().PieceCollector.size()==1)
log.back().decreaseRandomed();
setsolution(log,puzzleMat);
return true;
}
}
//else remove log element and backtrack once more
else
{
puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers
int count =0;
if((log.back().PieceCollector.size()))
@ -182,8 +179,7 @@ bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
count++;
}
}
if (count !=4)
cerr << "incorrect set set" << endl;
cout << "removed " << count << endl;
}
cout << " no more pieces" << endl;
@ -192,7 +188,6 @@ bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
return false;
return true;
}
}
//this is addon stuff that should later all be extracted into a sererate cpp as it is not core dispatcher functionality

View File

@ -15,14 +15,14 @@ int main()
return 0;
}
puzzleMat.createRandomBox();
//puzzleMat.createRandomBox();
cout << "Solving Puzzle now...";
while(next(log, puzzleMat));
cout << "Done!" << endl;
//puzzleMat.resultImage(log);
puzzleMat.resultImage(log);
puzzleMat.printPuzzle();