 
 (defn move->algebraic-notation[position [[x1 y1] [x2 y2]]]
   ;; assert if occupied, must be enemy 
-  (str (piece-at-location position [x1 y1])
+  (str (name (piece-at-location position [x1 y1]))
        (num->alpha x1)
        (inc y1)
        (if (occupied? position [x2 y2])


(defn flip-position[position]
  (assoc position :flipped true
                     :locations-under-attack []
                              :player-to-move (opposite-color (:player-to-move position))))
 ;; (flip-position starting-position) 
;; (println starting-position)

(defn locations-under-attack-moves[position]

(defn king-location[position]
  "TODO: don't use scan???"
  (let [piece (if (= :white (:player-to-move position)) 
                :K
                :k)]
    (some #(if (= piece (second %))
             (first %))
          (:piece-locations position))
    ))
;; (:king-moves (string->position-and-print :K :white)
;;         (king-moves (string->position-and-print :K :white))
;;
(defn king-moves[position]
  (when debug
    (println "king-moves")
    (println position))

  (remove (fn[move]
            (when debug (println "move in fn is" move)
              (println "second move" (second move))
              (println (:locations-under-attack position)))
            (contains? (:locations-under-attack position)
                       (second move)))
          (non-ranging-moves position (king-location position)
                             king-rules) 
          ))

;; (string->position-base "rK" :white)
;{;
(def piece-letter #{"r" "R" "N" "n" "B" "b" "Q" "q" "K" "k" "P" "p"})
;; (get piece-letter "r")
;;
(defn string->position-base[string color]
  {:post  [(is-position? %)]
   :pre [(string? string)
         (is-color? color)] }
  (let [lines (vec (reverse (clojure.string/split-lines string)))
        ]
      { :type :position
       :player-to-move color
       :piece-locations
       (into (sorted-map) 
            (filter (fn[zzz] (not (nil? (second zzz))))
               (for [x (range 8) y (range 8)
                     :let [ location [x y]
                           my-piece-str (str (get (get lines y) x)) 
                         ;;  _ (println "my-piece-str is" my-piece-str)
                           piece 
                             (if (get piece-letter my-piece-str)
                               (keyword my-piece-str))
                           
                           ]
                     ]
                 [location piece]  ;; map entry
                 )))
       }))



(defn moves[position]
  (when debug
