 (defn bounded-coords? [[x y]]
   (and (>= x 0) (< x dim) (>= y 0) (< y dim)))
 
+(defn manhattan [p1 p2]
+  (map #(clojure.contrib.math/abs (- %1 %2)) p1 p2))
+
+(defn distance [p1 p2]
+  (apply + (manhattan p1 p2)))
+
 (defn location [board [x y]]
   (nth board (+ (* x dim) y)))
 
 (defn position [board piece]
-  (.indexOf board piece))
+  (first (clojure.contrib.seq/positions #(= piece %) board)))
 
 (defn coords [board piece]
   (let [pos (position board piece)]

(def dir-delta {:up [0 1] :down [0 -1]
                :left [-1 0] :right [1 0]})

(defn adjacent-coords [board [x y]]
  (let [adj-loc (map (fn [[dx dy]] [(+ x dx) (+ y dy)])
                     (vals dir-delta))]

       (adjacent-coords board (coords board piece))))

(defn adjacent? [board p1 p2]
  (= 1 (distance (coords board p1) (coords board p2))))

(defn can-move? [board piece]
  (adjacent? board 0 piece))
