-(ns reversi.core)
+(ns reversi.core
+  (:require [clojure.browser.repl]))
 
 (def ^:dynamic *empty-grid* 0)
 (def ^:dynamic *black-piece* 1)

    (apply conj possible-empty-grids
           new-possible-empty-grids)))

(defn find-putable-empty-grids
  ;; search each empty grids
  ;; ([piece border]
  ;;    (filter (fn [empty-grid]
  ;;              (can-reversi? piece empty-grid border))
  ;;            )
  ;;    )
  ;; only search possible-empty-grids
  ([piece possible-empty-grids border]
     (filter (fn [empty-grid]
               (can-reversi? piece empty-grid border))
             possible-empty-grids)))

(defn put-piece [piece [x y] border]
  ;; (when (in-empty-grid? [x y] border)
  ;;   (let [nearby-nonsame-color-dire-offsets
  ;;         (nearby-color-piece-dire-offsets
  ;;          (another-color-piece piece) [x y] border)]
  ;;     (if-not (empty? nearby-nonsame-color-dire-offsets)
  ;;       (let [target-posis
  ;;             (reduce (fn [m offset]
  ;;                       (let [offsetd-position (mapv + [x y] offset)
  ;;                             target-posi (find-same-piece-on-dire offset
  ;;                                                                  piece
  ;;                                                                  offsetd-position
  ;;                                                                  border)]
  ;;                         (if-not (nil? target-posi)
  ;;                           (cons target-posi m)
  ;;                           m)))
  ;;                     '()
  ;;                     nearby-nonsame-color-dire-offsets)]
  (let [target-posis (find-reversiable-lines piece [x y] border)]
    (if-not (empty? target-posis)
      (reduce (fn [b tposi]

    (let [nearby-nonsame-color-dire-offsets
          (nearby-color-piece-dire-offsets
           (another-color-piece piece) [x y] border)]
      (loop [offsets nearby-nonsame-color-dire-offsets]
        (if-not (empty? offsets)
          (let [offset (first offsets)
                offseted-position (mapv + [x y] offset)
                target-posi (find-same-piece-on-dire offset
                                                     piece
                                                     offseted-position
                                                     border)]
            (if-not (nil? target-posi)
              true
              (recur (rest offsets)))))))))

(defn add-possible-empty-grids [possible-empty-grids [x y] border]
  (let [nearby-empty-grid-dire-offsets
