@Override
public void performAction(RoboterController roboterController) {
// System.out.println("Simulator: Iterate RoboterController");
double leftSensorIntensity = 0;
double rightSensorIntensity = 0;
Roboter roboter = roboterController.getRoboter();
RoboterConstruction roboterConstruction = roboterController.getRoboterConstruction();
for (LightBulbController lightBulbController : lightBulbControllers) {
// Left Light Sensor
Point2d leftLightSensorPoint = roboterConstruction.getRoboterElementPoint(roboter.getLeftLightSensor());
Vector2d leftLightSensorVector = roboterConstruction.getRoboterElementAngleVector(roboter.getLeftLightSensor());
leftSensorIntensity = leftSensorIntensity
+ lightBulbController.calculateIntensity(leftLightSensorPoint, roboter.getLeftLightSensor(),
leftLightSensorVector);
// Right Light Sensor
Point2d rightLightSensorPoint = roboterConstruction.getRoboterElementPoint(roboter.getRightLightSensor());
Vector2d rightLightSensorVector = roboterConstruction.getRoboterElementAngleVector(roboter
.getRightLightSensor());
rightSensorIntensity = rightSensorIntensity
+ lightBulbController.calculateIntensity(rightLightSensorPoint, roboter.getRightLightSensor(),
rightLightSensorVector);
}
// Changed Left Sensor Intensity
if (leftSensorIntensity != roboter.getLeftLightSensor().getSensorIntensity()) {
notifyObservers(new LightSensorModelObserverCommand(roboter, LightSensorCommandState.SENSOR_INTENSITY_CHANGED,
roboter.getLeftLightSensor()));
logger.debug("Changed Left Light Sensor Intensity to {}: " + leftSensorIntensity);
roboter.getLeftLightSensor().setSensorIntensity(leftSensorIntensity);
}
if (leftSensorIntensity == 0) {
notifyObservers(new LightSensorModelObserverCommand(roboter, LightSensorCommandState.SENSOR_INTENSITY_REMAINS,
roboter.getLeftLightSensor()));
}
// Changed Right Sensor Intensity
if (rightSensorIntensity != roboter.getRightLightSensor().getSensorIntensity()) {
notifyObservers(new LightSensorModelObserverCommand(roboter, LightSensorCommandState.SENSOR_INTENSITY_CHANGED,
roboter.getRightLightSensor()));
logger.debug("Changed Right Light Sensor Intensity to {}: " + rightSensorIntensity);
roboter.getRightLightSensor().setSensorIntensity(rightSensorIntensity);
}
if (rightSensorIntensity == 0) {
notifyObservers(new LightSensorModelObserverCommand(roboter, LightSensorCommandState.SENSOR_INTENSITY_REMAINS,
roboter.getRightLightSensor()));
}
RoboterMove rm = roboterController.calculateNewRoboterPosition(leftSensorIntensity, rightSensorIntensity);
calculateOutOfWindowAreaPosition(roboterController, rm);