   (println "Trying to buy " b-name))
 
 (defn building-tile [b-name]
-    (let [building (b-name (:buildings @game))]
-      [:div.building {:class [(:resource building)]
-                      :on-click #(buy-building b-name)}
-       [:h5.pull-left (name b-name)]
-       
-       [:span.pull-right (gold (:cost building))]
-       [:span.pull-right (vp (:vp building))]
-       
-       [:div.clearfix]
-       [:div.pull-left (circles (:workers building))]
-       [:div.building-count.pull-right (:count building) "x"]
-       [:div.clearfix]
-       ]))
+  (let [building (b-name (:buildings @game))]
+    [:div.building {:class [(:resource building)]
+                    :on-click #(buy-building b-name)}
+     [:h5.pull-left (name b-name)]
+
+     [:span.pull-right (gold (:cost building))]
+     [:span.pull-right (vp (:vp building))]
+
+     [:div.clearfix]
+     [:div.pull-left (circles (:workers building))]
+     [:div.building-count.pull-right (:count building) "x"]
+     [:div.clearfix]
+     ]))
 
 (defn building-board []
   [:table


(defn render-ship [size type]
  [:div.ship
    (repeat size [:div.box {:class type}])
    [:div.clearfix]])

(defn render-trader [trader]
  [:div.ship
    [:div.box {:class type}]
    [:div.box {:class type}]
    [:div.box {:class type}]
    [:div.box {:class type}]
    [:div.clearfix]])

(defn player-board [player]
  [:div
   (if (:role player)
     [:div.rolecard (name (:role player))])
      [:div.well
        [:div.pull-left (:name player)]
        [:span.pull-right (gold (:gold player))]
        [:span.pull-right (vp (:vp player))]
        [:div.clearfix]
        [:h5 "Buildings"]
        (for [building (:buildings player)]
            [:div (:name building)])
        [:h5 "Fields"]
        (for [field (:fields player)]
            [:div.field {:class (name field)} (name field)])
        ]])

(defn current-role []
  (let [last-role-event
      (first 
          (filter
            (fn [event]
              (contains? #{:rolestart :roleend} (first event)))
            (rseq (:log @game))))]
      (println last-role-event)
      (if (= :rolestart (first last-role-event))
          (second last-role-event))))

(defn player-boards []
  [:div.row
   (for [player (:players @game)]
     [:div.col-md-3
        (player-board player)])])

(defn game-log []
    [:div
  (for [event (:log @game)]
    [:div (pr-str event)])])

(defn get-field [field-type i]
  (when (= :settler (current-role))

(defn player-pick-role [role]
  (let [cstate @game
        governor (:governor cstate)]
    (swap! game update-in [:log] conj [:rolestart role (:governor @game)])
    (swap! game update-in [:players governor] assoc :role role)
    (swap! game update-in [:roles] disj role)))

(defn roles-board []
  [:div
   (for [role (:roles @game)]
     [:div.rolecard {:on-click #(player-pick-role role)}
      (name role)
      [:span " - " (role role-descriptions)]])])

(defn supply-board []
  (let [current @game]
    [:div
     [:i.fa.fa-trophy (:vp current)]
     [:div "Colonist Supply: " (:colonists current)]
     [:div "Colonist Ship: " (:colonist-ship current)]
     [:h3 "Ships"]
     (for [ship (:ships current)]
       (render-ship ship))
     [:h3 "Trader"] (render-trader (:trader current))
     [:h3 "Fields"]
     [:div.quarry.field {:on-click #(get-field :quarry nil)} (:quarry current) " Q"]
     (map-indexed (fn [i field]
                    [:div.field {:class (name field)
                                 :on-click #(get-field field i)} (name field)]
                    )
                  (:available-fields current))
     #_[:h3 "It is " (active-player) "'s turn"]
     #_[:h3 "Current role: " (current-role)]]))

(defn game-state []
  [:blockquote (pr-str @game)])
