# HG changeset patch # User Robert McIntyre # Date 1332809845 18000 # Node ID 1b5c33614b0d5551070dabcd912d7ea427956481 # Parent 11cfe6dcb80381367b21e33f08956e19cdf77cad# Parent b2f9a0cb13e3efa3a553024ad59b3d6c54ba851b merge diff -r b2f9a0cb13e3 -r 1b5c33614b0d clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Mon Mar 26 18:34:06 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Mon Mar 26 19:57:25 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)))) + + + +