Code: Select all
(constant 'FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
(set 'file-list '(
("a8" "b8" "c8" "d8" "e8" "f8" "g8" "h8")
("a7" "b7" "c7" "d7" "e7" "f7" "g7" "h7")
("a6" "b6" "c6" "d6" "e6" "f6" "g6" "h6")
("a5" "b5" "c5" "d5" "e5" "f5" "g5" "h5")
("a4" "b4" "c4" "d4" "e4" "f4" "g4" "h4")
("a3" "b3" "c3" "d3" "e3" "f3" "g3" "h3")
("a2" "b2" "c2" "d2" "e2" "f2" "g2" "h2")
("a1" "b1" "c1" "d1" "e1" "f1" "g1" "h1")))
(define (fen-black? c)
(true?
(regex "[rnbqkp]" c)))
(define (fen-white? c)
(not
(fen-black? c)))
(define (fen-value c)
(if (= "_" c)
'(nil nil)
(list
(lower-case c)
(if (fen-black? c)
(string "b")
(string "w")))))
(define (fen-expand s)
(replace "([1-8])" s (dup "_" (int $0)) 0))
(define (fen-split f)
(parse
(fen-expand f) "/"))
(define (fen-list c s)
(append
(list s)
(fen-value c)))
(define (fen-parse fen)
(let (ret-list '())
(fen-parse-helper (fen-split fen) file-list)))
(define (fen-parse-helper list1 list2)
(unless (null? list1)
(let (temp-list nil)
(setq temp-list (map (fn (x y) (fen-list x y)) (explode (first list1)) (first list2)))
(until (null? temp-list) (push (pop temp-list) ret-list))
(fen-parse-helper (rest list1)(rest list2)))
(eval 'ret-list)))
--hsm