Mercurial > vba-clojure
view clojure/com/aurellem/world/practice.clj @ 247:22f58fa47c3c
starting work on unoptimized bootstrap script.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Mar 2012 03:08:54 -0500 |
parents | d5dddf33543c |
children | b2f9a0cb13e3 |
line wrap: on
line source
1 (ns com.aurellem.world.practice2 (:use (com.aurellem.gb gb-driver))4 (:use (com.aurellem.gb saves util constants gb-driver vbm items assembly characters))5 (:use (com.aurellem.run title))6 (:use (com.aurellem.exp pokemon))7 (:use (com.aurellem.exp item-bridge))8 (:import [com.aurellem.gb.gb_driver SaveState]))11 ;;(def original-rom (rom(root)))14 (def hex-pc (comp hex PC))16 (defn nstep [state n]17 (if (zero? n) state18 (recur (step state) (dec n))))21 (defn view-memory* [state start length]22 ((comp vec map)23 #((comp aget) (memory state) %)24 (range start (+ start length))))27 (defn state-surprise28 "This is one tick before the trainer goes [!]"29 []30 (->31 (pre-trainer-battle)32 (step [:r])33 (step)34 (ntick 88147)35 ;(step [:r])37 ;(step [:r])38 ;(step [:r])39 ;(step [:r])40 ;(step [:r])41 ))42 (defn state-inject43 "I have replaced the letter e with e-acute @ 0xC4E8."44 []45 (read-state "inject-surprise"))50 (defn pc-trail51 "Track the PC for a number of ticks."52 [state ticks]53 (tick state)54 (set-state! state)55 (loop [pcs [(PC)] ]56 (if (> (count pcs) ticks) pcs57 (do58 (com.aurellem.gb.Gb/tick)59 (recur (conj pcs (PC)))))))63 (defn differences [list-1 list-2]64 (remove65 (fn [[a b c]] (= b c))66 (map vector67 (range)68 list-169 list-2)))71 (defn pc-diff [state-1 state-2]72 (differences (map hex (pc-trail state-1 10000))73 (map hex (pc-trail state-2 10000))))76 (defn memory-diff [state-1 state-2]77 (remove78 (fn[[a b c]] (= b c))79 (map (comp vec (partial map hex) list)80 (range)81 (vec (memory state-1))82 (vec (memory state-2)))83 )84 )88 (defn state-speak89 "This is when the trainer speaks."90 []91 (->92 (pre-trainer-battle)93 (set-memory 0xD354 0x0)94 (step [:r])95 (step)96 (ntick 88147)97 (tick)98 (nstep 102)100 ;(step [:r])102 ;(step [:r])103 ;(step [:r])104 ;(step [:r])105 ;(step [:r])106 ))110 (defn get-memory [state n]111 (aget (memory state) n))113 (defn first-change114 "Watch the current memory location as it ticks,115 return the first state that differs at location mem."116 [state n]117 (tick state)118 (set-state! state)119 (let [init (aget (memory state) n)]120 (loop []121 (if (= (aget (memory) n) init)122 (do123 (com.aurellem.gb.Gb/tick)124 (recur))))125 (update-state)))130 (defn spell-array131 [array mem n]132 (character-codes->str133 (take n (drop mem134 (vec array)))))136 (defn spell137 ([state mem n]138 (spell (memory state) mem n))139 ([mem n] (spell @current-state mem n)))143 (comment144 (println)145 (print (character-codes->str (take 6000 (drop 0xA75F4146 (vec(com.aurellem.gb.gb-driver/rom)))))))148 ;(dorun (map println (view-memory* (state-surprise) 0x1AEF 1600)))152 (def surprise-words153 [0x80 0xAB 0xAB 0x7F 0xB1 0xA8 0xA6 0xA7 0xB3 0xE7 0x7F 0x8B 0xA4 0xB3 0xE0 0xB2 0x7F 0xB1 0xAE 0xAB 0xAB 0x7F 0xB3 0xA7 0xA4 0x7F 0xA3 0xA8 0xA2 0xA4 0xE7])155 (defn sublist156 "Unshifts the list until the sublist is at the start."157 [list sub]158 (cond159 (empty? sub) list160 (empty? list) nil161 (= (take (count sub) list) sub) list162 :else (recur (rest list) sub)))164 (defn find-sublist165 "Returns the position of the first occurence of sublist."166 [list sub]167 (loop [n 0 a list]168 (cond169 (empty? a) nil170 (= (take (count sub) a) sub) n171 :else (recur (inc n) (rest a)))))173 (defn find-sublists174 "Returns a vector of the occurences of sublists."175 [list sub]176 (let [m (find-sublist list sub)]177 (if (nil? m) '()178 (cons m179 (map (partial + (inc m))180 (find-sublists181 (drop (inc m) list)182 sub))))))184 (defn spelling-bee185 "Search for the given string in ROM, returning short snippets of186 text around the results."187 [str k]188 (let [rom (rom(root))]189 (map190 (fn [n]191 [(hex n)192 (character-codes->str (take k (drop n rom)))])194 (find-sublists195 rom196 (str->character-codes str)))))201 (defn change-speech202 ([state str k]203 (loop [ops str204 s state205 n k]206 (if (empty? ops) s207 (recur208 (rest ops)209 (set-memory (first-change s (+ 0xC4B9 n)) (+ 0xC4B9 n)210 (first ops))211 (if (not= n 19) (inc n)212 (+ n 21))))))213 ([str k]214 (change-speech (state-speak) str k))215 ([str]216 (change-speech str 0)))220 (defn rewrite-memory221 "Alters the vector of memory. Treats strings as lists of character222 ops."223 ([mem start strs-or-ops]224 (let [x (first strs-or-ops)]225 (cond (empty? strs-or-ops) mem226 (string? x)228 (recur mem start229 (concat230 (str->character-codes x)231 (rest strs-or-ops)))232 :else233 (recur234 (assoc mem start x)235 (inc start)236 (rest strs-or-ops))))))238 (def rewrite-rom239 "Alters the ROM array using write-memory."240 (partial rewrite-memory (vec (rom(root)))))242 (defn restore-rom! [] (write-rom! original-rom))246 (def oak-intro248 (list "Hello there!"249 0x4F250 "Welcome to the"251 0x55252 "world of "253 0x54254 "MON!"255 0x51256 "My name is OAK!"257 0x4F258 "People call me"259 0x55260 "the "261 0x54262 "MON PROF!"263 0x58264 "This world is"265 0x4F266 "inhabited by"267 0x55268 "creatures called"269 0x55270 0x54271 "MON!"272 0x50273 0x50274 0x51275 "For some people, "276 0x4F277 0x54278 "MON are"279 0x55280 "pets. Others use"281 0x55282 "them for fights."283 0x51284 "Myself..."285 0x51286 "I study "287 0x54288 "MON"289 0x4F290 "as a profession."291 0x58292 "First, what is"293 0x4F294 "your name?"295 0x58296 "This is my grand-"297 0x4F298 "son. He's been"299 0x55300 "your rival since"301 0x55302 "you were a baby."303 0x51304 "...Erm, what is"305 0x4F306 "his name again?"307 0x58308 0x52309 "!"310 0x51311 "Your very own"312 0x4F313 0x54314 "MON legend is"315 0x55316 "about to unfold!"317 0x51318 "A world of dreams"319 0x4F320 "and adventures"321 0x55322 "with "323 0x54324 "MON"325 0x55326 "awaits! Let's go!"327 0x57) )329 (defn state-intro330 "Professor Oak speaks!"331 []332 (do333 (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 0xB2 0xB3 0x4F 0xA1 0xA4 0x7F 0xA0 0xB3 0x7F 0xAB 0xA4 0xA0 0xB2 0xB3 0x7F 0x8B 0xF8 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 0xFE 0xF6 0xE7 0x58 0x0 0x8D 0xAE 0x7F 0x54 0x8C 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 ;; (list337 ;; "Sleeping on the"338 ;; 0x4F339 ;; "job again are we?"340 ;; 0x51341 ;; 0x00342 ;; "test"343 ;; 0x59344 ;; "EOM")347 )348 (int-array)349 (write-rom!))350 (root)352 )354 )356 (comment357 "Hello there![0x4F]Welcome to the[0x55]world of [POKE]MON![0x51]My358 name is OAK![0x4F]People call me[0x55]the [POKE]MON PROF![0x58]This359 world is[0x4F]inhabited by[0x55]creatures360 called[0x55][POKE]MON![0x50][0x50][0x51]For some people,361 [0x4F][POKE]MON are[0x55]pets. Others use[0x55]them for362 fights.[0x51]Myself...[0x51]I study [POKE]MON[0x4F]as a363 profession.[0x58]First, what is[0x4F]your name?[0x58]This is my364 grand-[0x4F]son. He's been[0x55]your rival since[0x55]you were a365 baby.[0x51]...Erm, what is[0x4F]his name again?[0x58][RED]![0x51]Your366 very own[0x4F][POKE]MON legend is[0x55]about to unfold![0x51]A world367 of dreams[0x4F]and adventures[0x55]with [POKE]MON[0x55]awaits! Let's368 go![0x57]")