/*
IterationOneInfection.cpp

*/

#include "IterationOneInfection.h"

// default constructor
IterationOneInfection::IterationOneInfection():highRiskFactor(2.0){
	//seed the random number generator based on the time of instantiation
	srand( (unsigned)time(0) );
}

// default destructor
IterationOneInfection::~IterationOneInfection(){}


void IterationOneInfection::DisplayMenu(){
	GetHighRiskInput();
}

void IterationOneInfection::Run(City * targetCity){
	int ra,r,c;
	double hrFactor;
	int row = targetCity->GetRows();
	int columns = targetCity->GetColumns();
	ra = rand();
	
	for(r = 0; r < row; r++){
		for(c = 0; c < columns; c++){
		
			//set local variable, depending on whether the location is high risk
			if (targetCity->IsHighRisk(r,c)) {
				hrFactor = highRiskFactor;
			}
			else {
				hrFactor = 1.0;
			}
			
			/*We divide all the probability values by hrFactor to increase the
			  probability that high risk people become infected. If the person
			  isn't at high risk, then we're dividing by 1, so it doesn't change
			  the default risk values.
			*/
			//if a person is vaccinated, they have a 1/10,000 chance of getting infected
			if(targetCity->IsVaccinated(r,c) && ((ra%(int)(10000/hrFactor)) + 1) == 1){
				targetCity->InfectLocation(r,c);
			}
			//if they're not vaccinated, and no one adjacent to them is contagious, they still have a 1/100 chance of getting infected
			else if(AdjacentInfectiousCount(targetCity,r,c) == 0 && ((ra%(int)(100/hrFactor)) + 1) == 1){
				targetCity->InfectLocation(r,c);
			}
			//if they're not vaccinated, but anyone adjacent to them is contagious, they have a 1/10 chance of getting infected
			else if(AdjacentInfectiousCount(targetCity,r,c) > 0 && ((ra%(int)(10/hrFactor)) + 1) == 1){
				targetCity->InfectLocation(r,c);
			}
		}
	}
}
