             (:piece-locations position))
     ))
 
-;; (locations-under-attack starting-position)
-;;      (locations-under-attack (string->position "Bk" :black))
-;;
-(defn locations-under-attack[position]
-  {
-   :post  [(set? %)]
-   :pre [(my-is-a? :position position)] }
-
-  (let [enemy-position (flip-position position)]
-   (when debug (println "enemy-position" enemy-position))
-    (set (map second (moves enemy-position)))))
-        ;; (filter (partial unoccupied? enemy-position)
-                ;; (map second (locations-under-attack-moves enemy-position))))
 
 
 

;;  defn move
;; From wikipedia:
;; A FEN record contains six fields. The separator between fields is a space. The fields are:
;; Piece placement (from white's perspective). Each rank is described, starting with rank 8 and ending with rank 1; within each rank, the contents of each square are described from file "a" through file "h". Following the Standard Algebraic Notation (SAN), each piece is identified by a single letter taken from the standard English names (pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q" and king = "K").[1] White pieces are designated using upper-case letters ("PNBRQK") while black pieces use lowercase ("pnbrqk"). Empty squares are noted using digits 1 through 8 (the number of empty squares), and "/" separates ranks.
;; Active color. "w" means White moves next, "b" means Black.
;; Castling availability. If neither side can castle, this is "-". Otherwise, this has one or more letters: "K" (White can castle kingside), "Q" (White can castle queenside), "k" (Black can castle kingside), and/or "q" (Black can castle queenside).
;; En passant target square in algebraic notation. If there's no en passant target square, this is "-". If a pawn has just made a two-square move, this is the position "behind" the pawn. This is recorded regardless of whether there is a pawn in position to make an en passant capture.[2]
;; Halfmove clock: This is the number of halfmoves since the last capture or pawn advance. This is used to determine if a draw can be claimed under the fifty-move rule.
;; Fullmove number: The number of the full move. It starts at 1, and is incremented after Black's move.

(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
