                                     )
                         ))))))
 
-(defn bishop-captures[board location]
-  "return list of captures that the bishop at location can make"
-  (assert (is-bishop? board location))
-  (assert (is-board? board))
-  (assert (valid-location? location))
-  (let [color (get-color (get board location))
-        [x y] location
-        ]
-    (remove nil?
-            (for [op1  [+ -] op2 [+ -]]  ;; to generate 4 diagonals
-              (loop [locs (for [z (drop 1(range))] 
-                            [(op1 x z) (op2 y z)])
-                     ]
-                (cond (off-board? (first locs))
-                      nil
-                      (occupied-by-enemy? board (first locs) color)
-                      [ location (first locs) ]
-                      (occupied? board (first locs))
-                      nil
-                      true
-                      (recur  (next locs))))))))
-
-(defn can-move-through?[board loc]
-  (and (on-board? loc) (not (occupied? board loc))))
-
-(defn rook-non-captures[board location]
-  (println (get board location))
-  (assert (is-rook? (get board location)))
-  (assert (is-board? board))
-  (assert (valid-location? location))
-  (let [[x y] location]
-    (into []  ;
-          (map (partial vector location)
-               (concat 
-                 (take-while  (partial can-move-through? board)
-                             (for [z (drop 1(range))]  [(+ x z) y] ))
-                 (take-while  (partial can-move-through? board)
-                             (for [z (drop 1(range))]  [(- x z) y] ))
-                 (take-while  (partial can-move-through? board)
-                             (for [z (drop 1(range))]  [x (+ z y)] ))
-                 (take-while  (partial can-move-through? board)
-                             (for [z (drop 1(range))]  [x (- z y)] ))
-                 )))))
-;; (test-rook-moves)
-(defn test-rook-moves[]
-  (let [board (string->board (join "\n" 
-                                   ["  "
-                                    " R"
-                                    "  "]))
-        ]
-    (println (rook-non-captures board [1 1])))
-  )
-
-;; (test-rook-captures)
-
-;; z will range from 1 to infinity
-
-(defn look-for-rook-capture[board location direction-fn]
-  ;; location is the location of the rook
-  ;; generate locations to test using a function applied to the range 1..infinity
+(defn rook-right[x y z] [ (+ x z) y ])
+
+(defn rook-left[x y z] [ (- x z) y ])
+
+(defn rook-up[x y z] [ x (+ y z)])
+
+(defn rook-down[x y z] [ x (- y z)])
+
+(defn bishop-ne[x y z] [ (+ x z) (+ y z) ])
+
+(defn bishop-nw[x y z] [ (- x z) (+ y z) ])
+
+(defn bishop-se[x y z] [ (+ x z) (- y z)])
+
+(defn bishop-sw[x y z] [ (- x z) (- y z)])
+
+(def bishop-rules [bishop-ne bishop-nw bishop-se bishop-sw])
+(def rook-rules [rook-right rook-left rook-up rook-down])
+
+
+(def is-ranging? #{"q" "Q" "b" "B" "r" "R"})
+
+(defn ranging-capture-in-direction[board location direction-fn]
+  ;; location is the location of the friendly piece in question 
+  ;; direction-fn generate locations to test using a function applied to the range 1..infinity
   ;; Finished when 
   ;; 1. off board - return nil
   ;; 2. friendly piece found return nil
   ;; 3. enemy piece is found - return the location of the enemy piece
   ;;
-  (when false
-    (println "entering look-for-rook-capture, direction-fn is" direction-fn))
+  (when debug 
+    (println "entering ranging-capture-in-direction, direction-fn is" direction-fn))
   (let [[x y] location
         color (get-color (get board location))
         ]
-    ;;  (println x y)
-    ;; (println board)
-    ;;(println location)
+    (when debug
+      (println x y)
+     (println (board->string board))
+    (println location))
     (loop [locs-to-test (for [z (drop 1(range))]  ;; lazy seq of locations to test
                           (direction-fn x y z))
            ]

  (assert is-color? color)
  (assert is-board? board)
  (let [ opponent-king-piece (if (= color :white) "k" "K")
        _ (println "1")
        king-location (some #(if (= opponent-king-piece (second %)) 
                               (first %))
                            board)
        _ (println "1")
        ]
    (some #(when (= (second %) king-location) true) (moves board color))

    ))

;;;;;;;;;;;;;; TESTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn test-checkmated[]
  (assert (not (checkmated? (string->board "BR\nkR") :white)))
  (assert (checkmated? (string->board "BR\n k") :white))
  )

        ]
    [x y]))
(println locations-helper)


;; 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.
;; Example:
;; rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
;; w means white to move- "side to move"
;; The KQkq indicates all 4 castles are elegible. 
(defn board->fen[board]

  )
(defn board->string[board]
  (assert is-board? board)
  (str
  (reduce (fn[accum location]
            (str accum
                 (get board location " ")

                 (if (= 7 (first location))
                   "\n")
                 (if (and (= 7 (first location))
                          (not= 0 (second location)))
                       (str (second location) " ")))
            ) "8 " locations-helper)
      "  abcdefgh" 
    ))
(println (board->string starting-board))
;;; to print board 0 7, 1 7,     7,7 cr
;;;                0 6 .........7 6 cr
;;;                ...
