    In that case nil is returned."
   [tile-fn board direction]
   (let [board' (slide-synth board direction)]
-    (when (not= board board') (add-tile tile-fn board'))))
+    (when (not= board board') (add-tile (tile-fn) board'))))
 
 ;; Sadly, moves can’t be made indefinitely. As stated in the 'Tile synthesis'
 ;; section, the player wins the game when a tile that is not able to be merged

;;   :wait action. In other words, we’ll keep waiting for a valid move.

(let [keys (keys-chan)]
  (go-loop [board (initial-board build-tile)
            action :render]
    (case action
      :render (do (render board :slide)

  [v]
  (-> v nil-indexes shuffle first))

;; Then, we associate the index with a new tile in the board representation. The
;; tile must be provided because we don't really care about its details.

(defn add-tile
  "Takes a board and returns a new one with one empty square replaced by tile."
  [tile board]
  (assoc board (rand-nil-index board) tile))

;; All the conditions are now met to build a board with two tiles, which is
;; necessary for the player to make the first move.

(defn initial-board
  "Returns a board with two tiles (tile-1 and tile-2) in random positions."
  [tile-1 tile-2]
  (->> empty-board (add-tile tile-1) (add-tile tile-2)))

;; # Tile synthesis

