Merge branch 'master' into Layer_PoempelPosition
This commit is contained in:
@ -168,14 +168,14 @@ Mat Puzzle::resultImage( vector<LogEntry>& log){
|
||||
char name[100];
|
||||
for (auto it:log)
|
||||
{
|
||||
if (it.myCoor.col == 12 && it.myCoor.row == 0)
|
||||
if (it.myCoor.col == 27 && it.myCoor.row == 5)
|
||||
{
|
||||
;
|
||||
// imshow("result",result);
|
||||
// waitKey(0);
|
||||
}
|
||||
|
||||
cout << it.PieceCollector[0].second->GetPartID() << endl;
|
||||
//cout << it.PieceCollector[0].second->GetPartID() << endl;
|
||||
|
||||
int imageNumber = it.PieceCollector[0].second->GetPartID();
|
||||
//cout<<"imageIndex: "<< imageNumber << endl;
|
||||
@ -186,7 +186,8 @@ Mat Puzzle::resultImage( vector<LogEntry>& log){
|
||||
copyMakeBorder(img,img,200,200,200,200,BORDER_CONSTANT,Scalar(255,255,255));
|
||||
Mat invert = Mat::ones(img.size(), CV_8UC3); // invert for rotation to work correctly
|
||||
bitwise_not ( img, invert );
|
||||
if (it.myCoor.col == 12 && it.myCoor.row == 0)
|
||||
|
||||
if (it.myCoor.col == 35 && it.myCoor.row == 5)
|
||||
{
|
||||
//imshow("img",img);
|
||||
//waitKey(0);
|
||||
|
@ -44,7 +44,6 @@ void createNextLogElement(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
log.emplace_back(LogEntry(coor(0, 0)));
|
||||
log.back().myCoor = calculateNextCoor(log, puzzleMat);
|
||||
puzzleMat.dp.DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding
|
||||
cout << "-----------------------" << endl;
|
||||
//get all not set pieces
|
||||
for(auto it:puzzleMat.p_myBox)
|
||||
if(!it->set)
|
||||
@ -110,16 +109,13 @@ void setsolution(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
//tell log entry that it is set
|
||||
log.back().Set();
|
||||
puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second);
|
||||
cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl;
|
||||
cout << "ID: " << log.back().PieceCollector[0].second->GetPartID() << endl;
|
||||
cout << "log:" << endl;
|
||||
for(auto it:log.back().PieceCollector)
|
||||
cout << std::bitset<8>(it.second->m_a1.getConnections()) << "|" << it.second->GetPartID() << endl;
|
||||
//cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl;
|
||||
//cout << "ID: " << log.back().PieceCollector[0].second->GetPartID() << endl;
|
||||
|
||||
}
|
||||
|
||||
bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
{
|
||||
cout << "backtracking" ;
|
||||
if(log.empty())
|
||||
{
|
||||
cout << "Puzzle not solveable!" << endl;
|
||||
@ -129,38 +125,35 @@ 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;
|
||||
for(int i=0;i<puzzleMat.p_myBox.size();i++)
|
||||
for(int i=0;i<puzzleMat.p_myBox.size();i++)//unset puzzlepieces
|
||||
if(puzzleMat.p_myBox[i]->GetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid
|
||||
puzzleMat.p_myBox[i]->set=false;
|
||||
|
||||
|
||||
//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()==1)
|
||||
log.back().decreaseRandomed();
|
||||
|
||||
setsolution(log,puzzleMat);
|
||||
|
||||
return true;
|
||||
if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement
|
||||
{
|
||||
if(log.back().PieceCollector.size()==1)
|
||||
log.back().decreaseRandomed();
|
||||
setsolution(log,puzzleMat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//else remove log element and backtrack once more
|
||||
else
|
||||
{
|
||||
cout << " no more pieces" << endl;
|
||||
puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers
|
||||
if((log.back().PieceCollector.size()))
|
||||
for(int i=0;i<puzzleMat.p_myBox.size();i++)
|
||||
if(puzzleMat.p_myBox[i]->GetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid
|
||||
puzzleMat.p_myBox[i]->set=false;
|
||||
log.pop_back();
|
||||
if(!backtrack(log,puzzleMat))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers
|
||||
if((log.back().PieceCollector.size())) //unset all
|
||||
for(int i=0;i<puzzleMat.p_myBox.size();i++)
|
||||
if(puzzleMat.p_myBox[i]->GetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid
|
||||
puzzleMat.p_myBox[i]->set=false;
|
||||
|
||||
log.pop_back();
|
||||
if(!backtrack(log,puzzleMat))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user