/*
* File name: StupidScheduler.java (package eas.users.lukas.demos.stupidModel)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 14.09.2011 (16:11:29)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.demos.stupidModel;
import java.awt.Color;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import eas.math.geometry.Vector2D;
import eas.plugins.PluginProperties;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.gridSimulation.standardGridObjects.GridDoubleValue;
import eas.startSetup.ParCollection;
/**
* @author Lukas König
*
*/
@PluginProperties (pluginIsHidden = true)
public class StupidScheduler extends AbstractDefaultMaster<StupidEnvironment> {
/**
*
*/
private static final long serialVersionUID = 233969795548831651L;
@Override
public StupidEnvironment[] generateRunnables(ParCollection params) {
int size = 50;
StupidEnvironment env = new StupidEnvironment(0, params, size, size, true);
Random rand = new Random();
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
GridDoubleValue gridDoubleValue = new GridDoubleValue(rand.nextDouble() * 10);
gridDoubleValue.setMaxValColor(Color.green);
env.addGridObject(gridDoubleValue, i, j);
}
}
for (int i = 0; i < 2; i++) {
env.addAgent(new StupidBug(i, env, params), new Vector2D(rand.nextInt(size), rand.nextInt(size)), rand.nextDouble() * 360);
}
return new StupidEnvironment[] { env };
}
@Override
public String id() {
return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-Stupid";
}
@Override
public synchronized void runDuringSimulation(StupidEnvironment env, Wink simZyk,
ParCollection params) {
env.step(simZyk);
List<StupidBug> list = env.getAgents();
LinkedList<StupidBug> newlist = new LinkedList<StupidBug>();
Random rand = new Random();
while (list.size() > 0) {
int i = rand.nextInt(list.size());
newlist.add(list.get(i));
list.remove(i);
}
for (StupidBug agent : newlist) {
agent.step(simZyk);
}
}
}