   []
   (swap! state assoc :piece (get-rand-piece)
                      :position start-position))
+
+(defn try-collapse!
+  "Try to collapse any full rows on the current board."
+  []
+  (let [board (:board @state)
+        cleared-board (remove #(every? cell-filled? %) board)
+        n (- (count board) (count cleared-board))
+        new-board (into (vec (repeat n empty-row)) cleared-board)]
+    (swap! state assoc :board new-board)))
 
 (defn go-go-gravity!
   "Starts the gravity routine."

          (swap! state assoc-in [:position 1] ny)
          (do
            (swap! state assoc :board (write-piece-to-board piece x y board))
            (spawn-piece!))))
      (recur))))


;; Board.
;;------------------------------------------------------------

(def empty-row (vec (repeat 10 0)))
(def empty-board (vec (repeat 22 empty-row)))

; The starting position of all pieces.
(def start-position [4 2])
