               :handler on-play-card
               :error-handler on-error}))
 
-(defn move-back [state response]
+(defn move-back [state board response]
   (assoc state :board board
          :draw-pile (:draw-pile response)
          :discard-pile (:discard-pile response)

  (reset! app-state response))

(defn new-game [state]
  (let [players (cond-> []
                        (get-name :black) (conj {:name (get-name :black) :color :black})
                        (get-name :blue) (conj {:name (get-name :blue) :color :blue})
                        (get-name :green) (conj {:name (get-name :green) :color :green})
                        (get-name :orange) (conj {:name (get-name :orange) :color :orange})
                        (get-name :red) (conj {:name (get-name :red) :color :red}))]
    (dissoc state :selected-players)))

(defn new-game! []
  (swap! app-state new-game)
  (swap! names empty-names)
  (ajax/POST "http://localhost:3000/new-game"
             {:params {:players (shuffle players)}
              :handler on-new-game
              :error-handler on-error}))

(defn select-players [state]
  (assoc state :select-players true))


(defn update-active-player [state response]
  (assoc state :actions-remaining (:actions-remaining response)
               :current-player (:current-player response)))

(defn on-update-active-player [response]
  (swap! app-state update-active-player response))
