From eada1bba9629e539ed45cafae798c7ca3d588113 Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Sat, 23 Dec 2017 10:11:07 +0100 Subject: [PATCH] split functions, added printbox, fixed put into box --- .../Layer1/AbstractionLayer_1.cpp | 20 +++++++---- .../Layer1/AbstractionLayer_1.h | 2 +- .../Layer1/AbstractionLayer_1_Properties.h | 3 ++ Source/functions/solve/puzzleExtension.cpp | 33 +++++++++++++++---- Source/header/input.h | 4 ++- Source/header/solve.h | 2 +- Source/main.cpp | 10 +++--- 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index 7693d5c..8909583 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -19,7 +19,7 @@ bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, quali { for(auto it = qVector.begin(); it != qVector.end(); it++) { - if(PlaceOfPartGood(constraintCoordinate, it->first->m_test1.m_connections)) + if(PlaceOfPartGood(constraintCoordinate, it->first->m_a1.m_connections)) continue; qVector.erase(it++); } @@ -35,7 +35,7 @@ bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordin m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].m_connections=0b11111111; } -bool AbstractionLayer_1::CreateRandomPuzzle() +void AbstractionLayer_1::CreateRandomPuzzle() { std::minstd_rand simple_rand; simple_rand.seed((unsigned int)"dumbo"); @@ -76,11 +76,9 @@ bool AbstractionLayer_1::CreateRandomPuzzle() tempPiece and_eq (uint8_t)0b11001111; //set piece if piece good - std::cout << "tempPiece = " << std::bitset<8>(tempPiece) << std::endl; if(PlaceOfPartGood(coor(col,row),tempPiece)) { m_constraintMatrix[row][col].m_connections = tempPiece; - printConstraintMatrix(); col++; } } @@ -100,7 +98,7 @@ qualityVector AbstractionLayer_1::returnInBox(vector& PuzzleBox) int i=0; for(int col=1;col(it2.m_connections) << " "; std::cout << std::endl; } + cout.flush(); } void AbstractionLayer_1::setEdgeZero() { @@ -130,7 +129,6 @@ bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart) negativePart or_eq (m_constraintMatrix[myCoor.row-1][myCoor.col].m_connections & 0b00001100); negativePart or_eq (m_constraintMatrix[myCoor.row][myCoor.col+1].m_connections & 0b00000011); shift(negativePart,2); - std::cout << "negativePart = " << std::bitset<8>(negativePart) << std::endl; if ( ( ((((negativePart & 0b11000000) ^ (myPart & 0b11000000)) != 0b00000000) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000)) || ((((negativePart & 0b11000000) == 0b11000000) || ((myPart & 0b11000000) == 0b11000000)) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000)) @@ -158,3 +156,13 @@ void AbstractionLayer_1::shift(uint8_t& Part, int shifts) Part = Part >> (shifts*2) | Part << sizeof(uint8_t)*8 - (shifts*2); } +void AbstractionLayer_1_Properties::shift(int shifts) +{ + this->m_connections = this->m_connections >> (shifts*2) | this->m_connections << sizeof(uint8_t)*8 - (shifts*2); +} + +void AbstractionLayer_1_Properties::print() +{ + std::cout << std::bitset<8>(this->m_connections); +} + diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index adc411f..8374354 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -25,7 +25,7 @@ public: void setEdgeZero(); - bool CreateRandomPuzzle(); + void CreateRandomPuzzle(); qualityVector returnInBox(vector& PuzzleBox); void printConstraintMatrix(); diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h index cca5f0e..cd5e639 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h @@ -11,6 +11,9 @@ class AbstractionLayer_1_Properties { public: AbstractionLayer_1_Properties() : m_connections(0b11111111) {} + void shift(int shifts); + void print(); + private: uint8_t m_connections; friend class AbstractionLayer_1; diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index e79472e..5e5fea9 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -7,22 +7,43 @@ void Puzzle::printPuzzle() { - //print every layer individually for now and later make complete visual + cout << "a1: " << endl; + a1.printConstraintMatrix(); +} + +void Puzzle::printBox() +{ + int i=0; + for(auto it:myBox) + { + cout << "Part " << i++ << ":" << endl; + it.print(); cout << endl; + + } } //puts a puzzlepiece back into its box void Puzzle::putIntoBox() { Part tmpPart; + int id = 0; for(int i=0;igetSizeAsCoor().col;i++) { for(int j=0;jgetSizeAsCoor().row;j++) { - //TODO! add rotation of all parts - //TODO! add id to every part (how) - tmpPart.m_test1=this->a1.m_constraintMatrix[i][j]; - //TODO! add all other layers here - myBox.emplace_back(tmpPart); + + tmpPart.m_a1=this->a1.m_constraintMatrix[i][j]; + //sets part id + tmpPart.SetPartID(id++); + // adds all 4 rotations to Box + for(int rotations=0;rotations<4;rotations++) + { + tmpPart.m_a1.shift(1); + //TODO! add all other layers and rotationvariance here + myBox.emplace_back(tmpPart); + + } + } } } diff --git a/Source/header/input.h b/Source/header/input.h index f40098a..32b8b0e 100755 --- a/Source/header/input.h +++ b/Source/header/input.h @@ -38,7 +38,9 @@ public: m_numOfRotations = numOfRotations; } - AbstractionLayer_1_Properties m_test1; + void print(){m_a1.print();} + + AbstractionLayer_1_Properties m_a1; DestructionPower_Properties m_destruction; private: int32_t m_partID; diff --git a/Source/header/solve.h b/Source/header/solve.h index 345fa09..bdbe160 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -43,7 +43,6 @@ public: Puzzle(unsigned int newcols,unsigned int newrows):rows(newrows),cols(newcols) { a1.PreProcessing({rows,cols}, nullptr); - a1.CreateRandomPuzzle(); } coor getSizeAsCoor() @@ -54,6 +53,7 @@ public: void removeConstrains(coor removeCoordinates); void printPuzzle(); + void printBox(); void createRandomBox(){createRandomPuzzle();putIntoBox();shuffle();createp_box();} void createRandomPuzzle(); diff --git a/Source/main.cpp b/Source/main.cpp index 3db123b..ff34bf7 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -7,18 +7,16 @@ int main() unsigned int cols=5, rows=6; - //some basic random puzzle stuff - Puzzle myFirstPuzzle(cols,rows); - myFirstPuzzle.createRandomBox(); - - //some advanced solver stuff vector log; - Puzzle puzzleMat(cols, rows); puzzleMat.createRandomBox(); + cout << "here" << endl; + puzzleMat.a1.printConstraintMatrix(); + puzzleMat.printBox(); //vector> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat); while(next(log, puzzleMat.p_myBox,puzzleMat)); puzzleMat.printPuzzle(); + return 0; }