Mercurial > vba-clojure
view clojure/com/aurellem/world/practice.clj @ 298:95afeea88c3a
found a second good character-item that can serve as a target
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 30 Mar 2012 22:41:25 -0500 |
parents | df9cad9909d2 |
children | de172acc5a03 |
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.exp pokemon))4 (:use (com.aurellem.exp item-bridge))5 (:import [com.aurellem.gb.gb_driver SaveState]))8 ;;(def original-rom (rom(root)))11 (def hex-pc (comp hex PC))13 (defn nstep [state n]14 (if (zero? n) state15 (recur (step state) (dec n))))18 (defn view-memory*19 "View a region of indexable memory in the given state."20 [state start length]21 ((comp vec map)22 #((comp aget) (memory state) %)23 (range start (+ start length))))26 (defn state-surprise27 "This is one tick before the trainer goes [!]"28 []29 (->30 (pre-trainer-battle)31 (step [:r])32 (step)33 (ntick 88147)34 ;(step [:r])36 ;(step [:r])37 ;(step [:r])38 ;(step [:r])39 ;(step [:r])40 ))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 ))87 (defn state-speak88 "This is when the trainer speaks."89 []90 (->91 (pre-trainer-battle)92 (set-memory 0xD354 0x0)93 (step [:r])94 (step)95 (ntick 88147)96 (tick)97 (nstep 102)99 ;(step [:r])101 ;(step [:r])102 ;(step [:r])103 ;(step [:r])104 ;(step [:r])105 ))109 (defn get-memory [state n]110 (aget (memory state) n))112 (defn first-change113 "Watch the current memory location as it ticks,114 return the first state that differs at location mem."115 [state n]116 (tick state)117 (set-state! state)118 (let [init (aget (memory state) n)]119 (loop []120 (if (= (aget (memory) n) init)121 (do122 (com.aurellem.gb.Gb/tick)123 (recur))))124 (update-state)))129 (defn spell-array130 [array mem n]131 (character-codes->str132 (take n (drop mem133 (vec array)))))135 (defn spell136 ([state mem n]137 (spell (memory state) mem n))138 ([mem n] (spell @current-state mem n)))142 (comment143 (println)144 (print (character-codes->str (take 6000 (drop 0xA75F4145 (vec(com.aurellem.gb.gb-driver/rom)))))))147 ;(dorun (map println (view-memory* (state-surprise) 0x1AEF 1600)))151 (def surprise-words152 [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])154 (defn sublist155 "Unshifts the list until the sublist is at the start."156 [list sub]157 (cond158 (empty? sub) list159 (empty? list) nil160 (= (take (count sub) list) sub) list161 :else (recur (rest list) sub)))163 (defn find-sublist164 "Returns the position of the first occurence of sublist."165 [list sub]166 (loop [n 0 a list]167 (cond168 (empty? a) nil169 (= (take (count sub) a) sub) n170 :else (recur (inc n) (rest a)))))172 (defn find-sublists173 "Returns a vector of the occurences of sublists."174 [list sub]175 (let [m (find-sublist list sub)]176 (if (nil? m) '()177 (cons m178 (map (partial + (inc m))179 (find-sublists180 (drop (inc m) list)181 sub))))))185 (defn search-rom186 "Search for the given codes in ROM, returning short snippets of187 text around the results."188 ([codes k]189 (search-rom com.aurellem.gb.gb-driver/original-rom codes k))190 ([rom codes k]191 (map192 (fn [n]193 [(hex n)194 (take k (drop n rom))])196 (find-sublists197 rom198 codes))))200 (defn spelling-bee201 "Search for the given string in ROM, returning short snippets of202 text around the results."203 ([str k]204 (spelling-bee com.aurellem.gb.gb-driver/original-rom str k))205 ([rom str k]206 (map207 (fn [[address snip]]208 [address (character-codes->str snip)])209 (search-rom rom (str->character-codes str) k))))215 (defn change-speech216 ([state str k]217 (loop [ops str218 s state219 n k]220 (if (empty? ops) s221 (recur222 (rest ops)223 (set-memory (first-change s (+ 0xC4B9 n)) (+ 0xC4B9 n)224 (first ops))225 (if (not= n 19) (inc n)226 (+ n 21))))))227 ([str k]228 (change-speech (state-speak) str k))229 ([str]230 (change-speech str 0)))234 (defn rewrite-memory235 "Alters the vector of memory. Treats strings as lists of character236 ops."237 ([mem start strs-or-ops]238 (let [x (first strs-or-ops)]239 (cond (empty? strs-or-ops) mem240 (string? x)242 (recur mem start243 (concat244 (str->character-codes x)245 (rest strs-or-ops)))246 :else247 (recur248 (assoc mem start x)249 (inc start)250 (rest strs-or-ops))))))252 (def rewrite-rom253 "Alters the ROM array using write-memory. Takes a list of254 various strings/bytes as data."255 (partial rewrite-memory (vec (rom(root)))))257 (defn restore-rom! [] (write-rom! original-rom))261 (def oak-intro263 (list "Hello there!"264 0x4F265 "Welcome to the"266 0x55267 "world of "268 0x54269 "MON!"270 0x51271 "My name is OAK!"272 0x4F273 "People call me"274 0x55275 "the "276 0x54277 "MON PROF!"278 0x58279 "This world is"280 0x4F281 "inhabited by"282 0x55283 "creatures called"284 0x55285 0x54286 "MON!"287 0x50288 0x50289 0x51290 "For some people, "291 0x4F292 0x54293 "MON are"294 0x55295 "pets. Others use"296 0x55297 "them for fights."298 0x51299 "Myself..."300 0x51301 "I study "302 0x54303 "MON"304 0x4F305 "as a profession."306 0x58307 "First, what is"308 0x4F309 "your name?"310 0x58311 "This is my grand-"312 0x4F313 "son. He's been"314 0x55315 "your rival since"316 0x55317 "you were a baby."318 0x51319 "...Erm, what is"320 0x4F321 "his name again?"322 0x58323 0x52324 "!"325 0x51326 "Your very own"327 0x4F328 0x54329 "MON legend is"330 0x55331 "about to unfold!"332 0x51333 "A world of dreams"334 0x4F335 "and adventures"336 0x55337 "with "338 0x54339 "MON"340 0x55341 "awaits! Let's go!"342 0x57) )344 (defn state-intro345 "Professor Oak speaks!"346 []347 (do348 (->349 (rewrite-rom 0xA07BB350 (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 0x8E 0x8D 0x7F 0xA0 0xB1 0xA4 0x55 0xAF 0xA4 0xB3 0xB2 0xF1 0x7F 0x8E 0x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0x59359 ;; "EOM")362 )363 (int-array)364 (write-rom!))365 (root)367 )369 )371 (comment372 "Hello there![0x4F]Welcome to the[0x55]world of [POKE]MON![0x51]My373 name is OAK![0x4F]People call me[0x55]the [POKE]MON PROF![0x58]This374 world is[0x4F]inhabited by[0x55]creatures375 called[0x55][POKE]MON![0x50][0x50][0x51]For some people,376 [0x4F][POKE]MON are[0x55]pets. Others use[0x55]them for377 fights.[0x51]Myself...[0x51]I study [POKE]MON[0x4F]as a378 profession.[0x58]First, what is[0x4F]your name?[0x58]This is my379 grand-[0x4F]son. He's been[0x55]your rival since[0x55]you were a380 baby.[0x51]...Erm, what is[0x4F]his name again?[0x58][RED]![0x51]Your381 very own[0x4F][POKE]MON legend is[0x55]about to unfold![0x51]A world382 of dreams[0x4F]and adventures[0x55]with [POKE]MON[0x55]awaits! Let's383 go![0x57]")