/*
* File name: CleanAndMove.java (package eas.simulation.users.lukas.cleaningLiveDemo)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 10.12.2010 (11:14:26)
*
* (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.cleaningLiveDemo;
import java.util.LinkedList;
import eas.math.geometry.Vector2D;
import eas.simulation.agent.GenericActuator;
import eas.simulation.spatial.sim2D.gridSimulation.standardGridObjects.GridDoubleValue;
import eas.simulation.spatial.sim2D.standardAgents.AbstractAgent2D;
/**
* @author Lukas König
*
*/
public class CleanAndMove extends
GenericActuator<CleaningEnvironment, AbstractAgent2D<?>> {
/**
*
*/
private static final long serialVersionUID = 2523715790915871784L;
/*
* (non-Javadoc)
*
* @see
* eas.simulation.GenericActuator#actuate(eas.simulation.AbstractEnvironment
* , eas.simulation.AbstractAgent)
*/
@Override
public void actuate(CleaningEnvironment env, AbstractAgent2D<?> agent) {
// CLEAN
Vector2D pos = env.getAgentPosition(agent.id());
GridDoubleValue gridDoubleValue = env.getGridDoubleValue(pos.x, pos.y);
if (gridDoubleValue.getValue() > 10) {
double toClean = gridDoubleValue.getValue() / 1.2;
gridDoubleValue.setValue(toClean);
}
// MOVE
Vector2D position = env.getAgentPosition(agent.id());
@SuppressWarnings("unchecked")
LinkedList<Double> dirty = (LinkedList<Double>) agent.sense("Dirty");
double max = dirty.get(0);
double maxIndex = 0;
for (int i = 1; i < dirty.size(); i++) {
if (dirty.get(i) > max) {
max = dirty.get(i);
maxIndex = i;
}
}
if (maxIndex == 1) {
// hoch.
env.setAgentPosition(agent.id(), new Vector2D(position.x, position.y - 1));
env.setAgentAngle(agent.id(), 180);
}
if (maxIndex == 2) {
// links.
env.setAgentPosition(agent.id(), new Vector2D(position.x - 1, position.y));
env.setAgentAngle(agent.id(), 90);
}
if (maxIndex == 3) {
// runter.
env.setAgentPosition(agent.id(), new Vector2D(position.x, position.y + 1));
env.setAgentAngle(agent.id(), 0);
}
if (maxIndex == 4) {
// rechts.
env.setAgentAngle(agent.id(), 270);
env.setAgentPosition(agent.id(), new Vector2D(position.x + 1, position.y));
}
if (maxIndex == 0) {
} // Keine Bewegung.
}
/*
* (non-Javadoc)
*
* @see eas.simulation.GenericActuator#id()
*/
@Override
public String id() {
return "Clean+Move";
}
}