Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 274:210b465e4720
refactored walking code from buy-initial-objects to its own function.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 27 Mar 2012 11:30:58 -0500 |
parents | 3266bd0a6300 |
children | 68f4e87c8f51 |
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-text)))23 (defn-memo name-rival-bootstrap24 ([] (name-rival-bootstrap (to-rival-name)))25 ([script]26 (->> script27 (advance [] [:a])28 (advance [] [:r] DE)29 (play-moves30 [[]31 [:r] [] [:r] [] [:r] [] [:r] []32 [:r] [] [:r] [] [:r] [] [:d] []33 [:d] [:a] ;; space34 [:l] [] [:d] [:a] ;; [PK]35 [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G36 [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK]37 [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G38 [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK]40 [:d] [] [:r] [:a] ;; finish41 ]))))43 (defn walk44 "Move the character along the given directions."45 [directions script]46 (reduce (fn [script direction]47 (move direction script))48 script directions))50 (def ↑ [:u])51 (def ↓ [:d])52 (def ← [:l])53 (def → [:r])55 (defn-memo leave-house56 ([] (leave-house (name-rival-bootstrap)))57 ([script]58 (->> script59 finish-title60 start-walking61 walk-to-stairs62 walk-to-door63 (walk [↓ ↓]))))65 (defn-memo to-pallet-town-edge66 ([] (to-pallet-town-edge (leave-house)))67 ([script]68 (->> script69 start-walking70 (walk [→ → → → →71 ↑ ↑ ↑ ↑ ↑ ↑]))))73 (defn end-text [script]74 (->> script75 (scroll-text)76 (play-moves [[] [:a]])))78 (defn-memo start-pikachu-battle79 ([] (start-pikachu-battle80 (to-pallet-town-edge)))81 ([script]82 (->> script83 (advance [:b] [:b :a] DE)84 (scroll-text)85 (play-moves [[:b]])86 (scroll-text)87 (end-text) ;; battle begins88 (scroll-text))))90 (defn-memo capture-pikachu91 ([] (capture-pikachu (start-pikachu-battle)))92 ([script]93 (->> script94 (scroll-text 2)95 (end-text))))97 (defn-memo go-to-lab98 ([] (go-to-lab (capture-pikachu)))99 ([script]100 (->> script101 (scroll-text 5)102 (end-text)103 (scroll-text)104 (end-text)105 (scroll-text 8)106 (end-text)107 (scroll-text)108 (end-text))))110 (defn-memo obtain-pikachu111 ([] (obtain-pikachu (go-to-lab)))112 ([script]113 (->> script114 (scroll-text)115 (play-moves116 (concat117 (repeat 51 [])118 [[:a] []]))119 (walk [↓ ↓ → → ↑])120 (play-moves121 (concat [[] [:a]]122 (repeat 100 [])))123 (scroll-text 9)124 (end-text)125 (scroll-text 7)127 (play-moves128 (concat129 (repeat 42 [])130 [[:b] [:b] [:b] [:b]])))))132 (defn-memo begin-battle-with-rival133 ([] (begin-battle-with-rival134 (obtain-pikachu)))135 ([script]136 (->> script137 (walk [↓ ↓ ↓ ↓])138 (scroll-text 3)139 (end-text)140 (scroll-text))))142 (defn search-string143 [array string]144 (let [codes145 (str->character-codes string)146 codes-length (count codes)147 mem (vec array)148 mem-length (count mem)]149 (loop [idx 0]150 (if (< (- mem-length idx) codes-length)151 nil152 (if (= (subvec mem idx (+ idx codes-length))153 codes)154 idx155 (recur (inc idx)))))))157 (defn critical-hit158 "Put the cursor over the desired attack. This program will159 determine the appropriate amount of blank frames to160 insert before pressing [:a] to ensure that the attack is161 a critical hit."162 [script]163 (loop [blanks 6]164 (let [new-script165 (->> script166 (play-moves167 (concat (repeat blanks [])168 [[:a][]])))]169 (if (let [future-state170 (run-moves (second new-script)171 (repeat 400 []))173 result (search-string (memory future-state)174 "Critical")]175 (if result176 (println "critical hit with" blanks "blank frames"))177 result)178 new-script179 (recur (inc blanks))))))181 (defn-memo battle-with-rival182 ([] (battle-with-rival183 (begin-battle-with-rival)))184 ([script]185 (->> script186 (play-moves (repeat 381 []))187 (play-moves [[:a]])188 (critical-hit)189 (play-moves (repeat 100 []))190 (scroll-text)191 (play-moves192 (concat (repeat 275 []) [[:a]]))193 (critical-hit)194 (play-moves (repeat 100 []))195 (scroll-text)196 (play-moves197 (concat (repeat 270 []) [[:a]]))198 (play-moves [[][][][][][][][][:a]]))))200 (defn-memo finish-rival-text201 ([] (finish-rival-text202 (battle-with-rival)))203 ([script]204 (->> script205 (scroll-text 2)206 (end-text)207 (scroll-text 9)208 (end-text))))210 (defn do-nothing [n script]211 (->> script212 (play-moves213 (repeat n []))))215 (defn-memo pikachu-comes-out216 ([] (pikachu-comes-out217 (finish-rival-text)))218 ([script]219 (->> script220 (do-nothing 177)221 (end-text)222 (scroll-text 7)223 (end-text))))225 (defn-memo leave-oaks-lab226 ([] (leave-oaks-lab227 (pikachu-comes-out)))228 ([script]229 (->> script230 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓]))))232 (defn-memo oaks-lab->pallet-town-edge233 ([] (oaks-lab->pallet-town-edge234 (leave-oaks-lab)))235 ([script]236 (->> script237 (walk [← ← ← ←238 ↑ ↑ ↑ ↑239 ↑ ↑ ↑ ↑ ↑ ↑240 → ↑]))))242 (defn move-thru-grass243 [direction script]244 (loop [blanks 0]245 (let [new-script246 (->> script247 (play-moves (repeat blanks []))248 (move direction))250 future-state251 (run-moves (second new-script)252 (repeat 600 []))254 result (search-string (memory future-state)255 "Wild")]256 (if (nil? result)257 new-script258 (recur (inc blanks))))))260 (defn walk-thru-grass261 [directions script]262 (reduce (fn [script direction]263 (move-thru-grass direction script))264 script directions))266 (defn-memo pallet-edge->viridian-mart267 ([] (pallet-edge->viridian-mart true268 (oaks-lab->pallet-town-edge)))269 ([dodge-stupid-guy? script]270 (let [dodge-1 (if dodge-stupid-guy?271 [→ →]272 [→])273 dodge-2 (if dodge-stupid-guy?274 [↑ ↑ ←]275 [↑ ↑ ←])]277 (->> script278 ;; leave straight grass279 (walk-thru-grass280 [↑ ↑ ↑ ↑ ↑])282 (walk [↑ ↑ ↑ ↑])284 (walk-thru-grass285 [← ← ↑])286 (walk [↑ ↑ ↑ ↑ → → → ])288 (walk-thru-grass289 [→ ↑ ↑ ←])291 (walk292 [← ←293 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑294 → → → → ])296 ;; this part is dependent on that297 ;; stupid NPC in the grass patch298 (walk-thru-grass299 (concat dodge-1300 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))302 (walk303 (concat304 dodge-2305 [← ← ←306 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑307 ← ←308 ↑ ↑ ↑ ↑309 → → → → → → → → → →310 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))312 (defn-memo get-oaks-parcel313 ([] (get-oaks-parcel314 (pallet-edge->viridian-mart)))315 ([script]316 (->> script317 (end-text)318 (scroll-text 3)319 (do-nothing 197)320 (play-moves [[:a] []])321 (walk [↓ ↓ → ↓]))))323 (defn-memo viridian-store->oaks-lab324 ([] (viridian-store->oaks-lab325 (get-oaks-parcel)))326 ([script]327 (->> script328 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓329 ← ← ← ← ← ← ← ← ← ←330 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓331 ← ←332 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓333 ↓ ↓ ↓ ↓ ↓ ↓ ↓334 → → → → → → → →335 ↓ ↓ ↓ ↓336 ← ← ← ← ←337 ↓ ↓ ↓ ↓])339 (walk-thru-grass340 [↓ ↓ ↓ ↓ ↓ ↓ ↓])342 (walk [↓ ↓ ← ↓ ↓ ↓ ←343 ↓ ↓ ↓ ↓ ↓344 → → → ↑]))))346 (defn-memo viridian-store->oaks-lab-like-a-boss347 ([] (viridian-store->oaks-lab-like-a-boss348 (get-oaks-parcel)))349 ([script]350 (->> script351 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓352 ← ← ← ← ← ← ← ← ← ←353 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])355 (walk-thru-grass356 [↓ ↓ ↓ ↓ ↓])358 (walk359 [↓ ↓ ← ↓360 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓361 → →])363 (walk-thru-grass364 [→ ↓ ↓ ↓])366 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])368 (walk-thru-grass369 [↓ ↓ ↓ ↓ ↓ ↓ ↓])371 (walk [↓ ↓ ← ↓ ↓ ↓ ←372 ↓ ↓ ↓ ↓ ↓373 → → → ↑]))))375 (defn-memo deliver-oaks-parcel376 ([] (deliver-oaks-parcel377 (viridian-store->oaks-lab-like-a-boss)))378 ([script]379 (->> script380 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])381 (play-moves [[:a]])382 (scroll-text 11)383 (end-text)384 (end-text)385 (do-nothing 200)386 (end-text)387 (scroll-text 3)388 (end-text)389 (scroll-text 2)390 (end-text)391 (scroll-text 5)392 (end-text)393 (scroll-text 2)394 (end-text)395 (scroll-text 9)396 (end-text)397 (scroll-text 7)398 (end-text)399 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))401 (defn-memo return-to-viridian-mart402 ([] (return-to-viridian-mart403 (deliver-oaks-parcel)))404 ([script]405 (->> script406 oaks-lab->pallet-town-edge407 (pallet-edge->viridian-mart false))))409 (defn-memo walk-to-counter410 ([] (walk-to-counter411 (return-to-viridian-mart)))412 ([script]413 (->> script414 (walk [↑ ↑ ← ←]))))417 (defn-memo buy-initial-objects418 ([] (buy-initial-objects419 (walk-to-counter)))420 ([script]421 (->> script422 ;(do-nothing 200)423 (play-moves424 [[] [:a] []])425 (scroll-text)426 (do-nothing 100)427 (play-moves [[:a]])428 (do-nothing 100)429 (play-moves [[:a]])430 (do-nothing 100)431 (play-moves [[:a]])432 (do-nothing 100)433 (scroll-text)434 (do-nothing 100)435 (play-moves [[:a]])436 (do-nothing 100)437 (play-moves [[:a]])438 (do-nothing 100))))