   (for [i (range 9)]
     (math/expt 2 i)))
 
-(defn pick-move [state]
+(defn valid-moves [state]
   (let [occupied (bit-or (:p1 state) (:p2 state))]
-    (rand-nth (keep identity (map-indexed (fn [i pos]
-                              (if (zero? (bit-and occupied pos))
-                                i))
-                            possible-moves)))))
+    (filter #(zero? (bit-and occupied %))
+                      possible-moves)))
+
 
 (def winning-positions
   [2r111000000                                              ;horizontals

                        (= winning-pos (bit-and board winning-pos)))
                      winning-positions)))

(defn simulate [state]

  )

(defn simulate-step [state player]
  (println state)
  (cond (check-win (:p1 state)) 1
        (check-win (:p2 state)) -1
        (= 2r111111111 (bit-or (:p1 state) (:p2 state))) 0
        :else (let [random-move (pick-move state)
                    bit (math/expt 2 random-move)]
                (recur
                 (update-in state [player] #(bit-or bit %))
                 (if (= :p1 player) :p2 :p1)))))

(simulate-step (init) :p1)

(ns ulam.tictactoe
  (require [ulam.core :as ulam]
           [criterium.core :as crit]
           [clojure.math.numeric-tower :as math]))

(defn init []
