 (defn new-game []
   (list (with-ai-data (turn/new-init-turn))))
 
+(defn get-turn
+  [game-turns]
+  (first game-turns))
+
+(defn play-turn
+  [game-turns coord]
+  (conj game-turns
+    (turn/play-move (get-turn game-turns) coord)))
+
 (defn cancel-last-move ;; TODO - It needs the ai: how to move it in the game? undo then undo-while
   [old-turns]
   (let [ai-turn? #(contains? (:ai-players %) (:player %))


(def ai-move-delay 1000)

(defn update-game! [f & args]
  (swap! app-state update-in [:games] conj (apply f @game args)))

(defn- handle-ai! []
  (let [ai-algo (get @ai-players @current-player)
        move (ai-algo @game @current-player)]
    (update-game! turn/play-move move)))

(defn- handle-game-event!
  [msg]

      (while true
        (alt!
          game-events ([msg] (handle-game-event! msg))
          player-events ([coord] (play-game-turn! coord))
          (async/timeout ai-move-delay) ([_] (if (is-ai? @current-player) (handle-ai!)))
          )))

