 (defn convert-to-int [float-value]
   (Integer/valueOf (Math/round float-value)))
 
+(defn after [val1 val2] (if (> (- val2 val1) 0) true false))
+(defn before [val1 val2] (if (< (- val2 val1) 0) true false))
+
+(defn compute-x [x next-checkpoint-x next-checkpoint-angle next-checkpoint-distance]
+  (if (> next-checkpoint-distance 1000)
+    (cond
+      (and (>= next-checkpoint-angle -90) (<= next-checkpoint-angle 90) (before next-checkpoint-x x))
+      (convert-to-int (+ next-checkpoint-x (* checkpoint-core-size (Math/cos next-checkpoint-angle))))
+      (and (>= next-checkpoint-angle -90) (<= next-checkpoint-angle 90) (after next-checkpoint-x x))
+      (convert-to-int (- next-checkpoint-x (* checkpoint-core-size (Math/cos next-checkpoint-angle))))
+      (or (<= -180 next-checkpoint-angle -90 ) (>= 180 next-checkpoint-angle 90))
+      (convert-to-int (- next-checkpoint-x (* checkpoint-core-size (Math/cos next-checkpoint-angle)))))
+    next-checkpoint-x))
+
+(defn compute-y [y next-checkpoint-y next-checkpoint-angle next-checkpoint-distance]
+  (if (cond
+        (and (>= next-checkpoint-angle 0)  (<= next-checkpoint-angle 180)) (convert-to-int (- next-checkpoint-y (* checkpoint-core-size (Math/sin next-checkpoint-angle))))
+        (and (< next-checkpoint-angle 0) (>= next-checkpoint-angle -180)) (convert-to-int (+ next-checkpoint-y (* checkpoint-core-size (Math/sin next-checkpoint-angle)))))
+    next-checkpoint-y))
+
 ;;Angle entre 2 points (x1,y1) et (x2,y2)
 (defn angle-between-2-points [x1 y1 x2 y2]
   (let [d (distance x1 y1 x2 y2) dx (/ (- x2 x1) d) dy (/ (- y2 y1) d) angle (convert-radian-to-degree (Math/acos dx))]
     (if (< dy 0) (- 360.0 angle) angle)))
-
-(defn after [val1 val2] (if (> (- val2 val1) 0) true false))
-(defn before [val1 val2] (if (< (- val2 val1) 0) true false))
 
 (defn compute-boost-from-angle [next-checkpoint-angle]
   (str (convert-to-int (* (Math/sin (convert-degree-to-radian (Math/abs next-checkpoint-angle))) 100))))

(ns Player
  (:gen-class))

(defn inc-atom [curr-val] (inc curr-val))
(defn dec-atom [curr-val] (dec curr-val))

        ; You have to output the target position
        ; followed by the power (0 <= thrust <= 100)
        ; i.e.: "x y thrust"
        (print (compute-x x nextCheckpointX nextCheckpointAngle nextCheckpointDist))
        (print " ")
        (print (compute-y y nextCheckpointY nextCheckpointAngle nextCheckpointDist))
        (print " ")
        (reset! last-boost-value
                (compute-action
