 (defn play-move
   "On player playing the move [x y]"
   [{:keys [player board] :as game} [x y]]
-  (if-let [moves (get (available-moves-at board [x y]) player)]
+  (if-let [moves (get-in game [:moves [x y] player])]
     (-> game
       (apply-moves (conj moves (take-empty-cell-move player [x y])))
+      (with-available-moves)
       (update-in [:player] next-player)) ;; TODO - We must compute the available moves to switch player
     game))
 

    (fn [r [color [x y]]] (assoc-in r [x y] color))
    empty-board (init-positions)))

(defn new-game []
  {:board (new-board)
   :turn 0
   ;; From the turn you can deduce the number of turn left
   ;; There is an invariant holding: total score = 12 * 3 + turn
   ;; TODO - Enhance the display to show the available moves (compute them once)
   :player (rand-nth players)
   :scores
   {:blue 12
    :red 12
    :green 12}})


;; -----------------------------------------
;; TAKING CELLS
;; -----------------------------------------

(defn range-single-coord

   :looser :empty
   :taken [pos]})

(defn with-available-moves
  "Compute all available moves on the board"
  [{:keys [board] :as game}]
  (merge game
    {:moves
     (into {}
       (map (juxt identity #(available-moves-at board %)))
       all-positions)}
    ))


;; -----------------------------------------
;; ON PLAYER MOVE
