 
 (defn check-terminal [state]
   (cond (check-win (:p1 state)) 1
-        (check-win (:p2 state)) -1
+        (check-win (:p2 state)) 2
         (empty? (valid-moves state)) 0))
 
 #_(crit/quick-bench (check-win #{1 3 4 12 20 23}))

      :else (let [child-path (best-child mtcs path)]
              (recur mtcs child-path)))))

(time (loop [root {[] {:visited 0 :score 0 :state (init)}}]
   (process root [])))

(defn simulate [state]


(defn generate-node [mtcs path state]
  (reduce (fn [coll move]
            (let [current-player (:player (mtcs path))
                   new-state (perform-move state move)
                  new-path (conj path move)
                  terminal-result (check-terminal new-state)]
              (-> coll
                  (update-in [path :children] #(conj % new-path))
                  (assoc new-path
                           (if terminal-result
                             {:player (- 3 current-player) :state new-state :terminal true :visited 0 :score 0 :result terminal-result}
                             {:player (- 3 current-player) :state new-state :visited 0 :score 0}))))
            )
          mtcs
          (valid-moves state)))

(backprop (generate-node {[] {:visited 0 :score 0 :player 1}} [] (init)) [6] 1)

(defn process [mtcs path]
  (let [node (mtcs path)]
    (cond
      (> (:visited node) 100)
      (filter (fn [[p v]] (= 1 (count p))) mtcs)

      (:terminal node)
      (recur (backprop mtcs path (:result node)) [])
