 (defn update-node [root path result]
   (-> root
       (update-in [path :visited] inc)
-      (update-in [path :score] #(+ % result))))
+      (update-in [path :score]
+                 (fn [x] (+ x (let [node (root path)]
+                            (cond
+                              (zero? result) 0.5
+                              (= result (:player node)) 1
+                              (not= result (:player node)) 0
+                              )))))))
 
 (defn backprop [root path result]
-  (if-not (empty? path)
+  (if-not (nil? path)
     (recur (update-node root path result)
-           (subvec path 0 (dec (count path)))
+           (if-not (empty? path)
+             (subvec path 0 (dec (count path)))
+             nil)
            result)
-    (update-node root [] result)))
+    root))
 
 (subvec [1 2 3] 0 (dec (count [1 2 3])))
 


(defn check-terminal [state]
  (cond (check-win (:p1 state)) 1
        (check-win (:p2 state)) -1
        (empty? (valid-moves state)) 0))

#_(crit/quick-bench (check-win #{1 3 4 12 20 23}))

      (update-in [(:active state)] #(conj % move))
      (assoc :active (if (= :p1 (:active state)) :p2 :p1))))

(defn uct [node parent-visits]
  (if (zero? (:visited node))
    Long/MAX_VALUE
