added basic construct to keep on turning puzzle piece. non functional as of yet.
This commit is contained in:
parent
6c81722d02
commit
3567b77cec
@ -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;
|
||||||
|
@ -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]))))
|
||||||
{
|
{
|
||||||
@ -200,33 +201,52 @@ bool backtrack(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzl
|
|||||||
//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)
|
||||||
{
|
{
|
||||||
//cout << "one" << endl;
|
(*(log.back().PieceCollector[0])).shift(1);
|
||||||
p_Box.push_back(log.back().PieceCollector[0]);
|
if(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[0]), 4-(*(log.back().PieceCollector[0])).getShift()))
|
||||||
//shuffleup
|
setsolution(log,p_Box,puzzleMat);
|
||||||
random_shuffle(p_Box.begin(),p_Box.end());
|
else
|
||||||
puzzleMat.removePiece(log.back().myCoor.m, log.back().myCoor.n);
|
{
|
||||||
log.pop_back();
|
//cout << "one" << endl;
|
||||||
//cout << "removed" << endl;
|
p_Box.push_back(log.back().PieceCollector[0]);
|
||||||
//status(log,p_Box,puzzleMat);
|
//shuffleup
|
||||||
backtrack(log,p_Box,puzzleMat);
|
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;
|
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)
|
||||||
{
|
{
|
||||||
//cout << "multiple" << endl;
|
|
||||||
p_Box.push_back(log.back().PieceCollector[0]);
|
//check if piece has second rotation solution
|
||||||
//shuffleup
|
(*(log.back().PieceCollector[0])).shift(1);
|
||||||
random_shuffle(p_Box.begin(),p_Box.end());
|
if(puzzleMat.testRotationPiece(log.back().myCoor.m, log.back().myCoor.n, *(log.back().PieceCollector[0]), 4-(*(log.back().PieceCollector[0])).getShift()))
|
||||||
log.back().PieceCollector.erase(log.back().PieceCollector.begin());
|
setsolution(log,p_Box,puzzleMat);
|
||||||
|
else
|
||||||
if(log.back().PieceCollector.size()==1)
|
{
|
||||||
log.back().decreaseRandomed();
|
|
||||||
|
//cout << "multiple" << endl;
|
||||||
//cout << "erased first element" << endl;
|
p_Box.push_back(log.back().PieceCollector[0]);
|
||||||
//status(log,p_Box,puzzleMat);
|
//shuffleup
|
||||||
setsolution(log,p_Box,puzzleMat);
|
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;
|
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
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user