# HG changeset patch # User Robert McIntyre # Date 1332809817 18000 # Node ID 11cfe6dcb80381367b21e33f08956e19cdf77cad # Parent 2a46422902becb61eb4486595ecd81118fbf1dae script: defeated rival. diff -r 2a46422902be -r 11cfe6dcb803 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Mon Mar 26 18:01:39 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Mon Mar 26 19:56:57 2012 -0500 @@ -1,5 +1,5 @@ (ns com.aurellem.run.bootstrap-0 - (:use (com.aurellem.gb gb-driver vbm)) + (:use (com.aurellem.gb gb-driver vbm characters)) (:use (com.aurellem.run title save-corruption)) (:use (com.aurellem.exp item-bridge))) @@ -128,19 +128,89 @@ (play-moves (concat (repeat 42 []) - [[:b]]))))) + [[:b] [:b] [:b] [:b]]))))) (defn-memo begin-battle-with-rival ([] (begin-battle-with-rival (obtain-pikachu))) ([script] (->> script + (walk [↓ ↓ ↓ ↓]) + (scroll-text 3) + (end-text) + (scroll-text)))) + +(defn search-string + [array string] + (let [codes + (str->character-codes string) + codes-length (count codes) + mem (vec array) + mem-length (count mem)] + (loop [idx 0] + (if (< (- mem-length idx) codes-length) + nil + (if (= (subvec mem idx (+ idx codes-length)) + codes) + idx + (recur (inc idx))))))) + +(defn critical-hit + "Put the cursor over the desired attack. This program will + determine the appropriate amount of blank frames to + insert before pressing [:a] to ensure that the attack is + a critical hit." + [script] + (loop [blanks 6] + (let [new-script + (->> script + (play-moves + (concat (repeat blanks []) + [[:a][]])))] + (if (let [future-state + (run-moves (second new-script) + (repeat 400 [])) + + result (search-string (memory future-state) + "Critical")] + (if result + (println "critical hit with" blanks "blank frames")) + result) + new-script + (recur (inc blanks)))))) + +(defn-memo battle-with-rival + ([] (battle-with-rival + (begin-battle-with-rival))) + ([script] + (->> script + (play-moves (repeat 381 [])) + (play-moves [[:a]]) + (critical-hit) + (play-moves (repeat 100 [])) + (scroll-text) (play-moves - (repeat 200 [:b])) + (concat (repeat 275 []) [[:a]])) + (critical-hit) + (play-moves (repeat 100 [])) + (scroll-text) (play-moves - (repeat 200 [])) - (walk [↓ ↓ ↓])))) - + (concat (repeat 270 []) [[:a]])) + (play-moves [[][][][][][][][][:a]])))) + +(defn-memo finish-rival-text + ([] (finish-rival-text + (battle-with-rival))) + ([script] + (->> script + (scroll-text 2) + (end-text) + (scroll-text 9) + (end-text)))) + + + +