changeset 260:11cfe6dcb803

script: defeated rival.
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Mar 2012 19:56:57 -0500
parents 2a46422902be
children 1b5c33614b0d
files clojure/com/aurellem/run/bootstrap_0.clj
diffstat 1 files changed, 76 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj	Mon Mar 26 18:01:39 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj	Mon Mar 26 19:56:57 2012 -0500
     1.3 @@ -1,5 +1,5 @@
     1.4  (ns com.aurellem.run.bootstrap-0
     1.5 -  (:use (com.aurellem.gb gb-driver vbm))
     1.6 +  (:use (com.aurellem.gb gb-driver vbm characters))
     1.7    (:use (com.aurellem.run title save-corruption))
     1.8    (:use (com.aurellem.exp item-bridge)))
     1.9  
    1.10 @@ -128,19 +128,89 @@
    1.11            (play-moves
    1.12             (concat
    1.13              (repeat 42 [])
    1.14 -                   [[:b]])))))
    1.15 +                   [[:b] [:b] [:b] [:b]])))))
    1.16  
    1.17  (defn-memo begin-battle-with-rival
    1.18    ([] (begin-battle-with-rival
    1.19          (obtain-pikachu)))
    1.20    ([script]
    1.21       (->> script
    1.22 +          (walk [↓ ↓ ↓ ↓])
    1.23 +          (scroll-text 3)
    1.24 +          (end-text)
    1.25 +          (scroll-text))))
    1.26 +
    1.27 +(defn search-string
    1.28 +  [array string]
    1.29 +  (let [codes
    1.30 +        (str->character-codes string)
    1.31 +        codes-length (count codes)
    1.32 +        mem (vec array)
    1.33 +        mem-length (count mem)]
    1.34 +    (loop [idx 0]
    1.35 +      (if (< (- mem-length idx) codes-length)
    1.36 +        nil
    1.37 +        (if (= (subvec mem idx (+ idx codes-length))
    1.38 +               codes)
    1.39 +          idx
    1.40 +          (recur (inc idx)))))))
    1.41 +        
    1.42 +(defn critical-hit
    1.43 +  "Put the cursor over the desired attack. This program will
    1.44 +   determine the appropriate amount of blank frames to
    1.45 +   insert before pressing [:a] to ensure that the attack is
    1.46 +   a critical hit."
    1.47 +  [script]
    1.48 +  (loop [blanks 6]
    1.49 +    (let [new-script
    1.50 +          (->> script
    1.51 +               (play-moves
    1.52 +                (concat (repeat blanks [])
    1.53 +                        [[:a][]])))]
    1.54 +      (if (let [future-state
    1.55 +                (run-moves (second new-script)
    1.56 +                           (repeat 400 []))
    1.57 +
    1.58 +                result (search-string (memory future-state)
    1.59 +                                      "Critical")]
    1.60 +            (if result
    1.61 +              (println "critical hit with" blanks "blank frames"))
    1.62 +            result) 
    1.63 +        new-script
    1.64 +        (recur (inc blanks))))))  
    1.65 +
    1.66 +(defn-memo battle-with-rival
    1.67 +  ([] (battle-with-rival
    1.68 +        (begin-battle-with-rival)))
    1.69 +  ([script]
    1.70 +     (->> script
    1.71 +          (play-moves (repeat 381 []))
    1.72 +          (play-moves [[:a]])
    1.73 +          (critical-hit)
    1.74 +          (play-moves (repeat 100 []))
    1.75 +          (scroll-text)
    1.76            (play-moves
    1.77 -           (repeat 200 [:b]))
    1.78 +           (concat (repeat 275 []) [[:a]]))
    1.79 +          (critical-hit)
    1.80 +          (play-moves (repeat 100 []))
    1.81 +          (scroll-text)
    1.82            (play-moves
    1.83 -           (repeat 200 []))
    1.84 -          (walk [↓ ↓ ↓]))))
    1.85 -  
    1.86 +           (concat (repeat 270 []) [[:a]]))
    1.87 +          (play-moves [[][][][][][][][][:a]]))))
    1.88 +
    1.89 +(defn-memo finish-rival-text
    1.90 +  ([] (finish-rival-text
    1.91 +       (battle-with-rival)))
    1.92 +  ([script]
    1.93 +     (->> script
    1.94 +          (scroll-text 2)
    1.95 +          (end-text)
    1.96 +          (scroll-text 9)
    1.97 +          (end-text))))
    1.98 +
    1.99 +
   1.100 +          
   1.101 +
   1.102            
   1.103        
   1.104