          rcore/*possible-grid* "possible-grid"}]
     (rp-gn-table rcore-grid)))
 
+(defn grid-pos->phaser-pos [grid-pos]
+  [(+ (* 75 (first grid-pos)) 5)
+   (+ (* 75 (second grid-pos)) 5)])
+
 (defn another-color-piece [grid-name]
   (rcore-grid->grid-name
    (rcore/another-color-piece
     (grid-name->rcore-grid grid-name))))
 
-(defn put-piece [piece [x y] border phaser-border]
-  (let [result-border
+(defn put-piece [piece [x y] game]
+  (let [border
+        (.-border game)
+        phaser-border
+        (.-phaserBorder game)
+        visible-possible-grids-pos
+        (.-visiblePossibleGridsPos game)
+        result-border
         (rcore/put-piece piece
                          [x y]
                          border

  (:require [clojure.browser.repl]
            [reversi.core :as rcore]))

(def *border* (atom rcore/*default-border*))
(def *phaser-border* (atom [[] [] [] [] [] [] [] []]))
(def *visible-possible-grids-pos* (atom '()))
(def ^:dynamic *game* (js/Phaser.Game. 905 605 js/Phaser.AUTO "game_div"))
(def ^:dynamic *default-player-use-piece* rcore/*black-piece*)
(def ^:dynamic *default-pc-use-piece* rcore/*white-piece*)

(defn grid-name->rcore-grid [grid-name]
  (let [gn-rp-table

        style (clj->js { :font "35px Arial" :fill "#000000" :align "left" })]
    (set! (.-pieceCountText game) (.text (.-add game) 615 20 text style))))

(defn create-buttons [game]
  (let [restart-button
        (.sprite (.-add game) 675 515 "restart-button")]
    (set! (.-inputEnabled restart-button) true)
    (set! (.-useHandCursor (.-input restart-button)) true)
    (.add (.-onInputDown (.-events restart-button))
          (fn [b] (.restartGame game game)) game)
    (set! (.-restartButton game) restart-button)))

(def ^:dynamic *assets-table*
                                        ;name    path
  [["border"         "assets/reversi-border.png"]
   ["white-piece"    "assets/white-piece.png"]
   ["black-piece"    "assets/black-piece.png"]
   ["possible-grid"  "assets/gray-grid.png"]
   ["restart-button" "assets/restart-button.png"]])

(defn preload [game]
  (let [loader (.-load game)]
    (doseq [pair *assets-table*]
      (let [name (first pair)
            path (second pair)]
        (.image loader name path)))))

;; (defn update [game]
;;   )

;; (defn render [game])

(defn init-reversi []
  (set! (.-border *game*) *border*)
  (set! (.-phaserBorder *game*) *phaser-border*)
  (set! (.-visiblePossibleGridsPos *game*) *visible-possible-grids-pos*)
  (set! (.-defaultPlayerPiece *game*) *default-player-piece*)
  (set! (.-defaultPcPiece *game*) *default-pc-piece*))

(defn create [game]
  (set! (.-backgroundColor (.-stage game)) "#ffffff")
