comparison clojure/com/aurellem/world/practice.clj @ 227:d5dddf33543c

Added functions for getting and setting badges.
author Dylan Holmes <ocsenave@gmail.com>
date Sat, 24 Mar 2012 05:45:06 -0500
parents 67c42608ef9d
children b2f9a0cb13e3
comparison
equal deleted inserted replaced
226:21641c1c3f87 227:d5dddf33543c
1 (ns com.aurellem.world.practice 1 (ns com.aurellem.world.practice
2 (:use (com.aurellem.gb saves util constants gb-driver vbm items 2 (:use (com.aurellem.gb gb-driver))
3 assembly characters)) 3
4 (:use (com.aurellem.run title save-corruption)) 4 (:use (com.aurellem.gb saves util constants gb-driver vbm items assembly characters))
5 ;;(:use (com.aurellem.exp pokemon)) 5 (:use (com.aurellem.run title))
6 (:use (com.aurellem.exp item-bridge)) 6 (:use (com.aurellem.exp pokemon))
7 (:import [com.aurellem.gb.gb_driver SaveState]) 7 (:use (com.aurellem.exp item-bridge))
8 8 (:import [com.aurellem.gb.gb_driver SaveState]))
9 ) 9
10
11 ;;(def original-rom (rom(root)))
12
10 13
11 (def hex-pc (comp hex PC)) 14 (def hex-pc (comp hex PC))
12 15
13 (defn nstep [state n] 16 (defn nstep [state n]
14 (if (zero? n) state 17 (if (zero? n) state
121 (recur)))) 124 (recur))))
122 (update-state))) 125 (update-state)))
123 126
124 127
125 128
126 (defn spell [state mem n] 129
127 (print (character-codes->str 130 (defn spell-array
131 [array mem n]
132 (character-codes->str
128 (take n (drop mem 133 (take n (drop mem
129 (vec(memory state))))))) 134 (vec array)))))
130 135
131 136 (defn spell
132 (do 137 ([state mem n]
138 (spell (memory state) mem n))
139 ([mem n] (spell @current-state mem n)))
140
141
142
143 (comment
133 (println) 144 (println)
134 (print (character-codes->str (take 6000 (drop 0xA75F4 145 (print (character-codes->str (take 6000 (drop 0xA75F4
135 (vec(com.aurellem.gb.gb-driver/rom)))))) 146 (vec(com.aurellem.gb.gb-driver/rom)))))))
136 )
137 147
138 ;(dorun (map println (view-memory* (state-surprise) 0x1AEF 1600))) 148 ;(dorun (map println (view-memory* (state-surprise) 0x1AEF 1600)))
139 149
140 150
141 151
149 (empty? sub) list 159 (empty? sub) list
150 (empty? list) nil 160 (empty? list) nil
151 (= (take (count sub) list) sub) list 161 (= (take (count sub) list) sub) list
152 :else (recur (rest list) sub))) 162 :else (recur (rest list) sub)))
153 163
154 (defn subloc 164 (defn find-sublist
155 "Returns the position of the first occurence of sublist." 165 "Returns the position of the first occurence of sublist."
156 [list sub] 166 [list sub]
157 (loop [n 0 a list] 167 (loop [n 0 a list]
158 (cond 168 (cond
159 (empty? a) nil 169 (empty? a) nil
160 (= (take (count sub) a) sub) n 170 (= (take (count sub) a) sub) n
161 :else (recur (inc n) (rest a))))) 171 :else (recur (inc n) (rest a)))))
172
173 (defn find-sublists
174 "Returns a vector of the occurences of sublists."
175 [list sub]
176 (let [m (find-sublist list sub)]
177 (if (nil? m) '()
178 (cons m
179 (map (partial + (inc m))
180 (find-sublists
181 (drop (inc m) list)
182 sub))))))
183
184 (defn spelling-bee
185 "Search for the given string in ROM, returning short snippets of
186 text around the results."
187 [str k]
188 (let [rom (rom(root))]
189 (map
190 (fn [n]
191 [(hex n)
192 (character-codes->str (take k (drop n rom)))])
193
194 (find-sublists
195 rom
196 (str->character-codes str)))))
162 197
163 198
164 199
165 200
166 (defn change-speech 201 (defn change-speech
176 (if (not= n 19) (inc n) 211 (if (not= n 19) (inc n)
177 (+ n 21)))))) 212 (+ n 21))))))
178 ([str k] 213 ([str k]
179 (change-speech (state-speak) str k)) 214 (change-speech (state-speak) str k))
180 ([str] 215 ([str]
181 (change-speech str 0)) 216 (change-speech str 0)))
182 217
183 218
184 219
185 220 (defn rewrite-memory
221 "Alters the vector of memory. Treats strings as lists of character
222 ops."
223 ([mem start strs-or-ops]
224 (let [x (first strs-or-ops)]
225 (cond (empty? strs-or-ops) mem
226 (string? x)
227
228 (recur mem start
229 (concat
230 (str->character-codes x)
231 (rest strs-or-ops)))
232 :else
233 (recur
234 (assoc mem start x)
235 (inc start)
236 (rest strs-or-ops))))))
237
238 (def rewrite-rom
239 "Alters the ROM array using write-memory."
240 (partial rewrite-memory (vec (rom(root)))))
241
242 (defn restore-rom! [] (write-rom! original-rom))
243
244
245
246 (def oak-intro
247
248 (list "Hello there!"
249 0x4F
250 "Welcome to the"
251 0x55
252 "world of "
253 0x54
254 "MON!"
255 0x51
256 "My name is OAK!"
257 0x4F
258 "People call me"
259 0x55
260 "the "
261 0x54
262 "MON PROF!"
263 0x58
264 "This world is"
265 0x4F
266 "inhabited by"
267 0x55
268 "creatures called"
269 0x55
270 0x54
271 "MON!"
272 0x50
273 0x50
274 0x51
275 "For some people, "
276 0x4F
277 0x54
278 "MON are"
279 0x55
280 "pets. Others use"
281 0x55
282 "them for fights."
283 0x51
284 "Myself..."
285 0x51
286 "I study "
287 0x54
288 "MON"
289 0x4F
290 "as a profession."
291 0x58
292 "First, what is"
293 0x4F
294 "your name?"
295 0x58
296 "This is my grand-"
297 0x4F
298 "son. He's been"
299 0x55
300 "your rival since"
301 0x55
302 "you were a baby."
303 0x51
304 "...Erm, what is"
305 0x4F
306 "his name again?"
307 0x58
308 0x52
309 "!"
310 0x51
311 "Your very own"
312 0x4F
313 0x54
314 "MON legend is"
315 0x55
316 "about to unfold!"
317 0x51
318 "A world of dreams"
319 0x4F
320 "and adventures"
321 0x55
322 "with "
323 0x54
324 "MON"
325 0x55
326 "awaits! Let's go!"
327 0x57) )
328
329 (defn state-intro
330 "Professor Oak speaks!"
331 []
332 (do
333 (->
334 (rewrite-rom 0xA07BB
335 (list 0x87 0xA4 0xAB 0xAB 0xAE 0x7F 0xB3 0xA7 0xA4 0xB1 0xA4 0xE7 0x4F 0x96 0xA4 0xAB 0xA2 0xAE 0xAC 0xA4 0x7F 0xB3 0xAE 0x7F 0xB3 0xA7 0xA4 0x55 0xB6 0xAE 0xB1 0xAB 0xA3 0x7F 0xAE 0xA5 0x7F 0x54 0x8C 0x8E 0x8D 0xE7 0x51 0x8C 0xB8 0x7F 0xAD 0xA0 0xAC 0xA4 0x7F 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C 0x8E 0x8D 0x7F 0xA2 0xA0 0xAD 0x4F 0xA4 0xB7 0xA2 0xA4 0xA4 0xA3 0x7F 0x8B 0xF8 0xF6 0xE7 0x58 0x0 0x80 0xAB 0xAB 0x7F 0x54 0x8C 0x8E 0x8D 0x7F 0xAC 0xB4 0xB2 0xB3 0x4F 0xA1 0xA4 0x7F 0xA0 0xB3 0x7F 0xAB 0xA4 0xA0 0xB2 0xB3 0x7F 0x8B 0xF7 0xFB 0xE7 0x58 0x0 0x98 0xAE 0xB4 0xB1 0x7F 0xB3 0xAE 0xB3 0xA0 0xAB 0x7F 0xAB 0xA4 0xB5 0xA4 0xAB 0xB2 0x4F 0xA4 0xB7 0xA2 0xA4 0xA4 0xA3 0x7F 0xFB 0xF6 0xE7 0x58 0x1 0x6D 0xCD 0x0 0x7F 0xA8 0xB2 0x7F 0xAE 0xB5 0xA4 0xB1 0x4F 0xFC 0x71 0xFE 0x73 0x7F 0xB3 0xA0 0xAB 0xAB 0xE7 0x58 0x1 0x6D 0xCD 0x0)
336 ;; (list
337 ;; "Sleeping on the"
338 ;; 0x4F
339 ;; "job again are we?"
340 ;; 0x51
341 ;; 0x00
342 ;; "test"
343 ;; 0x59
344 ;; "EOM")
345
346
347 )
348 (int-array)
349 (write-rom!))
350 (root)
351
352 )
353
186 ) 354 )
187 355
356 (comment
357 "Hello there![0x4F]Welcome to the[0x55]world of [POKE]MON![0x51]My
358 name is OAK![0x4F]People call me[0x55]the [POKE]MON PROF![0x58]This
359 world is[0x4F]inhabited by[0x55]creatures
360 called[0x55][POKE]MON![0x50][0x50][0x51]For some people,
361 [0x4F][POKE]MON are[0x55]pets. Others use[0x55]them for
362 fights.[0x51]Myself...[0x51]I study [POKE]MON[0x4F]as a
363 profession.[0x58]First, what is[0x4F]your name?[0x58]This is my
364 grand-[0x4F]son. He's been[0x55]your rival since[0x55]you were a
365 baby.[0x51]...Erm, what is[0x4F]his name again?[0x58][RED]![0x51]Your
366 very own[0x4F][POKE]MON legend is[0x55]about to unfold![0x51]A world
367 of dreams[0x4F]and adventures[0x55]with [POKE]MON[0x55]awaits! Let's
368 go![0x57]")
369
370
371
372
373
374
375
376
377
378
379
380
381