(ns com.oly.static-sites.do-blog.pages.chess.board)

(defn calculate-black-white [pos]
  (if (even? (first pos))
    (if (even? (second pos))
      :black :white)
    (if (even? (second pos))
      :white :black)))

(defn square-defaults [pos]
  {:piece {}
   :bg-colour (name (calculate-black-white pos))})

(defn create-board-data [size]
  (loop [x-pos 1
         y-pos 1
         result []]
    (if (> y-pos size) #_(and (= x-pos size))
        result
        (if (= size x-pos)
          (recur 1
                 (inc y-pos)
                 (conj result [x-pos y-pos]))
          (recur (inc x-pos)
                 y-pos
                 (conj result [x-pos y-pos]))))))


(defn create-board-data-map
  ([size] (create-board-data-map size square-defaults))
  ([size square-defaults-map]
   (->> (create-board-data size)
        (mapv #(vector % (square-defaults-map %)))
        (into {}))))


(defn merge-board-piece
  "Merge in piece changes at position"
  [board position piece]
      (update board position update :piece merge piece))

(comment
  (create-board-data 5)
  (create-board-data-map 5)
  (-> (create-board-data-map 5)
      (update-board-piece [1 1] {:type :pawn}))
  )
