import java.awt.Color;
import java.util.Random;

import becker.robots.*;
/**
 * This driver class was prepared for in support of the 
 * <a href="http://darcy.rsgc.on.ca/ACES/ICS2O/1112RobotProgrammingProjects.htm#Election">Elections Programming Project</a>. 
 * Votes (Things) are assigned to each household (intersection) using a probability that reflects polling data 
 * from a recent Nanos Research poll. Walls are positioned at the ends of each street to enable candidadtes
 * to recognized when it's time to prepare for the next street.  
 * You are not to modify this undocumented class in any way, but you ARE encouraged to examine the code if you are curious.  
 * @author C. D'Arcy
 *
 */
public class Riding extends City {

	double[] probabilities = { 0.388, 0.676, 0.868, 0.953, 0.981, 1.0 };
	Color[] palette = { Color.blue, Color.red, Color.orange, Color.cyan,
			new Color(0, 128, 0), Color.black };
	Random random = new Random();

	public Riding() {
		super(8, 8);
		this.placeWalls();
		this.placeVoters();
	}

	private void placeWalls() {
		int street = 1;
		while (street < 7) {
			Wall wall = new Wall(this, street, 0, Direction.WEST);
			wall = new Wall(this, street, 7, Direction.EAST);
			street++;
		}
	}

	private void placeVoters() {
		int street = 1;
		while (street <= 6) {
			int avenue = 1;
			while (avenue <= 6) {
				Thing voter = new Thing(this, street, avenue);
				voter.setColor(palette[getParty()]);
				avenue++;
			}
			street++;
		}

	}

	private int getParty() {
		int index = 0;
		double sample = random.nextDouble();
		while (sample > probabilities[index])
			index++;
		return index;

	}

}
