   [piece x y board]
   (every? #(coord-fits? % x y board) (:coords piece)))
 
-; ------------------------------------------------------------
-; DRAWING FUNCTIONS
-; ------------------------------------------------------------
-
-(def sq-size 20)
-
-(defn size-canvas []
+;;------------------------------------------------------------
+;; PAINTING (for showing the game on a canvas)
+;;------------------------------------------------------------
+
+(defn size-canvas
+  "Set the size of the canvas."
+  []
   (let [canvas (.getElementById js/document "canvas")]
-    (aset canvas "width" (* sq-size 10))
-    (aset canvas "height" (* sq-size 22))))
+    (aset canvas "width" (* cell-size 10))
+    (aset canvas "height" (* cell-size 22))))
+
+(defn get-cell-color
+  "Get the color for the given cell value."
+  [value]
+  (if (zero? value) "#EEE" "#CC0000"))
 
 (defn draw-cell
   "Draw the given cell of the given board."
   [ctx x y board]
   (let [color (get-cell-color (read-board x y board))
-        left (* sq-size x)
-        top  (* sq-size y)]
+        left (* cell-size x)
+        top  (* cell-size y)]
     (aset ctx "fillStyle" color)
-    (.fillRect ctx left top sq-size sq-size)))
+    (.fillRect ctx left top cell-size cell-size)))
 
 (defn draw-board
   "Draw the given board to the canvas."

      (draw-cell ctx x y board))
    nil))

(defn create-drawable-board
  "Creates a new drawable board, by combining the current piece with the current board."
  []

   :O {:name :O :coords [[0 0] [-1 0] [-1 1] [0 1]]}
   :T {:name :T :coords [[0 0] [-1 0] [1 0] [0 1]]}})

(defn get-rand-piece
  "Return a random piece."
  []
  (pieces (rand-nth (keys pieces))))

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

(def empty-board [[0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]
                  [0 0 0 0 0 0 0 0 0 0]])

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

(defn coord-inside?
  "Determines if the coordinate is inside the board."
  [x y]
  (and (<= 0 x 9) (<= 0 y 21)))


; The size of a cell in pixels.
(def cell-size 20)

;;------------------------------------------------------------
;; Pure Functions operating on a board.
;;------------------------------------------------------------

(defn read-board
  "Get the current value from the given board position."
  [x y board]
  (get-in board [y x]))

(defn write-to-board
  "Returns a new board with a value written to the given position."
