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

    (render [_]
      (dom/div #js {:className "blue-team"}))))

(defn tile-view [cursor owner]
  (reify
    om/IRenderState
    (render-state [this {:keys [x y move] :as position}]
      (let [found (find-piece position)]
        (dom/td #js {:onClick #(put! move position)}
          (cond
            (= (:type found) :my-team)
              (om/build player-view found {:state {:move move}})
            (= (:type found) :opponent)
               (om/build opponent-view cursor)
            (= (:type found) :loose-ball)
               (om/build ball-view cursor)))))))

(defn ball-view [cursor owner]
  (reify
    om/IRender
    (render [_]
          (dom/div #js {:className "ball"}))))

(defn board-view [app owner]
  (reify
     om/IInitState
     (init-state [_]
       {:move (chan)})
    om/IWillMount
    (will-mount [_]
      (let [move (om/get-state owner :move)]
        (go (loop []
          (let [player-to-move (find-piece (<! move))]
            (let [{:keys [x y] :as position} (<! move)]
              (if (find-piece position)
                (println "CAN'T MOVE THERE")
                (om/transact! app :cells
                  (fn [cs]
                    (vec (map
                           #(if (= player-to-move %)
                                  (assoc % :x x :y y)
                                  %)
                         cs)))))))
            (recur)))))
    om/IRenderState
    (render-state [this {:keys [move]}]
      (dom/div #js {:className "container"}


(defonce app-state (atom
                    {:cells
                        {: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)
