Skip to content

Instantly share code, notes, and snippets.

@jreighley
Created September 3, 2016 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jreighley/19316357a9d90aaeed1e6ee878971a24 to your computer and use it in GitHub Desktop.
Save jreighley/19316357a9d90aaeed1e6ee878971a24 to your computer and use it in GitHub Desktop.
chess960 clojure revision
(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