         new-board (into (vec (repeat n empty-row)) cleared-board)]
     (swap! state assoc :board new-board)))
 
+(defn go-go-collapse!
+  []
+  (let [board (:board @state)
+        rows (get-filled-row-indices board)]
+
+    (js/console.log "Collapsing?")
+    (when (> (count rows) 0)
+      (js/console.log "YES")
+      (swap! state assoc :animating true)
+      (go
+        ; blink n times
+        (doseq [i (range 3)]
+          (js/console.log "Blink" i)
+
+          (<! (timeout 100))                            ; resume here in 0.5 seconds
+          (swap! state assoc :highlighted-rows rows)    ; highlight rows
+          (<! (timeout 100))                            ; resume here in 0.5 seconds
+          (swap! state assoc :highlighted-rows #{}))     ; unhighlight rows
+
+        ; finally collapse
+        (js/console.log "Collapsing.")
+        (collapse-rows!)
+        (swap! state assoc :animating false)))))
+
 (defn lock-piece!
   "Lock the current piece into the board."
   []

        ghost (assoc piece :name :G)
        gy    (get-drop-pos piece x y board)
        board1 (write-piece-to-board ghost x gy board)
        board2 (write-piece-to-board piece x y board1)]
    board2))

(defn draw-state
  "Draw the current state of the board."

  (go
    (loop []
      (<! (timeout 1000))
      (when-not (:animating @state)
        (let [[x y] (:position @state)
              piece (:piece @state)
              board (:board @state)
              ny (inc y)]
          (if (piece-fits? piece x ny board)
            (swap! state assoc-in [:position 1] ny)
            (lock-piece!))))
      (recur))))

;;------------------------------------------------------------
