                                           0))))))
 
 (defmulti compute-matchup
-          "Compute a matchup.  The first argument is an associative structure that gives the points per a correct pick
-          for each round.  The second argument is an associative structure that gives the points per an upset pick for each
-          round.  The third and final argument is the matchup data to perform the computation on."
-          (fn [_ _ field]
-            (cond
-              (and (coll? field) (= (count field) 2) (record? (first field)) (record? (last field)))
-              :leaf
-              (and (coll? field) (= (count field) 2) (coll? (first field)) (coll? (last field)))
-              :branch)))
+  "Compute a matchup.  The first argument is an associative structure that gives the points per a correct pick
+  for each round.  The second argument is an associative structure that gives the points per an upset pick for each
+  round.  The third and final argument is the matchup data to perform the computation on."
+  (fn [_ _ field]
+    (cond
+      (and (coll? field) (= (count field) 2) (record? (first field)) (record? (last field)))
+      :leaf
+      (and (coll? field) (= (count field) 2) (coll? (first field)) (coll? (last field)))
+      :branch)))
 (defmethod compute-matchup :default [_ _ matchup]
   matchup)
 (defmethod compute-matchup :branch [pick-scoring upset-scoring [[upper-field] [lower-field] :as fields]]

      vals                                                  ;get the aggregation
      (#(vector % fields)))))                               ;preserve the tree
(defmethod compute-matchup :leaf [pick-scoring upset-scoring [a b]]
  (compute-matchup pick-scoring upset-scoring [[[a]] [[b]]]))

(defn to-tournament-teams [teams]
  "Transform a list of teams into a map of team name->team data."
  (->> teams
    (remove (comp nil? :seed))
    (map #(vector (:name %) (assoc (map->Team %) :weight 1 :avg-pts 0)))
    (into {})))

(defn to-tournament-bracket [bracket teams]
  "Transforms a bracket of team names and a map of team data into a bracket with team data."
  (walk/postwalk-replace
    teams
    bracket))

(defn compute-tournament [pick-scoring upset-scoring tournament-bracket]
  (walk/postwalk
    (partial compute-matchup pick-scoring upset-scoring)
    tournament-bracket))

(def bracket
  [[[["Florida"
      "Albany"]

     ["Colorado"
      "Pittsburgh"]]

    [["VCU"
      "Stephen F. Austin"]

     ["UCLA"
      "Tulsa"]]]

   [[["Ohio St."
      "Dayton"]

     ["Syracuse"
      "Western Michigan"]]

    [["New Mexico"
      "Stanford"]

     ["Kansas"
      "Eastern Kentucky"]]]])

(println
  (compute-tournament
    [0 1 2 4 8 12 16]
    [0 1 2 3 4 5 6]
    (to-tournament-bracket
      bracket
      (to-tournament-teams (data/get-kenpom-teams-bundled)))))


  (:require [clojure.math.combinatorics :as combo]
            [bracketolojy.log5 :as log5]
            [bracketolojy.team-data :as data]
            [clojure.walk :as walk]
            [clojure.zip :as zip]))

(defrecord Team [name seed pe weight avg-pts future-pts])

(defn- log2 [x]
  "The log base 2 of x, rounded to the nearest integer."
  (Math/round
    (/ (Math/log x)
       (Math/log 2))))
