Last active
December 10, 2015 00:29
-
-
Save edlich/4351510 to your computer and use it in GitHub Desktop.
Bad approach to convert a chess board to the first part of a fen string (and even not ready)
Can be dramatically improved by using function compositition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn pos2str [pos fenpos i-count spacecount] ;; Convert a position to the fen position (1st element) | |
(println ">" (apply str pos) "<") | |
(println ">" (apply str fenpos) "<") | |
(println "i-count=" i-count "spacecount" spacecount "piece(" (first pos) ") ---------------") | |
(read-line) | |
(let [piece (first pos)] | |
(if (empty? pos) | |
fenpos | |
(if (= i-count 7) | |
(if (= piece " ") ; nr=7 | |
(pos2str (rest pos) (conj fenpos (apply str (str spacecount)) "|") 0 0) ; Blank+Ende = slash and restart | |
(pos2str (rest pos) (conj fenpos (apply str piece "|")) 0 0)) ; Ende+Figur: piece + slash + restart | |
(if (= piece " ") ; nr 0 to 6 | |
(pos2str (rest pos) fenpos (inc i-count) (inc spacecount)) ; Blank+Mitte = nur spacecount+ | |
(pos2str (rest pos) | |
(if (> spacecount 0) ; if we had spaces | |
(conj fenpos (str spacecount)) | |
(conj fenpos piece)) | |
(inc i-count) spacecount)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment