/* @(#)MoveFitness.java
 */
/**
 *  Class containing all of the business logic regarding whether a
 *  move is considered good or not.
 *
 * @author <a href="mailto:geoff@minty-dark-tower">Geoff Shannon</a>
 */

package wall_follower;

public class MoveFitness {

    private static final float MIN_GOOD_DISTANCE = 0.1f;
    private static final float MAX_GOOD_DISTANCE = 0.15f;

    private int goodMoves;
    private int badMoves;

    public MoveFitness() {
        goodMoves = 0;
        badMoves = 0;
    }

    /**
     *  Overall, the way that we score moves is this: there is a
     *  predefined "good" range.  If the move caused us to stay in
     *  that range, then it was good.  If we were outside the range,
     *  then if the move put us closer to that range it was good.
     *  Otherwise, it was a bad move.
     */
    public void scoreMove(SensorReading before, SensorReading after) {

        if (inGoodRange(before.distance)) {
            if (inGoodRange(after.distance)) {
                goodMoves++;
            } else {
                badMoves++;
            }
        } else {
            // If deltaDistance is positive then we moved away from
            // the wall, if it is negative then we moved closer.
            float deltaDistance = after.distance - before.distance;

            // If we were too close, and got farther away: good
            if (before.distance < MIN_GOOD_DISTANCE &&
                deltaDistance > 0) {
                goodMoves++;
            // Or if we were too far and got closer: good
            } else if (before.distance > MAX_GOOD_DISTANCE &&
                       deltaDistance < 0) {
                goodMoves++;

            } else {
                badMoves++;
            }
        }
    }

    public float getFitness() {
        if (badMoves == 0)
            return goodMoves;
        return goodMoves / badMoves;
    }

    private static boolean inGoodRange(float distance) {
        return (distance >= MIN_GOOD_DISTANCE) &&
            (distance <= MAX_GOOD_DISTANCE);
    }
}

@@ -233,32 +233,97 @@
 r;%0A%0A
-public class MoveFitness
+import java.lang.Comparable;%0A%0Apublic class MoveFitness implements Comparable%3CMoveFitness%3E
  %7B%0A%0A
@@ -2116,10 +2116,167 @@
 ;%0A    %7D%0A
+%0A    @Override%0A    public int compareTo(MoveFitness m) %7B%0A        Float mine = new Float(getFitness());%0A        return mine.compareTo(m.getFitness());%0A    %7D%0A%0A
 %7D%0A

Make MoveFitness comparable