#include "NbVisibleUnitMiddle.h"
#include "DebugAI.h"

NbVisibleUnitMiddle::NbVisibleUnitMiddle(void){
	name = NB_VISIBLE_UNIT_MIDDLE;
	begin = 40;
	end = 60;
}

NbVisibleUnitMiddle::NbVisibleUnitMiddle(NbVisibleUnit* aFuzzyNumber){
	fuzzyNumber = aFuzzyNumber;
	fuzzyNumber->addFV(this);
	name = NB_VISIBLE_UNIT_MIDDLE;
	begin = 20;
	end = 80;
}

NbVisibleUnitMiddle::~NbVisibleUnitMiddle(void)
{
}

void NbVisibleUnitMiddle::update(){
	if (this->getFuzzyNumberValue()>= 0 && this->getFuzzyNumberValue()<begin){
		setValue(0);
	}
	if (this->getFuzzyNumberValue()>= end && this->getFuzzyNumberValue()<=100){
		setValue(0);
	}
	if (this->getFuzzyNumberValue()> 100||this->getFuzzyNumberValue()<0){
		//If the execution go here they must have a problem.
		setValue(-1);
	}
	if (this->getFuzzyNumberValue()>= begin && this->getFuzzyNumberValue()<=50){
		setValue((this->getFuzzyNumberValue() * (1/((end-begin)/2))) - (begin/((end-begin)/2)));
	}
	
	if (this->getFuzzyNumberValue()> 50 && this->getFuzzyNumberValue()<end){
		setValue((this->getFuzzyNumberValue() * (-1/((end-begin)/2))) +  (end/((end-begin)/2)));
	}
	DebugAI::trace('v', toString());
}

void NbVisibleUnitMiddle::setBegin(float aBegin){
	begin = aBegin;
}

void NbVisibleUnitMiddle::setEnd(float aEnd){
	end = aEnd;
}