package za.redbridge.simulator;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import za.redbridge.simulator.phenotype.Phenotype;

/**
 * Created by xenos on 10/8/14.
 */
public class FitnessStats {

    private final Map<Phenotype,Double> phenotypeFitnesses = new HashMap<>();
    private double teamFitness = 0.0;

    private final double totalResourceValue;
    private int maxSteps;

    public FitnessStats(double totalResourceValue, int maxSteps) {
        this.totalResourceValue = totalResourceValue;
        this.maxSteps = maxSteps;
    }

    /**
     * Increment a phenotype's fitness.
     * @param phenotype the phenotype who's score will be adjusted
     * @param adjustedValue the adjusted value of the resource
     */
    public void addToPhenotypeFitness(Phenotype phenotype, double adjustedValue) {
        phenotypeFitnesses.put(phenotype, getPhenotypeFitness(phenotype) + adjustedValue);
    }

    public double getPhenotypeFitness(Phenotype phenotype) {
        return phenotypeFitnesses.getOrDefault(phenotype, 0.0);
    }

    /**
     * Increment the team fitness.
     * @param value the unadjusted resource value
     */
    public void addToTeamFitness(double value) {
        teamFitness += value;
    }

    /** Gets the normalized team fitness (out of 120 if stepsTaken is provided; out of 100 otherwise) */
    public double getTeamFitness(Optional<Long> stepsTaken) {
        return (teamFitness / totalResourceValue) * 100 + (stepsTaken.orElse(0L) / maxSteps) * 20;
    }

    public Map<Phenotype,Double> getPhenotypeFitnessMap() {
        return phenotypeFitnesses;
    }

    public double getTotalResourceValue() {
        return totalResourceValue;
    }
}

@@ -77,35 +77,8 @@
 Map;
-%0Aimport java.util.Optional;
 %0A%0Aim
@@ -1278,67 +1278,40 @@
 ess 
-(out of 120 if stepsTaken is provided; out of 100 otherwise
+including time bonus (out of 120
 ) */
@@ -1347,23 +1347,26 @@
 ness
-(Optional%3CL
+WithTimeBonus(l
 ong
-%3E
  ste
@@ -1449,19 +1449,8 @@
 aken
-.orElse(0L)
  / m
@@ -1460,13 +1460,171 @@
 teps
+) * 20;%0A    %7D%0A%0A    /** Gets the normalized team fitness (out of 100) */%0A    public double getTeamFitness() %7B%0A        return (teamFitness / totalResourceValue
 ) * 
-2
+10
 0;%0A 

Add separate methods for fitness with and without time bonus