                    :height "133px"
                    :width "98px"}}]))
 
-(defn show-cards [hand]
+(defn show-cards
+  "Show all the cards in a hand."
+  [hand]
   (into [] (concat [:div {:class "cards"}]
                    (map (fn [x] (card-image hand x)) (range 0 (count hand))))))
 
-(defn tableau []
+(defn tableau
+  "Display the playing area (the tableau)."
+  []
   (let [{:keys [dealer-hand player-hand playing dealer-feedback player-feedback
                 player-money current-bet]} @game]
   [:div
-   [:h2 "Dealer’s Cards " [:span {:class "feedback"} dealer-feedback]]
+   [:h2 "Dealer’s Cards " [:span {:class "dealerFeedback"} dealer-feedback]]
    [show-cards dealer-hand]
    [:hr]
-   [:h2 "Your Cards " [:span {:class "feedback"} player-feedback]]
+   [:h2 "Your Cards " [:span {:class "playerFeedback"} player-feedback]]
    [show-cards player-hand]
    [:p
     [:input {:type "button"

                  :else :bust)])))

(defn immediate-win
  "Given player hand and dealer hand, return
  :none (nobody wins instantly)
  :tie (both have blackjack)
  :dealer-blackjack
  :player-blackjack"
  [player-hand dealer-hand]
  (let [[ptotal _] (evaluate-hand player-hand)
        [dtotal _] (evaluate-hand dealer-hand)]
    (or (= ptotal 21) (= dtotal 21))))

                    :else player-money)]
    (swap! game assoc :player-money new-money :current-bet (max 0 (min current-bet new-money)))))

(defn feedback
  "Given feedback for the dealer and player, update the reactive fields."
  [dealer player]
  (swap! game assoc :dealer-feedback dealer :player-feedback player))

(defn end-game
  "Evaluate the dealer's and player's hands when the
  game has ended."
  [dealer player]
  (let [[ptotal pstatus] (evaluate-hand player)
        [dtotal dstatus] (evaluate-hand dealer)]
;;    (println "Player:" player ptotal pstatus)
;;    (println "Dealer:" dealer dtotal dstatus)
    (cond
      (> ptotal 21) (feedback "Dealer wins." "Sorry, you busted.")
      (> dtotal 21) (feedback "Dealer goes bust." "You win!")
      (= ptotal dtotal) (feedback "" "Tie.")
      (= pstatus :blackjack) (feedback "" "You win with blackjack!")
      (= dstatus :blackjack) (feedback "Dealer has blackjack." "")
      (< ptotal dtotal) (feedback "Dealer wins." "")
      (> ptotal dtotal) (feedback "" "You win!")
      :else (feedback "" "Unknown result (Shouldn't happen.)"))
    (update-money dtotal dstatus ptotal pstatus)
    (swap! game assoc :playing false)))

(defn start-game
  "Deal two cards to the player (both face up), and two to the dealer (one
  face down and one face up). Update the game atom, and check for an immediate
  win."
  [event]
  (let [{:keys [deck discard-pile dealer-hand player-hand current-bet]} @game
        [player1 disc0] (discard [player-hand discard-pile])
        [dealer1 disc1] (discard [dealer-hand disc0])]
