2017-12-20 22:05:04 +01:00
|
|
|
#include "DestructionPower.h"
|
2017-12-21 12:20:57 +01:00
|
|
|
|
2017-12-21 13:35:13 +01:00
|
|
|
//TODO! Add more layers here!
|
2018-01-08 18:44:32 +01:00
|
|
|
|
|
|
|
//sets relations of speed for the different layers
|
2017-12-21 12:20:57 +01:00
|
|
|
map<int,float> DestructionPower_Properties::SpeedTable =
|
|
|
|
{
|
2018-01-19 21:36:31 +01:00
|
|
|
{0,0.99},
|
|
|
|
{1,0.7},
|
2018-01-25 22:14:00 +01:00
|
|
|
{2,0.7},
|
|
|
|
{3,0.5}
|
2017-12-21 12:20:57 +01:00
|
|
|
};
|
|
|
|
|
2017-12-29 14:33:22 +01:00
|
|
|
bool DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
|
2017-12-20 22:05:04 +01:00
|
|
|
{
|
2018-01-07 20:08:50 +01:00
|
|
|
cout << "DestructionPower Preprocessing... ";
|
2017-12-29 14:33:22 +01:00
|
|
|
|
2018-01-07 21:58:16 +01:00
|
|
|
InitialiseConstraintMatrixSize(mySize.col,mySize.row);
|
2018-01-07 20:08:50 +01:00
|
|
|
cout << "Done!" << endl;
|
2017-12-29 14:33:22 +01:00
|
|
|
return true;
|
2017-12-20 22:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
|
|
|
|
bool DestructionPower::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-22 23:09:23 +01:00
|
|
|
bool DestructionPower::SetConstraintOnPosition(const coor constraintCoordinate, const DestructionPower_Properties constraint)
|
2017-12-20 22:05:04 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DestructionPower::RemoveConstraintOnPosition(const coor constraintCoordinate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-06 23:23:42 +01:00
|
|
|
//gets destruction power from left and from top if possible and normalizes
|
2017-12-20 22:05:04 +01:00
|
|
|
void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) {
|
2018-01-06 23:23:42 +01:00
|
|
|
|
2018-01-20 09:40:03 +01:00
|
|
|
for(int i = 0; i < m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.size(); ++i)
|
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.pop_back();
|
2017-12-20 22:05:04 +01:00
|
|
|
for (int i = 0; i < DESTRUCTION_COUNT; ++i) {
|
2018-01-19 22:09:12 +01:00
|
|
|
|
2018-01-06 23:23:42 +01:00
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.push_back(0);
|
2017-12-20 22:05:04 +01:00
|
|
|
int divisor=0;
|
|
|
|
if(constraintCoordinate.row > 0)
|
|
|
|
{
|
|
|
|
divisor++;
|
2018-01-06 23:23:42 +01:00
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i];
|
2017-12-20 22:05:04 +01:00
|
|
|
}
|
|
|
|
if(constraintCoordinate.col > 0)
|
|
|
|
{
|
|
|
|
divisor++;
|
2018-01-06 23:23:42 +01:00
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i];
|
2017-12-20 22:05:04 +01:00
|
|
|
}
|
|
|
|
if(divisor)
|
2018-01-06 23:23:42 +01:00
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] /=divisor;
|
|
|
|
else
|
|
|
|
//create default destructionPower //TODO find some better solution for default
|
2018-01-19 21:36:31 +01:00
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] = m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SpeedTable[i];
|
2018-01-19 22:09:12 +01:00
|
|
|
//aging
|
|
|
|
if(m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]<0.9)
|
|
|
|
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]=m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]*(float)1.001+(float)0.01;
|
2017-12-20 22:05:04 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 23:23:42 +01:00
|
|
|
|
|
|
|
float DestructionPower::defaultDestructionPower(int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-22 22:55:55 +01:00
|
|
|
//gets next highest valued abstraction layer down from current one (if first, get highest)
|
|
|
|
int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer)
|
|
|
|
{
|
2018-01-22 19:20:25 +01:00
|
|
|
if(++currentAbstractionLayer>=DESTRUCTION_COUNT)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return currentAbstractionLayer;
|
|
|
|
|
2018-01-06 23:23:42 +01:00
|
|
|
float currentPower = 1;
|
2017-12-22 22:55:55 +01:00
|
|
|
int nextLayer=-1;
|
|
|
|
float nextLayerPower=0;
|
|
|
|
if (currentAbstractionLayer>=0)
|
2018-01-07 20:08:50 +01:00
|
|
|
currentPower = m_constraintMatrix[newCoordinate.col][newCoordinate.row].DestructionArray[currentAbstractionLayer];
|
2017-12-22 22:55:55 +01:00
|
|
|
|
|
|
|
int i=0;
|
2018-01-06 23:23:42 +01:00
|
|
|
|
|
|
|
//giff next most valuable layer
|
2018-01-07 20:08:50 +01:00
|
|
|
for(auto it:m_constraintMatrix[newCoordinate.col][newCoordinate.row].DestructionArray)
|
2017-12-22 22:55:55 +01:00
|
|
|
{
|
|
|
|
if(it <= currentPower)
|
2018-01-06 23:23:42 +01:00
|
|
|
{//if equal, then has to be the next one (activated from left to right)
|
2018-01-07 20:08:50 +01:00
|
|
|
if(it == currentPower) {
|
|
|
|
if (i > currentAbstractionLayer)
|
2017-12-22 22:55:55 +01:00
|
|
|
return i;
|
|
|
|
}
|
2018-01-07 20:08:50 +01:00
|
|
|
//if this one is bigger than previous biggest one, save
|
|
|
|
else if(it>nextLayerPower)
|
|
|
|
{
|
|
|
|
nextLayerPower=it;
|
|
|
|
nextLayer=i;
|
|
|
|
}
|
2017-12-22 22:55:55 +01:00
|
|
|
}
|
2018-01-06 23:23:42 +01:00
|
|
|
i++;
|
2017-12-22 22:55:55 +01:00
|
|
|
}
|
|
|
|
return nextLayer;
|
|
|
|
}
|
2017-12-21 13:35:13 +01:00
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
DestructionPower_Properties::DestructionPower_Properties() {
|
2017-12-21 13:35:13 +01:00
|
|
|
float aging=1.001;
|
|
|
|
for(int i=0;i<DestructionArray.size();i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
DestructionArray.emplace_back((DestructionPower_Properties::SpeedTable[i]*DESTRUCTION_INIT));
|
2018-01-19 21:36:31 +01:00
|
|
|
DestructionArray.back()<0.8 ? DestructionArray.back()=aging*DestructionArray.back()+(float)0.01:DestructionArray.back();
|
2017-12-21 13:35:13 +01:00
|
|
|
}
|
2017-12-22 22:55:55 +01:00
|
|
|
}
|