split functions, added printbox, fixed put into box

This commit is contained in:
Raphael Maenle 2017-12-23 10:11:07 +01:00
parent 93226cca1b
commit eada1bba96
7 changed files with 53 additions and 21 deletions

View File

@ -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<Part>& PuzzleBox)
int i=0;
for(int col=1;col<m_constraintMatrix.size()-1;col++)
for(int row=1;row<m_constraintMatrix[col].size()-1;row++)
PuzzleBox[i++].m_test1.m_connections=m_constraintMatrix[col][row].m_connections;
PuzzleBox[i++].m_a1.m_connections=m_constraintMatrix[col][row].m_connections;
}
@ -110,6 +108,7 @@ void AbstractionLayer_1::printConstraintMatrix() {
std::cout << std::bitset<8>(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);
}

View File

@ -25,7 +25,7 @@ public:
void setEdgeZero();
bool CreateRandomPuzzle();
void CreateRandomPuzzle();
qualityVector returnInBox(vector<Part>& PuzzleBox);
void printConstraintMatrix();

View File

@ -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;

View File

@ -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;i<this->getSizeAsCoor().col;i++)
{
for(int j=0;j<this->getSizeAsCoor().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);
}
}
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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<LogEntry> log;
Puzzle puzzleMat(cols, rows);
puzzleMat.createRandomBox();
cout << "here" << endl;
puzzleMat.a1.printConstraintMatrix();
puzzleMat.printBox();
//vector<vector<PuzzlePiece*>> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat);
while(next(log, puzzleMat.p_myBox,puzzleMat));
puzzleMat.printPuzzle();
return 0;
}