Package fmg.fmg8.endlAutomat.fitness

Source Code of fmg.fmg8.endlAutomat.fitness.FitnessWallFollowNEU

/*
* Datei:            FitnessWallFollowNEU.java
* Autor(en):        Lukas K�nig
* Java-Version:     6.0
* Erstellt (vor):   24.09.2008
*
* (c) Lukas K�nig, die Datei unterliegt der LGPL
* -> http://www.gnu.de/lgpl-ger.html
*/

package fmg.fmg8.endlAutomat.fitness;

import fmg.fmg8.umgebung2D.Roboter;
import fmg.fmg8.umgebung2D.Vektor2D;

/**
* Fitnessberechnung nach Mark Schimanski zum Verfolgen von W�nden.
*
* @author Lukas K�nig
*/
public class FitnessWallFollowNEU implements FitnessVerfahren {

    /**
     * �berschreibung des Default-Konstruktors.
     */
    public FitnessWallFollowNEU() {
        throw new RuntimeException("Fitness nicht ausgew�hlt.");
    }
   
    /**
     * Berechnet den Fitnesssnapshot.
     *
     * @param rob  Der Roboter, dessen Fitness berechnet werden soll.
     *
     * @return  die Fitness.
     */
    public int fitness(final Roboter rob) {

        // Wall-Follow:
        final double epsilon = 0.1;
        int wf = 0;
        Vektor2D blick = new Vektor2D(rob.getBlickrichtung());
        blick.normal();
//        if (Math.abs(blick.y) < epsilon) {
        if (Math.abs(blick.x) < epsilon || Math.abs(blick.y) < epsilon) {
            wf++;
        } else {
            wf--;
        }

        // Aus Collision avoidance (nur MOVE-Teil):
        int bef0 = ((Integer) rob.getBefehle().get(0)).intValue();
        String befehl0 = fmg.fmg8.umgebung2D.Konstanten.BEF[bef0].toUpperCase();
        int fitCollAvoid = 0;

        if (!befehl0.equals("MOV")) {
            fitCollAvoid--;
        }
       
        return fitCollAvoid + wf;
    }

    /**
     * Die toString-Methode.
     *
     * @return Die Ausgabe.
     */
    public String toString() {
        return "FitnessSwapHalfs";
    }
}
TOP

Related Classes of fmg.fmg8.endlAutomat.fitness.FitnessWallFollowNEU

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.