               (ranging-moves position loc (:rules piece-info)) 
               (is-pawn? piece)
               (pawn-moves position loc) 
+             (is-knight? piece) 
+              (non-ranging-moves position loc (:rules piece-info)) 
+             (is-king? piece) 
+              (remove (fn[move] (contains? (:locations-under-attack position)
+                                           (second move)))
+              (non-ranging-moves position loc (:rules piece-info))) 
               true
-              (non-ranging-moves position loc (:rules piece-info)) 
+              (assert false)
               ))) 
     (filter (fn[[_ piece]]
               (=   (piece-color piece)

          position location)
         ))

(defn test-pawn-moves[]
  (let [ position starting-position]
    (pprint (map (partial move->algebraic-notation starting-position)
                 (pawn-moves starting-position [0 1])))
    ))


(def piece-color {"r" :black "n" :black "b" :black "q" :black "k" :black
                  "R" :white "N" :white "B" :white "Q" :white "K" :white
                  "P" :white})

;; (count (moves (string->position "  n\n   \n   " :black) :black))
;; (:piece-locations (string->position "  n\n   \n   " :black))
(defn moves[position white-or-black]
  (when true ;;debug
    (println "entering moves")
    (println "position is" position)
    )


(defn non-ranging-moves[position location rules]
  "returns moves, including captures. For king and knight"
    (map (fn[loc2] [location loc2])
         (remove (fn[loc2] (friendly-square? position loc2))
                 (filter on-board? 
                         (map (fn[rule] (apply rule location))
                              rules))
                 )))


(def is-ranging? #{"q" "Q" "b" "B" "r" "R"})
