              :color [1 0 0]
              :energy child-bird-energy-cost
              :position position
-             :friendliness friendliness)
+             :genome genome)
       (make-collision-shape)))
 
+(defn random-bird-genome
+  "Returns a random bird genome. Genome is [ friend_weight food_weight ]"
+  []  
+  [ (- (* 2 (lrand)) 1) (lrand) ])
+
+(defn mutate-bird-genome
+  "Returns a mutant bird genome. "
+  [genome]
+  (let [g1 (+ (first genome) (* 0.02 (lrand)) -0.01)
+        g2 (+ (second genome) (* 0.02 (lrand)) -0.01)]
+	  [(cond (> g1 1) 1
+	         (< g1 -1) -1
+	         :else g1)
+	   (cond (> g2 1) 1
+	         (< g2 0) 0
+	         :else g2)]))
+  
 (defn random-bird
   "Make a new random bird."
   []
-  (let [friendliness (lrand)]
-    (make-bird friendliness (random-bird-position))))
+  (make-bird (random-bird-genome) (random-bird-position)))
 
 (defn bound-acceleration
   "Keeps the acceleration within a reasonable range."

  (let [state (report state)
        objects (handle-collisions (:objects state) collision-handlers)
        updated-objects (doall (filter inside-boundary? (update-objects objects (:iteration-step-size state))))
        num-birds-to-add (- minimum-num-birds
                            (count (filter bird? updated-objects)))]
    (assoc state
      :simulation-time (+ (:simulation-time state) (:iteration-step-size state))
      :objects (concat updated-objects
                       (when (pos? num-birds-to-add)
                         (repeatedly num-birds-to-add random-bird))))))

(start-gui 0.01 update)

(defn eval-bird
  "Evaluate a bird to decide what to do."
  [bird nbrs]
  (let [nbr-bird (some #(when (bird? %) %) nbrs)
        nbr-food (some #(when (food? %) %) nbrs)
        dir-to-bird (sub (:position nbr-bird) (:position bird))
        dir-to-food (sub (:position nbr-food) (:position bird))]
    (assoc bird
           :acceleration (add (:acceleration bird) 
                              (mul dir-to-bird (first (:genome bird)))
                              (mul dir-to-food (second (:genome bird)))))))

(defn fly
  "Change the acceleration of a bird."
