(ns com.oly.static-sites.do-blog.pages.chess.state
  (:require [reagent.core :as r]))

(def white-circle "○ ")
(def white-square "⬜")

;; (def white-pawn "♙ ")
;; (def white-rook "♖ ")
;; (def white-knight "♘ ")
;; (def white-bishop "♗ ")
;; (def white-queen "♕ ")
;; (def white-king "♔ ")

(def black-circle "● ")
(def black-square "⬛")

(def black-pawn "♟ ")
(def black-rook "♜ ")
(def black-knight "♞ ")
(def black-bishop "♝ ")
(def black-queen "♛ ")
(def black-king "♚ ")

(def white-pawn "♟ ")
(def white-rook "♜ ")
(def white-knight "♞ ")
(def white-bishop "♝ ")
(def white-queen "♛ ")
(def white-king "♚ ")

(def get-x first)
(def get-y second)
;(def alternate-color (alternate-black-white))
(def board {:tile-size [8 8]})
(defonce game-state
  (r/atom {:player-one {}
           :player-two {}
           :board []}))

(def start-state
  [{:character white-rook
    :colour :white
    :type :rook
    :start-pos [1 1]}
   {:character white-knight
    :colour :white
    :type :knight
    :start-pos [2 1]}
   {:character white-bishop
    :colour :white
    :type :bishop
    :start-pos [3 1]}
   {:character white-king
    :colour :white
    :type :king
    :start-pos [4 1]}
   {:character white-queen
    :colour :white
    :type :queen
    :start-pos [5 1]}
   {:character white-bishop
    :colour :white
    :type :bishop
    :start-pos [6 1]}
   {:character white-knight
    :colour :white
    :type :knight
    :start-pos [7 1]}
   {:character white-rook
    :colour :white
    :type :rook
    :start-pos [8 1]}

   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [1 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [2 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [3 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [4 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [5 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [6 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [7 2]}
   {:type :pawn
    :colour :white
    :character white-pawn
    :start-pos [8 2]}

   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [1 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [2 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [3 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [4 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [5 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [6 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [7 7]}
   {:type :pawn
    :colour :black
    :character black-pawn
    :start-pos [8 7]}

   {:character black-rook
    :colour :black
    :type :rook
    :start-pos [1 8]}
   {:character black-knight
    :colour :black
    :type :knight
    :start-pos [2 8]}
   {:character black-bishop
    :colour :black
    :type :bishop
    :start-pos [3 8]}
   {:character black-queen
    :colour :black
    :type :queen
    :start-pos [4 8]}
   {:character black-king 
    :colour :black
    :type :king
    :start-pos [5 8]}
   {:character black-bishop
    :colour :black
    :type :bishop
    :start-pos [6 8]}
   {:character black-knight
    :colour :black
    :type :knight
    :start-pos [7 8]}
   {:character black-rook
    :colour :black
    :type :rook
    :start-pos [8 8]}])

(defn find-piece [colour piece]
  (first (filter #(and (= colour (:colour %1)) (= piece (:type %1))) start-state)))

(defn translate-char->piece [char]
  (get {"K" :king
        "Q" :queen
        "B" :bishop
        "N" :knight
        "R" :rook
        "P" :pawn} char))
