diff --git a/Source/functions/solve/classExtension.cpp b/Source/functions/solve/classExtension.cpp index 329b243..4f5d1bd 100755 --- a/Source/functions/solve/classExtension.cpp +++ b/Source/functions/solve/classExtension.cpp @@ -34,26 +34,6 @@ void PuzzlePiece::randomCenterPiece() setConnections(getConnections() | 0b00000010); } -//tries all pieces in box from separator to end and places fitting into matrix. removes fitting piece -//use separator if you have to retract to a position -//seperator may be bigger than box size, if all puzzle pieces have already been looked at. -// it immediately retracts again then (returns -1) -unsigned int Puzzle::tryAllPieces(coor myCoor, vector& myBox, unsigned int separator) -{ - for(int i=separator; i::iterator i = Box.begin(); i != Box.end(); i++) + for (auto i:Box) { - (*i).printPiece(); + i.printPiece(); cout << ' '; } cout << endl; @@ -290,10 +270,10 @@ void randomBox::printBox() vector randomBox::shuffle() { random_shuffle(Box.begin(),Box.end()); - for (vector::iterator i = Box.begin(); i != Box.end(); i++) + for (auto &i:Box) { - i->shift(rand()%4); - i->resetShift(); + i.shift(rand()%4); + i.resetShift(); } numerateBox(Box); @@ -303,13 +283,6 @@ vector randomBox::shuffle() //creates a random box size m, n, shuffles it, and then retuns it vector createBox(coor myCoor) { - /* -<<<<<<< HEAD - randomBox myFirstPuzzleBox(myCoor.m, myCoor.n); - myFirstPuzzleBox.createRandomPuzzle(); - return myFirstPuzzleBox.shuffle(); -======= - */ randomBox myFirstPuzzleBox(myCoor.m,myCoor.n); myFirstPuzzleBox.createRandomAbstraction1(); myFirstPuzzleBox.createRandomAbstraction2(); @@ -317,20 +290,18 @@ vector createBox(coor myCoor) myFirstPuzzleBox.printPuzzle(); return myFirstPuzzleBox.shuffle(); -//>>>>>>> 9b282e83caf9aaacea107f878d2d6b3f413f286b } //prints contents of box void printBox(vector myBox) { cout << "current Box: " << endl; - for (vector::iterator i = myBox.begin(); i != myBox.end(); i++) + for (auto &i:myBox) { - (*i).printPiece(); + i.printPiece(); cout << ' '; } cout << endl; - return; } //gives every element in box a box identifier. @@ -339,16 +310,15 @@ void numerateBox(vector& myBox) for(int i = 0; i< myBox.size();i++) myBox[i].setBoxIdentifier(i); - return; } std::vector convertPart2PuzzlePiece(std::vector simplePartBox) { std::vector advancedPartBox; - for(int i=0;i& log, vector& p_Box, Puzzle& puzzleMat) //last log element is set, create new log element or log not yet started if(!(log.size()) || log.back().isSet()) { - if(!(p_Box.size())) return 0; //puzzle solved - else createNextLogElement(); + if(!(p_Box.size())) return false; //puzzle solved + else createNextLogElement(log,p_Box,puzzleMat); } //last log element is empty, backtrack else if(!(log.back().PieceCollector.size())) backtrack(log,p_Box,puzzleMat); @@ -33,15 +33,15 @@ bool next(vector& log, vector& p_Box, Puzzle& puzzleMat) else setsolution(log,p_Box,puzzleMat); } - else + else setsolution(log,p_Box,puzzleMat); } - return 1; + return true; } void createNextLogElement(vector& log, vector& p_Box, Puzzle& puzzleMat) { - log.push_back(LogEntry()); + log.emplace_back(LogEntry()); log.back().myCoor = calculateNextCoor(log, p_Box, puzzleMat); getLayerDestructionPowerfromSurrounding(); solve(log, p_Box,puzzleMat); @@ -54,7 +54,7 @@ coor calculateNextCoor(vector& log, vector& p_Box, Puzzl //go left to right, then increase current row if (log.size() == 1) - return coor(0,0); + return {0,0}; int m= log.rbegin()[1].myCoor.m; @@ -63,8 +63,8 @@ coor calculateNextCoor(vector& log, vector& p_Box, Puzzl if(m& log, vector& p_Box, Puzzle& puzzleMat void abstractionlayer0solver(vector& log, vector& p_Box, Puzzle& puzzleMat) { //throw all remaining puzzle pieces into newest log - for(int i=0;i& log, vector& p_Box, Puzzle& puzzleMat) @@ -152,7 +152,7 @@ bool backtrack(vector& log, vector& p_Box, Puzzle& puzzl puzzleMat.removePiece(log.back().myCoor); log.pop_back(); backtrack(log,p_Box,puzzleMat); - return 1; + return true; } //last log entry only one solution - delete last logd put back into box + backtrack @@ -167,20 +167,22 @@ bool backtrack(vector& log, vector& p_Box, Puzzle& puzzl if(puzzleMat.testRotationPiece(log.back().myCoor, *(log.back().PieceCollector[0]), 1)) { setsolution(log,p_Box,puzzleMat); - return 1; + return true; } } p_Box.push_back(log.back().PieceCollector[0]); //shuffleup - random_shuffle(p_Box.begin(),p_Box.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(p_Box.begin(),p_Box.end(),g); puzzleMat.removePiece(log.back().myCoor); log.pop_back(); //cout << "removed" << endl; //status(log,p_Box,puzzleMat); backtrack(log,p_Box,puzzleMat); - return 1; + return true; } //last log entry multiple solutions (and current one was randomed) - delete randomed piece and go to next @@ -196,13 +198,15 @@ bool backtrack(vector& log, vector& p_Box, Puzzle& puzzl if(puzzleMat.testRotationPiece(log.back().myCoor, *(log.back().PieceCollector[0]), 1)) { setsolution(log,p_Box,puzzleMat); - return 1; + return true; } } p_Box.push_back(log.back().PieceCollector[0]); //shuffleup - random_shuffle(p_Box.begin(),p_Box.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(p_Box.begin(),p_Box.end(),g); log.back().PieceCollector.erase(log.back().PieceCollector.begin()); if(log.back().PieceCollector.size()==1) @@ -212,11 +216,11 @@ bool backtrack(vector& log, vector& p_Box, Puzzle& puzzl (*(log.back().PieceCollector[0])).resetShift(); setsolution(log,p_Box,puzzleMat); - return 1; - //no need to remove from puzzle mat, as sersolution overwrites it anyway + return true; + //no need to remove from puzzle mat, as setsolution overwrites it anyway } else - return 0; + return false; } @@ -233,26 +237,26 @@ void status(vector& log, vector& p_Box, Puzzle& puzzleMa cout << "isset: 1" << endl; else cout << "isset: 0" << endl; - - //cout << "Abstraction: " << log[i].abstractionLevel << endl; cout << "m: " << log[i].myCoor.m << " n: " << log[i].myCoor.n << endl; - /*for(int j=0;j::iterator i = p_Box.begin();i!=p_Box.end();i++) + for(auto i:p_Box) { - (*(*i)).printPiece(); + i->printPiece(); cout << endl; } cout << "Puzzle:" << endl; puzzleMat.printPuzzle(); cout << "----------------------------" << endl; +} + +void calculateTrueDestructionPower(vector& log, Puzzle& puzzleMat, float Layerworth) +{ + //hier muss noch rein, wo die zeit der Abstractionlevels gespeichter wird + float destructionPower=sqrt(Layerworth * log.back().abstractionLevel); + puzzleMat.setdestructionPower(log.back().myCoor,log.back().abstractionLevel,destructionPower); } \ No newline at end of file diff --git a/Source/header.h b/Source/header.h index 49ba840..73c6149 100755 --- a/Source/header.h +++ b/Source/header.h @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include #define MAX_ABSTRAX 1 #define structdebug diff --git a/Source/header/solve.h b/Source/header/solve.h index 0b8e3ba..c0be2db 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -176,4 +176,4 @@ void abstractionlayer1solver(vector& log, vector& p_Box, void setsolution(vector& log, vector& p_Box, Puzzle& puzzleMat); bool backtrack(vector& log, vector& p_Box, Puzzle& puzzleMat); - +void createNextLogElement(vector& log, vector& p_Box, Puzzle& puzzleMat); \ No newline at end of file diff --git a/Source/main.cpp b/Source/main.cpp index ae94bb3..79ebb39 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -7,7 +7,7 @@ unsigned int PuzzlePiece::idcount(0); int main() { - int cols=2, rows=3; + unsigned int cols=2, rows=3; //some basic random puzzle stuff vector myFirstBox = createBox(coor(cols,rows)); @@ -18,12 +18,13 @@ int main() //BoxClassify myFirstBox(); cout << endl; - for(int i=0;i> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat); - while(next(log, p_myFirstBox,puzzleMat)); + //while(next(log, p_myFirstBox,puzzleMat)); puzzleMat.printPuzzle(); }