 (def simul-steps 100) ; Steps to allow the robot to make in a simulation.
 (def tiles [\w \p \g]) ; Tiles that populate the map: wall, path, and gold.
 (def actions [\u \d \l \r \x \p]) ; Actions the robot can take: up, down, left, right, pick up.
-(def dir-vects ['(0 -1) '(0 1) '(-1 0) '(1 0) '(0 0)]) ; Direction vectors, corresponding to the actions.
+(def dir-vects ['(0 -1) '(0 1) '(-1 0) '(1 0) '(0 0)]) ; Direction vectors, corresponding to the 4 actions.
 
 (def mutation-prob 5) ; Probability in 100 that a gene will mutate.
 (def action-penalty 5) ; How many points robot loses when hitting the wall or picking up when it shouldn't.


(defn set-tile [the-map pos tile]
  "Returns a copy of the map where the tile on pos has been replaced."
  (let [[x y] (vec pos)]
    (def new-row (assoc (nth the-map y) x tile))
    (assoc the-map y new-row)))

(defn get-tile-index [t]



; DNA functions
(defn rand-gene []
  "Returns a random gene."
  (rand-nth actions))

(defn rand-dna []
  "Initializes a vector of random DNA."
  (vec (repeatedly (** (count tiles) 5) rand-gene)))

(defn cross [a b]
  "Crosses two vectors of DNA."
  (let [choose-rand (fn [x y] (if (< (rand-int 100) 50) x y))]
    (mapv choose-rand a b)))

(defn mutate [dna]
  "Randomly replace some genes in the DNA."
  (let [mutate-gene (fn [gene] (if (< (rand-int 100) mutation-prob) (rand-gene) gene))]
    (mapv mutate-gene dna)))


; Fitness evaluation functions
(defn rand-map []
  "Initializes a map with walls at the boundaries and randomly positioned gold."
  (let [last-coord (- map-size 1)
        map-coords (vec (range map-size))
        gen-tile (fn[x y]
                   (if (or (= x 0) (= y 0) (= x last-coord) (= y last-coord))
                     \w
                     (if (< (rand-int 100) gold-prob) \g \p)))]
    (mapv (fn [y] (mapv (fn [x] (gen-tile x y)) map-coords)) map-coords)))

(defn get-tile [the-map pos]
  "Given a map and coordinates, evaluates to what is on the map at the position."
