         n (- (count board) (count cleared-board))
         new-board (into (vec (repeat n empty-row)) cleared-board)]
     (swap! state assoc :board new-board)))
+
+(defn lock-piece!
+  "Lock the current piece into the board."
+  []
+  (let [[x y] (:position @state)
+        piece (:piece @state)
+        board (:board @state)]
+    (swap! state assoc :board (write-piece-to-board piece x y board))
+    (try-collapse!)
+    (spawn-piece!)))
 
 (defn go-go-gravity!
   "Starts the gravity routine."

           (= code (:down key-codes))  (do (try-move!  0  1) (.preventDefault e))
           (= code (:left key-codes))  (do (try-move! -1  0) (.preventDefault e))
           (= code (:right key-codes)) (do (try-move!  1  0) (.preventDefault e))
           (= code (:up key-codes))    (do (try-rotate!)     (.preventDefault e)))))))

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

  [piece x y board]
  (every? #(coord-fits? % x y board) (:coords piece)))

(defn get-drop-pos
  "Get the future drop position of the given piece."
  [piece x y board]
  (let [collide? (fn [cy] (not (piece-fits? piece x cy board)))
        cy (first (filter collide? (iterate inc y)))]
    (dec cy)))

;;------------------------------------------------------------
;; PAINTING (for showing the game on a canvas)
;;------------------------------------------------------------
