comparison clojure/com/aurellem/gb/badges.clj @ 228:edce489c3c21

fixed badge order, added HM-mew, mapped out some more memory
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 13:15:15 -0500
parents d5dddf33543c
children
comparison
equal deleted inserted replaced
227:d5dddf33543c 228:edce489c3c21
1 (ns com.aurellem.gb.badges 1 (ns com.aurellem.gb.badges
2 (:use (com.aurellem.gb gb-driver util constants)) 2 (:use (com.aurellem.gb gb-driver util constants))
3 (:use (com.aurellem.world practice))
4 (:import [com.aurellem.gb.gb_driver SaveState])) 3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 4
6 (def badges '(:boulder :cascade :thunder :marsh :rainbow :soul :volcano 5 (def badges
7 :earth)) 6 '(:boulder :cascade :thunder :rainbow
7 :soul :marsh :volcano :earth))
8 8
9 (defn get-badges 9 (defn get-badges
10 "Returns a list of the current badges held by the player." 10 "Returns a list of the current badges held by the player."
11 ([state] 11 ([state]
12 ((fn this [coll n] 12 ((fn this [coll n]
13 (cond (zero? n) '() 13 (cond (zero? n) '()
14 (zero? (rem n 2)) (recur (pop coll) (int (/ n 2))) 14 (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
15 :else (cons (peek coll) (this (pop coll) (int (/ n 15 :else (cons
16 2)))))) 16 (peek coll)
17 (this (pop coll) (int (/ n 2))))))
17 badges 18 badges
18 (aget (memory state) 0xD355) 19 (aget (memory state) 0xD355)))
19 ))
20 ([] (get-badges @current-state))) 20 ([] (get-badges @current-state)))
21 21
22 (defn set-badges 22 (defn set-badges
23 "Sets the badges held by the player. badge-list may contain :boulder 23 "Sets the badges held by the player. badge-list may contain
24 :cascade :thunder :marsh :rainbow :soul :volcano." 24 :boulder :cascade :thunder :marsh :rainbow :soul :volcano."
25 ([state badge-list] 25 ([state badge-list]
26 (let [has-badge (set badge-list)] 26 (let [has-badge (set badge-list)]
27 (->> 27 (->>
28 ((fn [n coll] 28 ((fn [n coll]
29 (cond 29 (cond
30 (empty? coll) n 30 (empty? coll) n
31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll)) 31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))
32 :else (recur (* 2 n) (pop coll)))) 32 :else (recur (* 2 n) (pop coll))))
33
34 0 33 0
35 (vec badges)) 34 (vec badges))
36 (set-memory state 0xD355)))) 35 (set-memory state 0xD355))))
37
38
39 ([badge-list] (set-badges @current-state badge-list))) 36 ([badge-list] (set-badges @current-state badge-list)))
40 37
41 38 (defn give-all-badges
42 39 ([^SaveState state]
43 40 (set-badges state badges))
41 ([] (give-all-badges @current-state)))
44 42
45
46
47 ;; (let [mem (aget (memory state) 0xD354)]
48 ;; ((fn this [coll n]
49 ;; (cond (zero? n) '()
50 ;; (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
51 ;; :else (cons (peek coll) (this (pop coll) (int (/ n
52 ;; 2))))))
53 ;; badges
54 ;; (aget (memory state) 0xD354)
55 ;; )))
56