package za.redbridge.experiment;

import org.encog.ml.CalculateScore;
import org.encog.ml.MLMethod;

import java.awt.Color;
import java.awt.Paint;

import za.redbridge.experiment.MMNEAT.MMNEATNetwork;
import za.redbridge.simulator.Simulation;
import za.redbridge.simulator.config.SimConfig;
import za.redbridge.simulator.factories.HomogeneousRobotFactory;
import za.redbridge.simulator.factories.RobotFactory;

/**
 * Created by jamie on 2014/09/09.
 */
public class ScoreCalculator implements CalculateScore {

    private static final double DEFAULT_ROBOT_MASS = 0.7;
    private static final double DEFAULT_ROBOT_RADIUS = 0.15;
    private static final Paint DEFAULT_ROBOT_PAINT = Color.BLACK;

    private final SimConfig simConfig;

    private double lastScore;

    public ScoreCalculator(SimConfig simConfig) {
        this.simConfig = simConfig;
    }

    @Override
    public double calculateScore(MLMethod method) {
        MMNEATNetwork network = (MMNEATNetwork) method;

        // Create the robot and resource factories
        RobotFactory robotFactory = new HomogeneousRobotFactory(new MMNEATPhenotype(network),
                DEFAULT_ROBOT_MASS, DEFAULT_ROBOT_RADIUS, DEFAULT_ROBOT_PAINT);

        // Create the simulation and run it
        Simulation simulation = new Simulation(simConfig, robotFactory, 15);
        simulation.run();

        // Get the fitness
        lastScore = simulation.getFitness();
        return lastScore;
    }

    @Override
    public boolean shouldMinimize() {
        return false;
    }

    @Override
    public boolean requireSingleThreaded() {
        return false;
    }

    public double getLastScore() {
        return lastScore;
    }
}

@@ -137,24 +137,52 @@
 awt.Paint;%0A%0A
+import sim.display.Console;%0A
 import za.re
@@ -264,16 +264,61 @@
 lation;%0A
+import za.redbridge.simulator.SimulationGUI;%0A
 import z
@@ -1522,32 +1522,628 @@
 stScore;%0A    %7D%0A%0A
+    public void demo(MMNEATNetwork network) %7B%0A        // Create the robot and resource factories%0A        RobotFactory robotFactory = new HomogeneousRobotFactory(new MMNEATPhenotype(network),%0A                DEFAULT_ROBOT_MASS, DEFAULT_ROBOT_RADIUS, DEFAULT_ROBOT_PAINT);%0A%0A        // Create the simulation and run it%0A        Simulation simulation = new Simulation(simConfig, robotFactory, 15);%0A%0A        SimulationGUI video = new SimulationGUI(simulation);%0A%0A        //new console which displays this simulation%0A        Console console = new Console(video);%0A        console.setVisible(true);%0A    %7D%0A%0A
     @Override%0A  

Add GUI demo to ScoreCalculator