#include <iostream>
#include <ctime>
#include <cstdlib>
#define INC 3 // incubation period
#define DUR 5 //duration

using namespace std;

template <typename TwoD>
void printMap(TwoD& map){
	for(int row = 0; row < 4; row++){
		cout << "| ";
		for(int col = 0; col < 8; col++){
			if(map[row][col] >= 0 and map[row][col] < INC){
				cout << "I | "; // incubating
			} else if(map[row][col] >= INC and map[row][col] < (INC+DUR)){
				cout << "A | "; // active (symptomatic)
			} else if(map[row][col] >= (INC+DUR)){
				cout << "H | "; // healthy and immune
			} else {
				cout << "U | "; // uninfected and healthy
			}
		}
		cout << endl;
	}
}

template <typename TwoD>
bool everyoneIsHealthy(TwoD& map){
	for(int row = 0; row < 4; row++){
		for(int col = 0; col < 8; col++){
			// if someone is incubating or active
			if(map[row][col] >= 0 and map[row][col] < (INC+DUR)){
				return false;
			}	
		}
	}
	return true;
}

int main(){
	int numStudents = 32;
	double transmissionRate = 0.1;
	int transmissionMap[4][8];
	int temp;
	int count;

	unsigned seed = time(0);
	srand(seed);

	for(int row = 0; row < 4; row++){
		for(int col = 0; col < 8; col++){
			transmissionMap[row][col] = -999999;	
		}
	}

	// start by setting patient zero
	int randRow = rand() % 4;
	int randCol = rand() % 8;
	transmissionMap[randRow][randCol] = 0;

	cout << "Initial state:\n";
	printMap(transmissionMap);

	// start simulation:
	count = 0;
	do{
		count++;
		cout << "****************************************\n";
		cout << "Round " << count << ":\n";
		for(int row = 0; row < 4; row++){
			for(int col = 0; col < 8; col++){
				if(transmissionMap[row][col] >= 0 and transmissionMap[row][col] < INC){
					cout << "(" << row << "," << col << ")" << ": already incubating (do nothing).\n";
				} else if(transmissionMap[row][col] >= INC and transmissionMap[row][col] < (INC+DUR)){
					cout << "(" << row << "," << col << ")" << ": already active (do nothing).\n";
				} else if(transmissionMap[row][col] >= (INC+DUR)){
					cout << "(" << row << "," << col << ")" << ": already immune (do nothing).\n";
				} else {
					cout << "(" << row << "," << col << ")" << ": healthy, determining if infected! ";
					// TODO: is there anyone on the map incubating or infected?
					temp = rand() % 10;
					cout << "Rolls a: " << temp;
					if(temp == 0){
						transmissionMap[row][col] = 0;
						cout << " ...NEW INFECTION!!!\n";
					} else {
						cout << " ...stays healthy.\n";
					}
					
				}

			}
		}

		// increment the values as time passes
		for(int row = 0; row < 4; row++){
			for(int col = 0; col < 8; col++){
				transmissionMap[row][col] += 1;	
			}
		}
		// print the new map
		printMap(transmissionMap);
	}while(not everyoneIsHealthy(transmissionMap));

	return 0;
}



