From 3567b77cec2df0660ae7d86000f83b7196af13fe Mon Sep 17 00:00:00 2001 From: Date: Wed, 22 Nov 2017 16:06:23 +0100 Subject: [PATCH] added basic construct to keep on turning puzzle piece. non functional as of yet. --- Source/functions/solve/classExtension.cpp | 4 +- Source/functions/solve/structure.cpp | 62 +++++++++++++++-------- Source/header/solve.h | 5 +- Source/main.cpp | 4 +- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/Source/functions/solve/classExtension.cpp b/Source/functions/solve/classExtension.cpp index e54388b..fa96423 100644 --- a/Source/functions/solve/classExtension.cpp +++ b/Source/functions/solve/classExtension.cpp @@ -53,9 +53,9 @@ unsigned int Puzzle::tryAllPieces(unsigned int m, unsigned int n, vector& log, vector& p_Box, //remove all that do not fit according to abstraction layer 0 for(int i=0;i<(log.back().PieceCollector.size());) { + (*(log.back().PieceCollector[i])).resetShift(); //TODO: change checker from checking every box piece to only checking the simplifyed version ob the box with abstraction layer one if(!(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[i])))) { @@ -200,33 +201,52 @@ bool backtrack(vector& log, vector& p_Box, Puzzle& puzzl //delete last logd put back into box + backtrack else if((log.back().PieceCollector.size())==1) { - //cout << "one" << endl; - p_Box.push_back(log.back().PieceCollector[0]); - //shuffleup - random_shuffle(p_Box.begin(),p_Box.end()); - puzzleMat.removePiece(log.back().myCoor.m, log.back().myCoor.n); - log.pop_back(); - //cout << "removed" << endl; - //status(log,p_Box,puzzleMat); - backtrack(log,p_Box,puzzleMat); + (*(log.back().PieceCollector[0])).shift(1); + if(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[0]), 4-(*(log.back().PieceCollector[0])).getShift())) + setsolution(log,p_Box,puzzleMat); + else + { + //cout << "one" << endl; + p_Box.push_back(log.back().PieceCollector[0]); + //shuffleup + random_shuffle(p_Box.begin(),p_Box.end()); + puzzleMat.removePiece(log.back().myCoor.m, log.back().myCoor.n); + log.pop_back(); + //cout << "removed" << endl; + //status(log,p_Box,puzzleMat); + backtrack(log,p_Box,puzzleMat); + } return 1; } //last log entry multiple solutions (and current one was randomed) //delete randomed piece from PieceCollector and go to next (which might random again depending on function) else if((log.back().PieceCollector.size())>1) { - //cout << "multiple" << endl; - p_Box.push_back(log.back().PieceCollector[0]); - //shuffleup - random_shuffle(p_Box.begin(),p_Box.end()); - log.back().PieceCollector.erase(log.back().PieceCollector.begin()); - - if(log.back().PieceCollector.size()==1) - log.back().decreaseRandomed(); - - //cout << "erased first element" << endl; - //status(log,p_Box,puzzleMat); - setsolution(log,p_Box,puzzleMat); + + //check if piece has second rotation solution + (*(log.back().PieceCollector[0])).shift(1); + if(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[0]), 4-(*(log.back().PieceCollector[0])).getShift())) + setsolution(log,p_Box,puzzleMat); + else + { + + //cout << "multiple" << endl; + p_Box.push_back(log.back().PieceCollector[0]); + //shuffleup + random_shuffle(p_Box.begin(),p_Box.end()); + log.back().PieceCollector.erase(log.back().PieceCollector.begin()); + + if(log.back().PieceCollector.size()==1) + log.back().decreaseRandomed(); + + //for abstraction layer 1 so that first rotation solution is set. + (*(log.back().PieceCollector[0])).resetShift(); + //cout << "erased first element" << endl; + //status(log,p_Box,puzzleMat); + setsolution(log,p_Box,puzzleMat); + + } + return 1; //no need to remove from puzzle mat, as sersolution overwrites it anyway } diff --git a/Source/header/solve.h b/Source/header/solve.h index a1c7b99..bd7aa16 100644 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -22,7 +22,8 @@ public: break; } } - + unsigned int getShift(){return shifts;} + void resetShift(){shifts=0;} void shift(unsigned int moves); void randomCenterPiece(); void printPiece() { cout << bitset (getConnections()); } @@ -94,7 +95,7 @@ public: bool PlaceOfPartGood(unsigned int m, unsigned int n, PuzzlePiece& myPart); bool PlaceOfPart2Good(unsigned int m,unsigned int n, PuzzlePiece& myPart); - bool testRotationPiece(unsigned int m, unsigned int n, PuzzlePiece& myPart); + bool testRotationPiece(unsigned int m, unsigned int n, PuzzlePiece& myPart, int nrOfRotations=4); unsigned int tryAllPieces(unsigned int m, unsigned int n, vector& myBox, unsigned int separator); unsigned int putBackIntoBox(unsigned int m, unsigned int n, vector& myBox); diff --git a/Source/main.cpp b/Source/main.cpp index 256eff3..b73b022 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -9,7 +9,7 @@ int main() { - int cols=40, rows=40; + int cols=10, rows=10; //some basic part stuff vector myFirstPuzzle; Part myFirstPart; @@ -24,7 +24,7 @@ int main() //undo everything and make this puzzle fucking imba hard!!! //need 40x40 for this, so check your status - makehard4040puzzle(myFirstBox); + //makehard4040puzzle(myFirstBox); //some advanced solver stuff vector log;