   (merge state {:editing? false
                 :selected nil}))
 
+
+(defn reset-stats
+  [world-state]
+  (merge world-state
+         {:stats {:runs 0,
+                  :success 0}}))
+
+
 (defn toggle-button-text
   [buttid condition valid invalid]
   (dommy/set-text! (dommy.core/sel1 buttid)

   reader/read-string
   reset-edit
   reset-random
   remember-initial-state
   make-flips-matter))

(go
  (listen-on-slider-change)

         (:edges world-state))))


(defn any-target-flipped?
  [world-state]
  (->>
   [(:initial world-state) world-state]
   (map get-target-edges)
   (apply merge-with not=)
   vals
   (some true?)))


(defn move-randomly
  [world-state]
  (swap! ticker dec)
  (if (neg? @ticker)
    (do 
      (reset! ticker @interval)
      (if (any-target-flipped? world-state)
        (update-in (reset-to-initial world-state)
                   [:stats] (partial  merge-with + {:runs 1, :success 1}))
        (if-let [m (get-random-legal-move-name world-state)]
          (flip-update-edge m world-state)
          (update-in (reset-to-initial world-state)
                     [:stats :runs] inc)
          )))
    world-state))


