Mercurial > vba-clojure
view clojure/com/aurellem/world/practice.clj @ 268:82ee2704c973
Since the game uses zeros as delimiters in the evolution/learnset section, it increments all of the move/pokemon indices by 1. Altered my code so that all returned values are consistently non-incremented.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Mon, 26 Mar 2012 23:25:18 -0500 |
parents | a44a2c459aeb |
children | a60ea8632ff4 |
line wrap: on
line source
1 (ns com.aurellem.world.practice2 (:use (com.aurellem.gb saves util constants gb-driver vbm items assembly characters))3 (:use (com.aurellem.run title))4 (:use (com.aurellem.exp pokemon))5 (:use (com.aurellem.exp item-bridge))6 (:import [com.aurellem.gb.gb_driver SaveState]))9 ;;(def original-rom (rom(root)))12 (def hex-pc (comp hex PC))14 (defn nstep [state n]15 (if (zero? n) state16 (recur (step state) (dec n))))19 (defn view-memory*20 "View a region of indexable memory in the given state."21 [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))))))186 (defn search-rom187 "Search for the given codes in ROM, returning short snippets of188 text around the results."189 ([codes k]190 (search-rom com.aurellem.gb.gb-driver/original-rom codes k))191 ([rom codes k]192 (map193 (fn [n]194 [(hex n)195 (take k (drop n rom))])197 (find-sublists198 rom199 codes))))201 (defn spelling-bee202 "Search for the given string in ROM, returning short snippets of203 text around the results."204 ([str k]205 (spelling-bee com.aurellem.gb.gb-driver/original-rom str k))206 ([rom str k]207 (map208 (fn [[address snip]]209 [address (character-codes->str snip)]210 (search-rom rom (str->character-codes str) k)))))216 (defn change-speech217 ([state str k]218 (loop [ops str219 s state220 n k]221 (if (empty? ops) s222 (recur223 (rest ops)224 (set-memory (first-change s (+ 0xC4B9 n)) (+ 0xC4B9 n)225 (first ops))226 (if (not= n 19) (inc n)227 (+ n 21))))))228 ([str k]229 (change-speech (state-speak) str k))230 ([str]231 (change-speech str 0)))235 (defn rewrite-memory236 "Alters the vector of memory. Treats strings as lists of character237 ops."238 ([mem start strs-or-ops]239 (let [x (first strs-or-ops)]240 (cond (empty? strs-or-ops) mem241 (string? x)243 (recur mem start244 (concat245 (str->character-codes x)246 (rest strs-or-ops)))247 :else248 (recur249 (assoc mem start x)250 (inc start)251 (rest strs-or-ops))))))253 (def rewrite-rom254 "Alters the ROM array using write-memory. Takes a list of255 various strings/bytes as data."256 (partial rewrite-memory (vec (rom(root)))))258 (defn restore-rom! [] (write-rom! original-rom))262 (def oak-intro264 (list "Hello there!"265 0x4F266 "Welcome to the"267 0x55268 "world of "269 0x54270 "MON!"271 0x51272 "My name is OAK!"273 0x4F274 "People call me"275 0x55276 "the "277 0x54278 "MON PROF!"279 0x58280 "This world is"281 0x4F282 "inhabited by"283 0x55284 "creatures called"285 0x55286 0x54287 "MON!"288 0x50289 0x50290 0x51291 "For some people, "292 0x4F293 0x54294 "MON are"295 0x55296 "pets. Others use"297 0x55298 "them for fights."299 0x51300 "Myself..."301 0x51302 "I study "303 0x54304 "MON"305 0x4F306 "as a profession."307 0x58308 "First, what is"309 0x4F310 "your name?"311 0x58312 "This is my grand-"313 0x4F314 "son. He's been"315 0x55316 "your rival since"317 0x55318 "you were a baby."319 0x51320 "...Erm, what is"321 0x4F322 "his name again?"323 0x58324 0x52325 "!"326 0x51327 "Your very own"328 0x4F329 0x54330 "MON legend is"331 0x55332 "about to unfold!"333 0x51334 "A world of dreams"335 0x4F336 "and adventures"337 0x55338 "with "339 0x54340 "MON"341 0x55342 "awaits! Let's go!"343 0x57) )345 (defn state-intro346 "Professor Oak speaks!"347 []348 (do349 (->350 (rewrite-rom 0xA07BB351 (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 0xA8 0xB2 0x7F 0x8E 0x80 0x8A 0xE7 0x4F 0x8F 0xA4 0xAE 0xAF 0xAB 0xA4 0x7F 0xA2 0xA0 0xAB 0xAB 0x7F 0xAC 0xA4 0x55 0xB3 0xA7 0xA4 0x7F 0x8F 0x8C 0x8E 0x8D 0x7F 0x8F 0x91 0x8E 0x85 0xE7 0x58 0x93 0xA7 0xA8 0xB2 0x7F 0xB6 0xAE 0xB1 0xAB 0xA3 0x7F 0xA8 0xB2 0x4F 0xA8 0xAD 0xA7 0xA0 0xA1 0xA8 0xB3 0xA4 0xA3 0x7F 0xA1 0xB8 0x55 0xA2 0xB1 0xA4 0xA0 0xB3 0xB4 0xB1 0xA4 0xB2 0x7F 0xA2 0xA0 0xAB 0xAB 0xA4 0xA3 0x55 0x54 0x8C 0x8E 0x8D 0xE7 0x50 0x50 0x51 0x85 0xAE 0xB1 0x7F 0xB2 0xAE 0xAC 0xA4 0x7F 0xAF 0xA4 0xAE 0xAF 0xAB 0xA4 0xF3 0x7F 0x4F 0x54 0x8C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;; (list353 ;; "Sleeping on the"354 ;; 0x4F355 ;; "job again are we?"356 ;; 0x51357 ;; 0x00358 ;; "test"359 ;; 0x59360 ;; "EOM")363 )364 (int-array)365 (write-rom!))366 (root)368 )370 )372 (comment373 "Hello there![0x4F]Welcome to the[0x55]world of [POKE]MON![0x51]My374 name is OAK![0x4F]People call me[0x55]the [POKE]MON PROF![0x58]This375 world is[0x4F]inhabited by[0x55]creatures376 called[0x55][POKE]MON![0x50][0x50][0x51]For some people,377 [0x4F][POKE]MON are[0x55]pets. Others use[0x55]them for378 fights.[0x51]Myself...[0x51]I study [POKE]MON[0x4F]as a379 profession.[0x58]First, what is[0x4F]your name?[0x58]This is my380 grand-[0x4F]son. He's been[0x55]your rival since[0x55]you were a381 baby.[0x51]...Erm, what is[0x4F]his name again?[0x58][RED]![0x51]Your382 very own[0x4F][POKE]MON legend is[0x55]about to unfold![0x51]A world383 of dreams[0x4F]and adventures[0x55]with [POKE]MON[0x55]awaits! Let's384 go![0x57]")