package hwo.kurjatturskat.ai.drivers;

import hwo.kurjatturskat.model.World;

public class MarkusBot implements Driver {
    private double lastThrottle = -1;

    @Override
    public double getThrottle(World world) {
        /*
         * Config to get absolute max speed: keimola When the straight start
         * speed up and store the max speed.
         * 
         * New recordSpeed: 9.483289941799981
         */
        if (world.getTrackModel().getTrackName().equals("Keimola")
                && (world.getPreviousPosition().pieceIndex > 33 || world
                        .getPreviousPosition().pieceIndex < 4)) {
            return 1;
        }

        /*
         * Stop the car from some speed.. get the distance.
         */
        // if (world.getTrackModel().getTrackName().equals("Keimola")) {
        // if ((world.getMyRaceTime().getCurrentLap() == 0 && world
        // .getPreviousPosition().pieceIndex > 37)
        // || (world.getMyRaceTime().getCurrentLap() == 1 && world
        // .getPreviousPosition().pieceIndex < 2)) {
        // System.out.println("Stop at speed: " + world.getMySpeed());
        // return 0;
        // }
        // }
        int nSwitch = world.getTrackModel().getNextSwitch();
        int nnSwitch = world.getTrackModel().getNextSwitchByIndex(nSwitch);

        if (world.getTrackModel().getCurrent().isCurve()) {
            if (lastThrottle != 0.2) {
                System.out.println("Seems like a curve. Lets slow down.");
                System.out.println("Next switch: " + nSwitch + " " + nnSwitch);
                System.out.println("Lane0: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 0));
                System.out.println("Lane1: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 1));
                System.out.println("Lane2: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 2));
            }
            lastThrottle = 0.2;
            return 0.2;
        } else {
            if (lastThrottle != 1) {
                System.out.println("We are on straight. Step on it!");
                System.out.println("Next switch: " + nSwitch + " " + nnSwitch);
                System.out.println("Lane0: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 0));
                System.out.println("Lane1: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 1));
                System.out.println("Lane2: "
                        + world.getTrackModel().getLaneDistanceBetweenPieces(
                                nSwitch, nnSwitch, 2));

            }
            lastThrottle = 1;
            return 1;
        }

    }

    @Override
    public String getLane(World world) {
        return null;

        // return null;
    }

}

@@ -1551,32 +1551,33 @@
  %22 + nnSwitch);%0A
+%0A
                 
@@ -1580,171 +1580,64 @@
     
-System.out.println(%22Lane0: %22%0A                        + world.getTrackModel().getLaneDistanceBetweenPieces(%0A                                nSwitch, nnSwitch, 0));%0A
+for (int i = 0; i %3C world.getLanes().length; i++) %7B%0A    
     
@@ -1664,35 +1664,32 @@
 ut.println(%22Lane
-1: 
 %22%0A              
@@ -1702,163 +1702,62 @@
     
-+ world.getTrackModel().getLaneDistanceBetweenPieces(%0A                                nSwitch, nnSwitch, 1));%0A                System.out.println(%22Lane2: %22%0A
+    + i%0A                            + %22: %22%0A           
     
@@ -1761,39 +1761,32 @@
                 
-       
 + world.getTrack
@@ -1784,32 +1784,69 @@
 .getTrackModel()
+%0A                                    
 .getLaneDistance
@@ -1851,32 +1851,40 @@
 ceBetweenPieces(
+nSwitch,
 %0A               
@@ -1896,32 +1896,35 @@
             
-nSwitch,
+           
  nnSwitch, 2
@@ -1922,21 +1922,39 @@
 Switch, 
-2
+i
 ));%0A
+                %7D%0A
         
@@ -2240,171 +2240,64 @@
     
-System.out.println(%22Lane0: %22%0A                        + world.getTrackModel().getLaneDistanceBetweenPieces(%0A                                nSwitch, nnSwitch, 0));%0A
+for (int i = 0; i %3C world.getLanes().length; i++) %7B%0A    
     
@@ -2336,11 +2336,8 @@
 Lane
-1: 
 %22%0A  
@@ -2362,163 +2362,62 @@
     
-+ world.getTrackModel().getLaneDistanceBetweenPieces(%0A                                nSwitch, nnSwitch, 1));%0A                System.out.println(%22Lane2: %22%0A
+    + i%0A                            + %22: %22%0A           
     
@@ -2421,39 +2421,32 @@
                 
-       
 + world.getTrack
@@ -2448,24 +2448,61 @@
 TrackModel()
+%0A                                    
 .getLaneDist
@@ -2519,16 +2519,24 @@
 nPieces(
+nSwitch,
 %0A       
@@ -2560,24 +2560,27 @@
         
-nSwitch,
+           
  nnSwitc
@@ -2586,13 +2586,30 @@
 ch, 
-2
+i
 ));%0A
+                %7D
 %0A   

Fix lanes accroding to track.