           (turn/player-transitions turn)))
       )))
 
-#_(defn- play-best-move
-    "[SIMPLISTIC] Play the best move for a player based on:
-     * The immediate gain
-     * The worse immediate lost afterwards"
-    [game]
-    (let [turn (game/current-turn game)
-          ai (make-ai (:board turn) (:player turn))]
-      (:game
-        (max-by :scoring
-          (map
-            #(move-best-outcome ai game %)
-            (turn/player-transitions turn)))
-        )))
+
+;; -----------------------------------------
+;; TESTS
+;; -----------------------------------------
+
+(defn test-on-game
+  [g]
+  (let [turn (game/current-turn g)
+        ai (make-ai (:board turn) (:player turn))]
+    (tree-score ai (game/current-turn g) 2)))
+
+(defn test-score-tree [] (test-on-game (game/new-game)))
+
+(defn benchmark []
+  (time (dotimes [i 10]
+          (time (test-score-tree))
+          )))

    ))

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

(defn test-on-game
  [g]
  (let [turn (game/current-turn g)
        ai (make-ai (:board turn) (:player turn))]
    (tree-score ai (game/current-turn g) 2)))

(defn test-score-tree [] (test-on-game (game/new-game)))

(defn benchmark []
  (time (dotimes [i 10]
          (time (test-score-tree))
          )))

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

(defn- worst-possible-score-from
  [{:keys [player other-players] :as ai} moves]
  (transduce
    (comp
      (mapcat #(get moves %))
      (map #(score-move ai (second %)))
      (map #(get % player)))
    min
    other-players))

(defn- move-best-outcome
  [ai game [coord transition]]
  (let [new-game (game/play-move game coord)
        move-diff (get (score-move ai transition) (:player ai))
        new-moves (:transitions (game/current-turn new-game))
        next-diff (worst-possible-score-from ai new-moves)]
    {:scoring (+ move-diff next-diff)
     :game new-game}))

(defn- max-by [key-fn coll] (apply max-key key-fn coll))


;; -----------------------------------------
;; Public API
;; -----------------------------------------


(defn- make-ai
  [board player]
  {:player player
   :cell-weights (scoring/get-weighting board)              ;; TODO
   })

(defn- max-by [key-fn coll] (apply max-key key-fn coll))

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

