unfinished merge, problems with randomgenerator

random generator in class needs to return a randomized puzzlebox
This commit is contained in:
Raphael Maenle 2017-12-18 22:50:03 +01:00
parent 90e31ddba6
commit 507533531c
3 changed files with 59 additions and 35 deletions

View File

@ -13,12 +13,18 @@ void AbstractionLayer_1::PreProcessing(const vector<Part*>* partArray)
bool AbstractionLayer_1::EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector) bool AbstractionLayer_1::EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector)
{ {
for(int i=0;i<qVector.size();i++)
{
if(PlaceOfPartGood(constraintCoordinate, qVector[i].Part))
qVector[i].setQuality(1);
else
qVector[i].setQuality(0);
}
} }
bool AbstractionLayer_1::SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint) bool AbstractionLayer_1::SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint)
{ {
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row]=
} }
bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordinate) bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordinate)
@ -29,7 +35,7 @@ bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordin
bool AbstractionLayer_1::CreateRandomPuzzle() bool AbstractionLayer_1::CreateRandomPuzzle()
{ {
for(int col=1;col<m_constraintMatrix.size()-1;col++){ for(int col=1;col<m_constraintMatrix.size()-1;col++){
for(int row=1;row<m_constraintMatrix[col].size()-1;row++) for(int row=1;row<m_constraintMatrix[col].size()-1;)
{ {
uint8_t tempPiece = 0b00000000; uint8_t tempPiece = 0b00000000;
if(rand()%2) if(rand()%2)
@ -37,46 +43,24 @@ bool AbstractionLayer_1::CreateRandomPuzzle()
else else
tempPiece|=0b10000000; tempPiece|=0b10000000;
if(rand()%2)
tempPiece|=0b00010000;
else
tempPiece|=0b00100000;
if(rand()%2) if(rand()%2)
tempPiece|=0b00000100; tempPiece|=0b00000100;
else else
tempPiece|=0b00001000; tempPiece|=0b00001000;
if(m_constraintMatrix[col-1][row].m_connections != 0b00000000 || m_constraintMatrix[col-1][row].m_connections != 0b11111111)
{
tempPiece|=(0b00110000 xor (0b00110000 & m_constraintMatrix[col-1][row].m_connections));
//tempPiece.shift();
}
}
//add shift function
else
{
if(rand()%2) if(rand()%2)
tempPiece|=0b00000001; tempPiece|=0b00000001;
else else
tempPiece|=0b00000010; tempPiece|=0b00000010;
}
if(m_constraintMatrix[col-1][row].m_connections != 0b00000000 || m_constraintMatrix[col-1][row].m_connections != 0b11111111) if(PlaceOfPartGood(coor(col,row),tempPiece))
tempPiece |= (0b00110000 xor (0b00110000 & m_constraintMatrix[col-1][row].m_connections)); row++;
else
{
if(rand()%2)
tempPiece |= 0b00010000;
else
tempPiece |= 0b00100000;
} }
}
//insert temppuzzlepiece into matrix
} }
} }
@ -89,3 +73,41 @@ void AbstractionLayer_1::setEdgeZero()
m_constraintMatrix[col][row].m_connections=0b00000000; m_constraintMatrix[col][row].m_connections=0b00000000;
} }
//checks if the myPart in its current orientation is legal in position m, n
bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart)
{
uint8_t negativePart(0)=0b00000000;
negativePart or_eq (m_constraintMatrix[myCoor.col][myCoor.row+1].m_connections & 0b11000000);
negativePart or_eq (m_constraintMatrix[myCoor.col-1][myCoor.row].m_connections & 0b00110000);
negativePart or_eq (m_constraintMatrix[myCoor.col][myCoor.row-1].m_connections & 0b00001100);
negativePart or_eq (m_constraintMatrix[myCoor.col+1][myCoor.row].m_connections & 0b00000011);
shift(negativePart,2);
if (
( ((((negativePart & 0b11000000) ^ (myPart & 0b11000000)) != 0b00000000) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|| ((((negativePart & 0b11000000) == 0b11000000) || ((myPart & 0b11000000) == 0b11000000)) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|| (((negativePart & 0b11000000) == 0b00000000) && ((myPart & 0b11000000) == 0b00000000)) )
&&
( ((((negativePart & 0b00110000) ^ (myPart & 0b00110000)) != 0b00000000) && (((myPart & 0b00110000) != 0b00000000) && (negativePart & 0b00110000) != 0b00000000))
|| ((((negativePart & 0b00110000) == 0b00110000) || ((myPart & 0b00110000) == 0b00110000)) && (((myPart & 0b00110000) != 0b00000000) && (negativePart & 0b00110000) != 0b00000000))
|| (((negativePart & 0b00110000) == 0b00000000) && ((myPart & 0b00110000) == 0b00000000)) )
&&
( ((((negativePart & 0b00001100) ^ (myPart & 0b00001100)) != 0b00000000) && (((myPart & 0b00001100) != 0b00000000) && (negativePart & 0b00001100) != 0b00000000))
|| ((((negativePart & 0b00001100) == 0b00001100) || ((myPart & 0b00001100) == 0b00001100)) && (((myPart & 0b00001100) != 0b00000000) && (negativePart & 0b00001100) != 0b00000000))
|| (((negativePart & 0b00001100) == 0b00000000) && ((myPart & 0b00001100) == 0b00000000)) )
&&
( ((((negativePart & 0b00000011) ^ (myPart & 0b00000011)) != 0b00000000)&& (((myPart & 0b00000011) != 0b00000000) && (negativePart & 0b00000011) != 0b00000000))
|| ((((negativePart & 0b00000011) == 0b00000011) || ((myPart & 0b00000011) == 0b00000011)) && (((myPart & 0b00000011) != 0b00000000) && (negativePart & 0b00000011) != 0b00000000))
|| (((negativePart & 0b00000011) == 0b00000000) && ((myPart & 0b00000011) == 0b00000000)) )
)
return true;
return false;
}
void AbstractionLayer_1::shift(uint8_t& Part, int shifts)
{
Part = Part >> (shifts*2) | Part << sizeof(uint8_t)*8 - (shifts*2);
}

View File

@ -18,7 +18,8 @@ public:
bool EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector); bool EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector);
bool SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint); bool SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint);
bool RemoveConstraintOnPosition(const coor constraintCoordinate); bool RemoveConstraintOnPosition(const coor constraintCoordinate);
bool PlaceOfPartGood(coor myCoor, uint8_t& myPart);
void shift(uint8_t& Part, int shifts);
void setEdgeZero(); void setEdgeZero();

View File

@ -1,5 +1,6 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include "input.h"
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>