    :first true
    :start 0 ;;timestamp
    :remains mines
+   :need-open (- (* x y) mines)
    }))
 
-(defn all-open? [game]
-  (= (->> (game :board)
-          (apply concat)
-          (filter #(not= 1 %))
-          (count))
-     (->> (game :states)
-          (apply concat)
-          (filter #(= :open %))
-          (count))))
 
 (defn complete-game [game]
   (.ga  js/window 'send', 'event', 'win-game', 'click')

(defn start []
  (new-game! :beginner)
  (r/render-component [control-component] (.getElementById js/document "controls"))
  (r/render-component [game-table] (.getElementById js/document "rows"))
  )


    (condp = (get-in game [:states x y])
      :flag game
      :open game 
      (let [game (open-cell game x y)]
           (cond 
             (= (get-in game [:board x y ]) 1)  (fail-game game)  ;bomb
             (zero? (game :need-open))           (complete-game game)               ;all openned
             (zero? (get-in game [:counts x y])) (open-surround game [[x y]] #{[x y]}) ;open all neighors
             :else game)))))

