Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 266:c85549460218
script: got oak's parcel
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Mar 2012 23:04:12 -0500 |
parents | 0297d315b574 |
children | d68a191997ca |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-02 (:use (com.aurellem.gb gb-driver vbm characters))3 (:use (com.aurellem.run title save-corruption))4 (:use (com.aurellem.exp item-bridge))5 (:import [com.aurellem.gb.gb_driver SaveState]))7 (defn-memo boot-root []8 [ [] (root)])10 (defn-memo to-rival-name11 ([] (to-rival-name (boot-root)))12 ([script]13 (-> script14 title15 oak16 name-entry-rlm17 scroll-text18 scroll-text19 scroll-text20 scroll-text21 scroll-text22 )))24 (defn-memo name-rival-bootstrap25 ([] (name-rival-bootstrap (to-rival-name)))26 ([script]27 (->> script28 (advance [] [:a])29 (advance [] [:r] DE)30 (play-moves31 [[]32 [:r] [] [:r] [] [:r] [] [:r] []33 [:r] [] [:r] [] [:r] [] [:d] []34 [:d] [:a] ;; space35 [:l] [] [:d] [:a] ;; [PK]36 [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G37 [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK]38 [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G39 [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK]41 [:d] [] [:r] [:a] ;; finish42 ]))))44 (defn walk45 "Move the character along the given directions."46 [directions script]47 (reduce (fn [script direction]48 (move direction script))49 script directions))51 (def ↑ [:u])52 (def ↓ [:d])53 (def ← [:l])54 (def → [:r])56 (defn-memo leave-house57 ([] (leave-house (name-rival-bootstrap)))58 ([script]59 (->> script60 finish-title61 start-walking62 walk-to-stairs63 walk-to-door64 (walk [↓ ↓]))))66 (defn-memo to-pallet-town-edge67 ([] (to-pallet-town-edge (leave-house)))68 ([script]69 (->> script70 start-walking71 (walk [→ → → → →72 ↑ ↑ ↑ ↑ ↑ ↑]))))74 (defn end-text [script]75 (->> script76 (scroll-text)77 (play-moves [[] [:a]])))79 (defn-memo start-pikachu-battle80 ([] (start-pikachu-battle81 (to-pallet-town-edge)))82 ([script]83 (->> script84 (advance [:b] [:b :a] DE)85 (scroll-text)86 (play-moves [[:b]])87 (scroll-text)88 (end-text) ;; battle begins89 (scroll-text))))91 (defn-memo capture-pikachu92 ([] (capture-pikachu (start-pikachu-battle)))93 ([script]94 (->> script95 (scroll-text 2)96 (end-text))))98 (defn-memo go-to-lab99 ([] (go-to-lab (capture-pikachu)))100 ([script]101 (->> script102 (scroll-text 5)103 (end-text)104 (scroll-text)105 (end-text)106 (scroll-text 8)107 (end-text)108 (scroll-text)109 (end-text))))111 (defn-memo obtain-pikachu112 ([] (obtain-pikachu (go-to-lab)))113 ([script]114 (->> script115 (scroll-text)116 (play-moves117 (concat118 (repeat 51 [])119 [[:a] []]))120 (walk [↓ ↓ → → ↑])121 (play-moves122 (concat [[] [:a]]123 (repeat 100 [])))124 (scroll-text 9)125 (end-text)126 (scroll-text 7)128 (play-moves129 (concat130 (repeat 42 [])131 [[:b] [:b] [:b] [:b]])))))133 (defn-memo begin-battle-with-rival134 ([] (begin-battle-with-rival135 (obtain-pikachu)))136 ([script]137 (->> script138 (walk [↓ ↓ ↓ ↓])139 (scroll-text 3)140 (end-text)141 (scroll-text))))143 (defn search-string144 [array string]145 (let [codes146 (str->character-codes string)147 codes-length (count codes)148 mem (vec array)149 mem-length (count mem)]150 (loop [idx 0]151 (if (< (- mem-length idx) codes-length)152 nil153 (if (= (subvec mem idx (+ idx codes-length))154 codes)155 idx156 (recur (inc idx)))))))158 (defn critical-hit159 "Put the cursor over the desired attack. This program will160 determine the appropriate amount of blank frames to161 insert before pressing [:a] to ensure that the attack is162 a critical hit."163 [script]164 (loop [blanks 6]165 (let [new-script166 (->> script167 (play-moves168 (concat (repeat blanks [])169 [[:a][]])))]170 (if (let [future-state171 (run-moves (second new-script)172 (repeat 400 []))174 result (search-string (memory future-state)175 "Critical")]176 (if result177 (println "critical hit with" blanks "blank frames"))178 result)179 new-script180 (recur (inc blanks))))))182 (defn-memo battle-with-rival183 ([] (battle-with-rival184 (begin-battle-with-rival)))185 ([script]186 (->> script187 (play-moves (repeat 381 []))188 (play-moves [[:a]])189 (critical-hit)190 (play-moves (repeat 100 []))191 (scroll-text)192 (play-moves193 (concat (repeat 275 []) [[:a]]))194 (critical-hit)195 (play-moves (repeat 100 []))196 (scroll-text)197 (play-moves198 (concat (repeat 270 []) [[:a]]))199 (play-moves [[][][][][][][][][:a]]))))201 (defn-memo finish-rival-text202 ([] (finish-rival-text203 (battle-with-rival)))204 ([script]205 (->> script206 (scroll-text 2)207 (end-text)208 (scroll-text 9)209 (end-text))))211 (defn do-nothing [n script]212 (->> script213 (play-moves214 (repeat n []))))216 (defn-memo pikachu-comes-out217 ([] (pikachu-comes-out218 (finish-rival-text)))219 ([script]220 (->> script221 (do-nothing 177)222 (end-text)223 (scroll-text 7)224 (end-text))))226 (defn-memo leave-oaks-lab227 ([] (leave-oaks-lab228 (pikachu-comes-out)))229 ([script]230 (->> script231 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓]))))233 (defn-memo oaks-lab->pallet-town-edge234 ([] (oaks-lab->pallet-town-edge235 (leave-oaks-lab)))236 ([script]237 (->> script238 (walk [← ← ← ←239 ↑ ↑ ↑ ↑240 ↑ ↑ ↑ ↑ ↑ ↑241 → ↑]))))244 (defn move-thru-grass245 [direction script]246 (loop [blanks 0]247 (let [new-script248 (->> script249 (play-moves (repeat blanks []))250 (move direction))252 future-state253 (run-moves (second new-script)254 (repeat 600 []))256 result (search-string (memory future-state)257 "Wild")]258 (if (nil? result)259 new-script260 (recur (inc blanks))))))262 (defn walk-thru-grass263 [directions script]264 (reduce (fn [script direction]265 (move-thru-grass direction script))266 script directions))268 (defn-memo pallet-edge->viridian-mart269 ([] (pallet-edge->viridian-mart270 (oaks-lab->pallet-town-edge)))271 ([script]272 (->> script273 ;; leave straight grass274 (walk-thru-grass275 [↑ ↑ ↑ ↑ ↑])277 (walk [↑ ↑ ↑ ↑])279 (walk-thru-grass280 [← ← ↑])281 (walk [↑ ↑ ↑ ↑ → → → ])283 (walk-thru-grass284 [→ ↑ ↑ ←])286 (walk287 [← ←288 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑289 → → → → ])291 ;; this part it dependent on that292 ;; stupid NPC in the grass patch293 (walk-thru-grass294 [→ →295 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ])297 (walk298 [↑ ↑299 ← ← ← ←300 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑301 ← ←302 ↑ ↑ ↑ ↑303 → → → → → → → → → →304 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))306 (defn-memo get-oaks-parcel307 ([] (get-oaks-parcel308 (pallet-edge->viridian-mart)))309 ([script]310 (->> script311 (end-text)312 (scroll-text 3)313 (do-nothing 197)314 (play-moves [[:a] []])315 (walk [↓ ↓ → ↓]))))