 
 (defonce app-state (atom
                     {:cells
-                      [{:type :opponent :x 0, :y 0}
-                       {:type :opponent :x 2, :y 0}
-                       {:type :opponent :x 4, :y 0}
-                       {:type :opponent :x 6, :y 0}
-                       {:type :opponent :x 8, :y 0}
-                       {:type :my-team :x 0, :y 8}
-                       {:type :my-team :x 2, :y 8}
-                       {:type :my-team :x 4, :y 8}
-                       {:type :my-team :x 6, :y 8}
-                       {:type :my-team :x 8, :y 8}
-                       {:type :loose-ball :x 0, :y 4}
-                       {:type :loose-ball :x 2, :y 4}
-                       {:type :loose-ball :x 4, :y 4}
-                       {:type :loose-ball :x 6, :y 4}
-                       {:type :loose-ball :x 8, :y 4}]
-                    :selected-unit {}}))
+                        {:blue-team
+                         [{:x 0, :y 0}
+                          {:x 2, :y 0}
+                          {:x 4, :y 0}
+                          {:x 6, :y 0}
+                          {:x 8, :y 0}]
+                        :red-team
+                         [{:x 0, :y 8}
+                          {:x 2, :y 8}
+                          {:x 4, :y 8}
+                          {:x 6, :y 8}
+                          {:x 8, :y 8}]
+                        :balls
+                         [{:x 0, :y 4}
+                          {:x 2, :y 4}
+                          {:x 4, :y 4}
+                          {:x 6, :y 4}
+                          {:x 8, :y 4}]}}))
 
 (def board-size (range 0 9))
 (def bench-size 4)

          (vec (for [y board-size]
            (apply dom/tr #js {:className (border-top y)}
              (vec (for [x board-size]
                (om/build tile-view (:cells app)
                  {:state {:move move :x x :y y}})))))))
        (bench)))))


       (dom/td nil))))))

(defn find-piece [position]
  (let [{:keys [:blue-team :red-team :balls] :as units} (:cells (om/root-cursor app-state))]
    (first (filter #(and
                   (= (:x position) (:x %))
                   (= (:y position) (:y %)))
                 (flatten (vals units))))))

(defn coords [m]
  (dissoc m :move))

(defn all-units [cells]
  (let [{:keys [:blue-team :red-team :balls] :as units} (:cells (om/root-cursor app-state))]
  units))

(defn red-unit? [x y]
  (let [{:keys [:red-team]} (:cells (om/root-cursor app-state))]
    (first (filter #(and
             (= x (:x %))
             (= y (:y %)))
           red-team))))

(defn blue-unit? [x y]
  (let [{:keys [:blue-team]} (:cells (om/root-cursor app-state))]
    (first (filter #(and
             (= x (:x %))
             (= y (:y %)))
           blue-team))))

(defn ball? [x y]
  (let [{:keys [:balls]} (:cells (om/root-cursor app-state))]
    (first (filter #(and
             (= x (:x %))
             (= y (:y %)))
           balls))))

(defn highlight-tile [e]
 (set! (.. e -target -style -background) "gray"))

(defn player-view [cursor owner]
  (reify
