     (reset! winner (get-winner @state i))
     true))
 
+(declare initial-loop)
 (defn game-loop [players]
   (let [ch-ins (mapv :ch-in players)
         ch-outs (mapv :ch-out players)
         state (atom (vec (repeat (* ncols nrows) 0)))
-        turn (atom 0)
+        turn (atom (rand-int 2))
         winner (atom nil)
         notify (fn [ch]
                  (put! ch (cond->

                             :winner (inc @winner)
                             :turn 0))))]
    (go
      (doseq [ch-out ch-outs]
        (notify ch-out))
      ;; During the game
      (loop []
        (when-let [[{:keys [type move] :as msg} ch-in] (alts! ch-ins)]
          (when msg
            (let [actor (.indexOf ch-ins ch-in)
                  ch-out (ch-outs actor)]
              (cond
                (= type "state_request")
                (notify ch-out)
                (and (= type "move")
                     (= @turn actor)
                     (process-move state winner turn move))
                (doseq [ch-out ch-outs]
                  (notify ch-out))
                :else (put! ch-out {:type :ignored :msg msg})))
            (when-not @winner
              (recur)))))
      ;; Cleanup
      (doseq [{:keys [latch ch-out]} players]
        (notify ch-out)
        (put! ch-out {:type (if @winner "end" "disconnected")})
        (async/close! latch)))))

(defn match-once [{:keys [id] :as player0}]
  (if-let [player1 (->> (vals @awaiting)

  (:require
   [clojure.core
    [async :as async :refer [go go-loop <! >! chan put! alt! alts!]]]
   [clojure
    [string :as string]]
   [taoensso.timbre :as tb]
   [manifold
    [stream :as st]
