added basic construct to keep on turning puzzle piece. non functional as of yet.

This commit is contained in:
2017-11-22 16:06:23 +01:00
parent 6c81722d02
commit 3567b77cec
4 changed files with 48 additions and 27 deletions

View File

@ -53,9 +53,9 @@ unsigned int Puzzle::tryAllPieces(unsigned int m, unsigned int n, vector<PuzzleP
} }
//tests the myPart in all 4 rotations at position m, n //tests the myPart in all 4 rotations at position m, n
bool Puzzle::testRotationPiece(unsigned int m, unsigned int n, PuzzlePiece& myPart) bool Puzzle::testRotationPiece(unsigned int m, unsigned int n, PuzzlePiece& myPart, int nrOfRotations)
{ {
for(int rotation=0; rotation < 4; rotation++) for(int rotation=0; rotation < nrOfRotations; rotation++)
{ {
if(PlaceOfPartGood(m,n,myPart)) if(PlaceOfPartGood(m,n,myPart))
return 1; return 1;

View File

@ -143,6 +143,7 @@ void abstractionlayer1solver(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box,
//remove all that do not fit according to abstraction layer 0 //remove all that do not fit according to abstraction layer 0
for(int i=0;i<(log.back().PieceCollector.size());) 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 //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])))) if(!(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[i]))))
{ {
@ -199,6 +200,11 @@ bool backtrack(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzl
//last log entry only one solution //last log entry only one solution
//delete last logd put back into box + backtrack //delete last logd put back into box + backtrack
else if((log.back().PieceCollector.size())==1) else if((log.back().PieceCollector.size())==1)
{
(*(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; //cout << "one" << endl;
p_Box.push_back(log.back().PieceCollector[0]); p_Box.push_back(log.back().PieceCollector[0]);
@ -209,12 +215,21 @@ bool backtrack(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzl
//cout << "removed" << endl; //cout << "removed" << endl;
//status(log,p_Box,puzzleMat); //status(log,p_Box,puzzleMat);
backtrack(log,p_Box,puzzleMat); backtrack(log,p_Box,puzzleMat);
}
return 1; return 1;
} }
//last log entry multiple solutions (and current one was randomed) //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) //delete randomed piece from PieceCollector and go to next (which might random again depending on function)
else if((log.back().PieceCollector.size())>1) else if((log.back().PieceCollector.size())>1)
{ {
//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; //cout << "multiple" << endl;
p_Box.push_back(log.back().PieceCollector[0]); p_Box.push_back(log.back().PieceCollector[0]);
//shuffleup //shuffleup
@ -224,9 +239,14 @@ bool backtrack(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzl
if(log.back().PieceCollector.size()==1) if(log.back().PieceCollector.size()==1)
log.back().decreaseRandomed(); log.back().decreaseRandomed();
//for abstraction layer 1 so that first rotation solution is set.
(*(log.back().PieceCollector[0])).resetShift();
//cout << "erased first element" << endl; //cout << "erased first element" << endl;
//status(log,p_Box,puzzleMat); //status(log,p_Box,puzzleMat);
setsolution(log,p_Box,puzzleMat); setsolution(log,p_Box,puzzleMat);
}
return 1; return 1;
//no need to remove from puzzle mat, as sersolution overwrites it anyway //no need to remove from puzzle mat, as sersolution overwrites it anyway
} }

View File

@ -22,7 +22,8 @@ public:
break; break;
} }
} }
unsigned int getShift(){return shifts;}
void resetShift(){shifts=0;}
void shift(unsigned int moves); void shift(unsigned int moves);
void randomCenterPiece(); void randomCenterPiece();
void printPiece() { cout << bitset<sizeof(unsigned char)*8> (getConnections()); } void printPiece() { cout << bitset<sizeof(unsigned char)*8> (getConnections()); }
@ -94,7 +95,7 @@ public:
bool PlaceOfPartGood(unsigned int m, unsigned int n, PuzzlePiece& myPart); bool PlaceOfPartGood(unsigned int m, unsigned int n, PuzzlePiece& myPart);
bool PlaceOfPart2Good(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<PuzzlePiece>& myBox, unsigned int separator); unsigned int tryAllPieces(unsigned int m, unsigned int n, vector<PuzzlePiece>& myBox, unsigned int separator);
unsigned int putBackIntoBox(unsigned int m, unsigned int n, vector<PuzzlePiece>& myBox); unsigned int putBackIntoBox(unsigned int m, unsigned int n, vector<PuzzlePiece>& myBox);

View File

@ -9,7 +9,7 @@
int main() int main()
{ {
int cols=40, rows=40; int cols=10, rows=10;
//some basic part stuff //some basic part stuff
vector<Part> myFirstPuzzle; vector<Part> myFirstPuzzle;
Part myFirstPart; Part myFirstPart;
@ -24,7 +24,7 @@ int main()
//undo everything and make this puzzle fucking imba hard!!! //undo everything and make this puzzle fucking imba hard!!!
//need 40x40 for this, so check your status //need 40x40 for this, so check your status
makehard4040puzzle(myFirstBox); //makehard4040puzzle(myFirstBox);
//some advanced solver stuff //some advanced solver stuff
vector<LogEntry> log; vector<LogEntry> log;