Created
September 3, 2016 05:24
-
-
Save jreighley/19316357a9d90aaeed1e6ee878971a24 to your computer and use it in GitHub Desktop.
chess960 clojure revision
This file contains 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
(ns c960) | |
(def pclist '(B B N N Q R K R)) | |
(defn c960 [](let [c960seq (shuffle (range 1 9)) | |
oddBish (first (filter odd? c960seq)) | |
evenBish (first (filter even? c960seq)) | |
goodseq (filterv #(not= oddBish %) | |
(filterv #(not= evenBish %)c960seq))] | |
(flatten (conj [evenBish oddBish] ;Bishop numbers go first | |
(take 3 goodseq) ; then Knights and Queens | |
(sort (take-last 3 goodseq)))))) ;then Rook King ;rook (sorted) | |
(defn order [] (->> pclist ;; list of peices | |
(zipmap (c960)) ;mapped to their square numbers | |
(sort) ; sorted by squares | |
(vals))) ; return the peices | |
(println (order)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment