Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 278:7ecea582ec9d
script: bought initial 5 items.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 27 Mar 2012 13:10:48 -0500 |
parents | 710bfbb1e048 |
children | aa9b8d9d5b76 |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-02 (:use (com.aurellem.gb gb-driver vbm characters money))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 (do258 (if (< 0 blanks)259 (do(println "avoided pokemon with" blanks "blank frames")))260 new-script)261 (recur (inc blanks))))))263 (defn walk-thru-grass264 [directions script]265 (reduce (fn [script direction]266 (move-thru-grass direction script))267 script directions))269 (defn-memo pallet-edge->viridian-mart270 ([] (pallet-edge->viridian-mart true271 (oaks-lab->pallet-town-edge)))272 ([dodge-stupid-guy? script]273 (let [dodge-1 (if dodge-stupid-guy?274 [→ →]275 [→])276 dodge-2 (if dodge-stupid-guy?277 [↑ ↑ ←]278 [↑ ↑ ←])]280 (->> script281 ;; leave straight grass282 (walk-thru-grass283 [↑ ↑ ↑ ↑ ↑])285 (walk [↑ ↑ ↑ ↑])287 (walk-thru-grass288 [← ← ↑])289 (walk [↑ ↑ ↑ ↑ → → → ])291 (walk-thru-grass292 [→ ↑ ↑ ←])294 (walk295 [← ←296 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑297 → → → → ])299 ;; this part is dependent on that300 ;; stupid NPC in the grass patch301 (walk-thru-grass302 (concat dodge-1303 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))305 (walk306 (concat307 dodge-2308 [← ← ←309 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑310 ← ←311 ↑ ↑ ↑ ↑312 → → → → → → → → → →313 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))315 (defn-memo get-oaks-parcel316 ([] (get-oaks-parcel317 (pallet-edge->viridian-mart)))318 ([script]319 (->> script320 (end-text)321 (scroll-text 3)322 (do-nothing 197)323 (play-moves [[:a] []])324 (walk [↓ ↓ → ↓]))))326 (defn-memo viridian-store->oaks-lab327 ([] (viridian-store->oaks-lab328 (get-oaks-parcel)))329 ([script]330 (->> script331 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓332 ← ← ← ← ← ← ← ← ← ←333 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓334 ← ←335 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓336 ↓ ↓ ↓ ↓ ↓ ↓ ↓337 → → → → → → → →338 ↓ ↓ ↓ ↓339 ← ← ← ← ←340 ↓ ↓ ↓ ↓])342 (walk-thru-grass343 [↓ ↓ ↓ ↓ ↓ ↓ ↓])345 (walk [↓ ↓ ← ↓ ↓ ↓ ←346 ↓ ↓ ↓ ↓ ↓347 → → → ↑]))))349 (defn-memo viridian-store->oaks-lab-like-a-boss350 ([] (viridian-store->oaks-lab-like-a-boss351 (get-oaks-parcel)))352 ([script]353 (->> script354 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓355 ← ← ← ← ← ← ← ← ← ←356 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])358 (walk-thru-grass359 [↓ ↓ ↓ ↓ ↓])361 (walk362 [↓ ↓ ← ↓363 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓364 → →])366 (walk-thru-grass367 [→ ↓ ↓ ↓])369 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])371 (walk-thru-grass372 [↓ ↓ ↓ ↓ ↓ ↓ ↓])374 (walk [↓ ↓ ← ↓ ↓ ↓ ←375 ↓ ↓ ↓ ↓ ↓376 → → → ↑]))))378 (defn-memo deliver-oaks-parcel379 ([] (deliver-oaks-parcel380 (viridian-store->oaks-lab-like-a-boss)))381 ([script]382 (->> script383 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])384 (play-moves [[:a]])385 (scroll-text 11)386 (end-text)387 (end-text)388 (do-nothing 200)389 (end-text)390 (scroll-text 3)391 (end-text)392 (scroll-text 2)393 (end-text)394 (scroll-text 5)395 (end-text)396 (scroll-text 2)397 (end-text)398 (scroll-text 9)399 (end-text)400 (scroll-text 7)401 (end-text)402 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))404 (defn-memo return-to-viridian-mart405 ([] (return-to-viridian-mart406 (deliver-oaks-parcel)))407 ([script]408 (->> script409 oaks-lab->pallet-town-edge410 (pallet-edge->viridian-mart false))))412 (defn-memo walk-to-counter413 ([] (walk-to-counter414 (return-to-viridian-mart)))415 ([script]416 (->> script417 (walk [↑ ↑ ← ←]))))419 (defn buy-item420 "Assumes that the main item-screen is up, and buys421 quantity of the nth item in the list, assuming that you422 have enough money."423 [n quantity script]424 (if (= 0 quantity)425 script426 (let [after-initial-pause427 (do-nothing 20 script)428 move-to-item429 (reduce (fn [script _]430 (->> script431 (play-moves [[:d]])432 (do-nothing 3)))433 after-initial-pause434 (range n))435 select-item436 (play-moves [[:a]] move-to-item)437 request-items438 (reduce (fn [script _]439 (->> script440 (play-moves [[:u]])441 (do-nothing 1)))442 select-item443 (range (dec quantity)))444 buy-items445 (->> request-items446 (do-nothing 3)447 (play-moves [[:a]])448 (scroll-text)449 (scroll-text)450 (play-moves [[:a]])451 (scroll-text))]452 buy-items)))455 (defn buy-items456 "Given a list of [item-no quantity], buys the quantity457 from the shop's list. Assumes that the item list is458 already up."459 [item-pairs script]460 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)461 initial-purchase462 (->> script463 (buy-item 0 (item-lookup 0))464 (buy-item 1 (item-lookup 1))465 (buy-item 2 (item-lookup 2)))]466 (cond467 (and468 (not= 0 (item-lookup 3))469 (not= 0 (item-lookup 4)))470 (->> initial-purchase471 (do-nothing 20)472 (play-moves [[:d]])473 (do-nothing 3)474 (play-moves [[:d]])475 (do-nothing 3)476 (play-moves [[:d]])477 (do-nothing 10)478 (buy-item 0 (item-lookup 3))479 (do-nothing 20)480 (play-moves [[:d]])481 (do-nothing 3)482 (play-moves [[:d]])483 (do-nothing 3)484 (play-moves [[:d]])485 (do-nothing 10)486 (buy-item 0 (item-lookup 4)))487 (and (= 0 (item-lookup 3))488 (not= 0 (item-lookup 4)))489 (->> initial-purchase490 (do-nothing 20)491 (play-moves [[:d]])492 (do-nothing 3)493 (play-moves [[:d]])494 (do-nothing 3)495 (play-moves [[:d]])496 (do-nothing 10)497 (play-moves [[:d]])498 (do-nothing 10)499 (buy-item 0 (item-lookup 4)))500 (and (not= 0 (item-lookup 3))501 (= 0 (item-lookup 4)))502 (->> initial-purchase503 (do-nothing 20)504 (play-moves [[:d]])505 (do-nothing 3)506 (play-moves [[:d]])507 (do-nothing 3)508 (play-moves [[:d]])509 (do-nothing 10)510 (buy-item 0 (item-lookup 3))))))513 (defn test-buy-items514 ([] (test-buy-items515 (walk-to-counter)))516 ([script]517 (->> [(first script) (set-money (second script)518 999999)]519 (play-moves520 [[] [:a] []])521 (scroll-text)522 (do-nothing 100)523 (play-moves [[:a]])524 (do-nothing 100)525 (buy-items526 [[0 1]527 [1 15]528 [2 1]529 [3 20]530 [4 95]531 ]))))533 (defn-memo buy-initial-items534 ([] (buy-initial-items535 (walk-to-counter)))536 ([script]537 (->> script538 (play-moves539 [[] [:a] []])540 (scroll-text)541 (do-nothing 100)542 (play-moves [[:a]])543 (do-nothing 100)544 (buy-items545 [[0 1]546 [1 1]547 [2 1]548 [3 1]549 [4 1]550 ]))))