 
 (defn ranging-non-captures[board location rules]
   {:pre  [(vector? rules)]
-   :post [(set? %)]
    }
-  "return set of locations for moves that the piece can make according to the rules which is an array of functions"
+  "return moves that the piece can make according to the rules which is an array of functions"
+  "[loc loc2]"
   (assert (is-ranging? (get board location)))
   (assert (is-board? board))
   (assert (valid-location? location))
   (let [color (get-color (get board location))
         [x y] location
         ]
-    (set (remove nil?
-                 (map
-                   (partial ranging-capture-in-direction board location)
+         (remove empty?
+                 (mapcat
+                   (partial ranging-non-capture-in-direction board location)
                    rules 
-                   )))))
-
-
-(defn rook-captures[board location]
-  {:pre  []
-   :post [(set? %)]
-   }
-  (ranging-captures board location rook-rules))
-
-(defn rook-non-captures[board location]
-  {:pre  []
-   :post [(set? %)]
-   }
-  (ranging-non-captures board location rook-rules))
-
-
-; (test-bishop-captures)
-(defn test-bishop-captures[]
-  (let [board (string->board (join "\n" 
-
-                                   ["       "
-                                    "     p"
-                                    "  p   "
-                                    "   B   b"
-                                    "  pnQ  "
-                                    "          "]))
-        ]
-    (when debug
-      (println (board->string board))
-      )
-    (is (= 
-          #{[2 1] [5 4] [2 3]}
-          (bishop-captures board [3 2])))
-    ))
-;;(def debug false)
-(defn test-rook-non-captures[]
-  (let [board (string->board (join "\n" 
-                                   ["   p    "
-                                    "  pR   b"
-                                    "  pQ    "
-                                    "        "]))
-        ]
-    (when debug
-     (println (board->string board))
-      )
-    (is (= 
-          #{[2 2] [3 3] [7 2]}
-          (rook-non-captures board [3 2])))
-    ))
-(test-rook-non-captures)
-(defn test-rook-captures[]
-  (let [board (string->board (join "\n" 
-                                   ["   p  "
-                                    "  pR   b"
-                                    "  pnQ  "
-                                    " "]))
-        ]
-    ;;    (println board)
-    ;;  (println (board->string board))
-    (is (= 
-          #{[2 2] [3 3] [7 2] [3 1]}
-          (rook-captures board [3 2])))
-    ))
-
-(defn rook-moves[board location]
-  (apply concat 
-         ((juxt rook-non-captures rook-captures)
-          board location))
-  )
-(defn bishop-moves[board location]
-  (apply concat 
-         ((juxt bishop-non-captures bishop-captures)
-          board location))
-  )
-
+                   ))))
+
+(defn piece-info-at-location[board location]
+  (get pieces-info 
+       (keyword (clojure.string/lower-case (get board location)))
+       ))
+
+
+(defn ranging-moves[board location]
+  (when true (println "ranging-moves")
+    (println "location is" location)
+    (println board) 
+    )
+  (let [piece-info (piece-info-at-location board location)]
+    (when true (println "piece-info is" piece-info))
+        (apply concat 
+           ((juxt ranging-captures ranging-non-captures)
+     board location (:rules piece-info)))))
 
 
 (defn pawn-captures[board [x y :as location]]

  (is (= 
        starting-board-string
        (board->string
        (string->board starting-board-string)))))
(defn on-board?[loc] (not (off-board? loc)))

(defn bishop-non-captures[board location]
  (assert (is-bishop? board location))
  (assert (is-board? board))
  (assert (valid-location? location))
  (let [[x y] location]
    (into []  ;
          (map (fn[loc2] [location loc2])
               (apply concat 
                      (for [op1  [+ -] op2 [+ -]]  ;; to generate 4 diagonals
                        (take-while (fn[loc]
                                      (and
                                        (on-board? loc)
                                        (not (occupied? board loc)))) 
                                    (for [z (drop 1(range))]  [(op1 x z) (op2 y z)])
                                    )
                        ))))))

(defn rook-right[x y z] [ (+ x z) y ])

(defn rook-left[x y z] [ (- x z) y ])

;;

(def debug false)

(defn string->board[string]
  (assert (string? string))
  (let [lines (vec (reverse (clojure.string/split-lines string)))
