package cz.vutbr.feec.muller;

import java.util.Random;
import java.util.Vector;

public class RFT extends FT {

	private Vector<Receiver> receivers;

	public RFT(int time) {
		super(time);
	}

	@Override
	public void action() {
		Random rnd = new Random();
		int ctr = 0;
		while(!getSimulation().isFinished()) {
			sleepProc(time/5.);
			int black = 0;
			int white = 0;
			int counter = 0;
			double stime = (double)((time/5.)* (rnd.nextDouble())); 
			sleepProc(stime);
			for (Receiver r : receivers) {
				counter++;
				if(r.getValue() == 0) {
					black++;
				} else {
					white++;
				}
			}
			int diffCount = getBlackCounter() + getWhiteCounter() - counter;
			System.out.print("\t"+diffCount+", ");
			resetCounters();
			sleepProc(stime);
			sleepProc((time/5.)-stime);
//			sleepProc((double)time * (rnd.nextDouble() + 0.5));
			sleepProc(time*3./5.);
			ctr++;
		}

	}

	public void setReceivers(Vector<Receiver> receivers) {
		this.receivers = receivers;
	}
	
}
