package exampleAlgorithms;

import api.CpsAlgorithm;
import ui.controller.Control;
import ui.model.Model;
import classes.*;

public class RandomSwitchesAlgorithm implements CpsAlgorithm {

	@Override
	public void runAlgorithm(Model model, Control controller) {
		randomSwitches(model);
	}

	/**
	 * Sets every Switch to a random state.
	 * 
	 * @param model
	 *            the Model
	 */
	private void randomSwitches(Model model) {
		for (HolonSwitch s : model.getSwitches()) {
			// Set to Manual Mode
			s.setManualMode(true);
			// Generate a random number between 0 and 1
			double randomDouble = Math.random();
			if (randomDouble < 0.5) {
				s.setManualState(true);
			} else {
				s.setManualState(false);
			}
		}
	}
}