/* File: Concentrations.cpp
 *
 * TODO: Edit these comments to describe anything interesting or noteworthy in your implementation.
 */
#include "concentrations.h"


void drawGrid(sf::RenderWindow& w, vector<vector<sf::RectangleShape> >& rs) {
	for (int i = 0; i < rs.size(); ++i)
		for (int j = 0; j < rs[i].size(); ++j) {
			w.draw(rs[i][j]);
		}
}



int main() {
	sf::RenderWindow window(sf::VideoMode(w_width, w_height), "Diffusion");
	window.setFramerateLimit(10);
	int r{ 0 }, c{ 0 };
	unsigned u{ 0 };
	cout << "Enter the rows and cols of your world: " << '\n';
	cin >> r >> c;
	Grid world(r, std::vector<int>(c));
	vector<vector<sf::RectangleShape> > sfGrid(r, vector<sf::RectangleShape>(c));
	randInit(world);
	//create the grid of sf::RectangleShape
	for(int i = 0; i < r; ++i)
		for (int j = 0; j < c; ++j) {
			sfGrid[i][j].setPosition(i*w_width / c, j*w_height / r);
			sfGrid[i][j].setFillColor(sf::Color::Color(256 * world[i][j] / max_height, 
													   256 * world[i][j] / max_height, 
													   256 * world[i][j] / max_height));
			sfGrid[i][j].setSize(sf::Vector2f(w_width / c, w_height / r));
		}

	/*while (!isDone(world)) {
		showWorld(world);
		disperse(world);
		cin.ignore();
		cin.get();
	}
	showWorld(world);
	cin.get();*/


	/*Grid world(r, std::vector<int>(c));
	cout << "Enter the row and column where you'd like to drop units: " << '\n';
	cout << "How many units? " << '\n';
	while (cin >> r >> c >> u) {
		while (u > 0) {
			dropUnit(world, r, c);
			showWorld(world);
			--u;
		}
		cout << "Enter the row and column where you'd like to drop how many unit: ";
	}*/
	// This "while" loop goes round and round- perhaps forever
	while (window.isOpen()) {
		// The next 5 lines detects and responds to a request to close the window
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}
		// Clear everything from the last run of the while loop
		window.clear();

		// Draw our circle and point
		

		//draw grid
		drawGrid(window, sfGrid);
		
		//update
		disperse(world);
		for (int i = 0; i < r; ++i)
			for (int j = 0; j < c; ++j) {
				sfGrid[i][j].setPosition(i*w_width / c, j*w_height / r);
				sfGrid[i][j].setFillColor(sf::Color::Color(256 * world[i][j] / max_height,
														   256 * world[i][j] / max_height, 
														   256 * world[i][j] / max_height));
				sfGrid[i][j].setSize(sf::Vector2f(w_width / c, w_height / r));
			}
		// Show everything we just drew
		window.display();
	}// This is the end of the "while" loop
}




/* * * * * * Tests Below This Point * * * * *
 //  Create a simple source grid.
	Grid before  {
		{ 3, 3, 3 },
		{ 3, 0, 3 },
		{ 3, 3, 3 }
	};
	Grid after  {
		{ 3, 3, 3 },
		{ 3, 1, 3 },
		{ 3, 3, 3 }
	};

	dropUnit(before, 1, 1);
	before == after; // The above call changes 'before.'

// Non-chaining diffues work.
// Create a simple source grid.
	Grid before  {
		{ 0, 0, 0 },
		{ 1, 3, 1 },
		{ 0, 2, 0 }
	};
	Grid after  {
		{ 0, 1, 0 },
		{ 2, 0, 2 },
		{ 0, 3, 0 }
	};

	dropUnit(before, 1, 1);
	before == after; // The above call changes 'before.'
}

Two diffuses chain.
// Create a simple source grid.
	Grid before  {
		{ 0, 0, 0, 0 },
		{ 0, 3, 3, 0 },
		{ 0, 0, 0, 0 }
	};
	Grid after  {
		{ 0, 1, 1, 0 },
		{ 1, 1, 0, 1 },
		{ 0, 1, 1, 0 }
	};

	dropUnit(before, 1, 1);
	before == after; // The above call changes 'before.'
}*/

/* TODO: You will need to add your own tests into this suite of test cases. Think about the sorts
 * of inputs we tested here, and, importantly, what sorts of inputs we *didn't* test here. Some
 * general rules of testing:
 *
 *    1. Try extreme cases. What are some very large cases to check? What are some very small cases?
 *
 *    2. Be diverse. There are a lot of possible inputs out there. Make sure you have tests that account
 *       for cases that aren't just variations of one another.
 *
 *    3. Be sneaky. Don't just try standard inputs. Try weird ones that you wouldn't expect anyone to
 *       actually enter, but which are still perfectly legal.
 *
 * Happy testing!
 */
