diff clojure/com/aurellem/gb/util.clj @ 288:eec3e69500d9

Made hxc-pokenames and hxc-items return keywords instead of strings by default; added hxc-pokenames-raw and hxc-items-raw for the string version.
author Dylan Holmes <ocsenave@gmail.com>
date Thu, 29 Mar 2012 13:31:31 -0500
parents 69184558fcf3
children 1de6aada1cb7
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/util.clj	Wed Mar 28 06:06:13 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/util.clj	Thu Mar 29 13:31:31 2012 -0500
     1.3 @@ -29,6 +29,47 @@
     1.4            (Integer/parseInt
     1.5             (Integer/toBinaryString num) 10)))
     1.6  
     1.7 +(defn bit-list
     1.8 +  "List the bits of n in order of decreasing significance."
     1.9 +  [n]
    1.10 +  ((fn this [coll n]
    1.11 +     (if (zero? n) coll
    1.12 +         (recur
    1.13 +          (conj coll (rem n 2))
    1.14 +          (int (/ n 2)))))
    1.15 +   [] n))
    1.16 +
    1.17 +
    1.18 +(defn low-high
    1.19 +  [low high]
    1.20 +  (+ low (* 256 high)))
    1.21 +  
    1.22 +
    1.23 +(defn format-name
    1.24 +  "Convert the string of alphabetic/space characters into a keyword by
    1.25 +  replacing spaces with hyphens and converting to lowercase."
    1.26 +  [s]
    1.27 +  (if (nil? s) nil
    1.28 +      (keyword (.toLowerCase
    1.29 +                (apply str
    1.30 +                       (map #(if (= % \space) "-" %) s))))))
    1.31 +
    1.32 +
    1.33 +;; used to decode item prices
    1.34 +
    1.35 +(defn decode-bcd
    1.36 +  "Take a sequence of binary-coded digits (in written order) and return the number they represent."
    1.37 +  [digits]
    1.38 +  ((fn self [coll]
    1.39 +     (if (empty? coll) 0
    1.40 +         (+ (first coll) (* 100 (self (rest coll))))))
    1.41 +   (map
    1.42 +    #(+ (* 10 (int (/ % 16)))
    1.43 +        (rem % 16))
    1.44 +    (reverse digits))))
    1.45 +
    1.46 +
    1.47 +  
    1.48  
    1.49  (defn view-register [state name reg-fn]
    1.50    (println (format "%s: %s" name