Mercurial > vba-clojure
changeset 315:363b650a77cc
merge
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 02 Apr 2012 20:30:28 -0500 |
parents | 073600cba28a (diff) 2060219691fa (current diff) |
children | d263df762c59 |
files | |
diffstat | 9 files changed, 278 insertions(+), 191 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/exp/item_bridge.clj Sun Apr 01 21:47:04 2012 -0500 1.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj Mon Apr 02 20:30:28 2012 -0500 1.3 @@ -10,12 +10,16 @@ 1.4 (defn corrupt-item-state [] 1.5 (read-state "corrupt-items")) 1.6 1.7 -(defn view-memory-range [state start end] 1.8 - (dorun 1.9 - (map (fn [loc val] 1.10 - (println (format "%04X : %02X" loc val))) 1.11 - (range start end) (subvec (vec (memory state)) start end))) 1.12 - state) 1.13 +(defn view-memory-range 1.14 + ([start end] 1.15 + (view-memory-range 1.16 + @current-state start end)) 1.17 + ([state start end] 1.18 + (dorun 1.19 + (map (fn [loc val] 1.20 + (println (format "%04X : %02X" loc val))) 1.21 + (range start end) (subvec (vec (memory state)) start end))) 1.22 + state)) 1.23 1.24 (defn almost-broken 1.25 "if one more memory location is turned into 0x03, the game crashes."
2.1 --- a/clojure/com/aurellem/gb/saves.clj Sun Apr 01 21:47:04 2012 -0500 2.2 +++ b/clojure/com/aurellem/gb/saves.clj Mon Apr 02 20:30:28 2012 -0500 2.3 @@ -11,5 +11,8 @@ 2.4 (defn rlm-pallet-town [] 2.5 (read-state "rlm-pallet-town")) 2.6 2.7 +(defn talk-to-oak [] 2.8 + (read-state "talk-to-oak")) 2.9 2.10 - 2.11 +(defn normal-conv [] 2.12 + (read-state "normal-conversation")) 2.13 \ No newline at end of file
3.1 --- a/clojure/com/aurellem/gb/util.clj Sun Apr 01 21:47:04 2012 -0500 3.2 +++ b/clojure/com/aurellem/gb/util.clj Mon Apr 02 20:30:28 2012 -0500 3.3 @@ -147,10 +147,12 @@ 3.4 3.5 (defn common-differences [& seqs] 3.6 (let [backbone (range (count (first seqs)))] 3.7 - (filter 3.8 - (comp (partial apply distinct?) second) 3.9 - (zipmap backbone 3.10 - (apply (partial map list) seqs))))) 3.11 + (sort-by 3.12 + first 3.13 + (filter 3.14 + (comp (partial apply distinct?) second) 3.15 + (zipmap backbone 3.16 + (apply (partial map list) seqs)))))) 3.17 3.18 (defn temporal-compare [& states] 3.19 (apply common-differences
4.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj Sun Apr 01 21:47:04 2012 -0500 4.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Mon Apr 02 20:30:28 2012 -0500 4.3 @@ -28,30 +28,18 @@ 4.4 (advance [] [:r] DE) 4.5 (play-moves 4.6 [[] 4.7 - [:r] [] [:r] [] [:r] [] [:r] [] 4.8 - [:r] [] [:r] [] [:r] [] [:d] [] 4.9 - [:d] [:a] ;; space 4.10 - [:l] [] [:d] [:a] ;; [PK] 4.11 - [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G 4.12 - [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK] 4.13 - [:u] [] [:u] [] [:u] [] [:l] [:a] ;; G 4.14 - [:d] [] [:d] [] [:d] [] [:r] [:a] ;; [PK] 4.15 - 4.16 - [:d] [] [:r] [:a] ;; finish 4.17 + [] [] [:r] [] [:d] [:a] ;; L 4.18 + [:r] [] [:r] [] [:r] [] [:r] [] 4.19 + [:r] [] [:d] [] [:d] [:a] ;; [PK] 4.20 + [:u] [] [:l] [] [:l] [] 4.21 + [:l] [] [:l] [] [:l] [:a] ;; U 4.22 + [:r] [] [:r] [] [:r] [] 4.23 + [:r] [] [:r] [] [:d] [:a] ;; [PK] 4.24 + [] [:a] ;; [PK] 4.25 + [] [:a] ;; [PK] 4.26 + [:r] [] [:d] [:a] ;; END 4.27 ])))) 4.28 4.29 -(defn walk 4.30 - "Move the character along the given directions." 4.31 - [directions script] 4.32 - (reduce (fn [script direction] 4.33 - (move direction script)) 4.34 - script directions)) 4.35 - 4.36 -(def ↑ [:u]) 4.37 -(def ↓ [:d]) 4.38 -(def ← [:l]) 4.39 -(def → [:r]) 4.40 - 4.41 (defn-memo leave-house 4.42 ([] (leave-house (name-rival-bootstrap))) 4.43 ([script] 4.44 @@ -70,11 +58,6 @@ 4.45 (walk [→ → → → → 4.46 ↑ ↑ ↑ ↑ ↑ ↑])))) 4.47 4.48 -(defn end-text [script] 4.49 - (->> script 4.50 - (scroll-text) 4.51 - (play-moves [[] [:a]]))) 4.52 - 4.53 (defn-memo start-pikachu-battle 4.54 ([] (start-pikachu-battle 4.55 (to-pallet-town-edge))) 4.56 @@ -126,8 +109,8 @@ 4.57 4.58 (play-moves 4.59 (concat 4.60 - (repeat 42 []) 4.61 - [[:b] [:b] [:b] [:b]]))))) 4.62 + (repeat 50 []) 4.63 + [[:b] [] []]))))) 4.64 4.65 (defn-memo begin-battle-with-rival 4.66 ([] (begin-battle-with-rival 4.67 @@ -139,63 +122,26 @@ 4.68 (end-text) 4.69 (scroll-text)))) 4.70 4.71 -(defn search-string 4.72 - [array string] 4.73 - (let [codes 4.74 - (str->character-codes string) 4.75 - codes-length (count codes) 4.76 - mem (vec array) 4.77 - mem-length (count mem)] 4.78 - (loop [idx 0] 4.79 - (if (< (- mem-length idx) codes-length) 4.80 - nil 4.81 - (if (= (subvec mem idx (+ idx codes-length)) 4.82 - codes) 4.83 - idx 4.84 - (recur (inc idx))))))) 4.85 - 4.86 -(defn critical-hit 4.87 - "Put the cursor over the desired attack. This program will 4.88 - determine the appropriate amount of blank frames to 4.89 - insert before pressing [:a] to ensure that the attack is 4.90 - a critical hit." 4.91 - [script] 4.92 - (loop [blanks 6] 4.93 - (let [new-script 4.94 - (->> script 4.95 - (play-moves 4.96 - (concat (repeat blanks []) 4.97 - [[:a][]])))] 4.98 - (if (let [future-state 4.99 - (run-moves (second new-script) 4.100 - (repeat 400 [])) 4.101 - 4.102 - result (search-string (memory future-state) 4.103 - "Critical")] 4.104 - (if result 4.105 - (println "critical hit with" blanks "blank frames")) 4.106 - result) 4.107 - new-script 4.108 - (recur (inc blanks)))))) 4.109 - 4.110 (defn-memo battle-with-rival 4.111 ([] (battle-with-rival 4.112 (begin-battle-with-rival))) 4.113 ([script] 4.114 (->> script 4.115 - (play-moves (repeat 381 [])) 4.116 + (do-nothing 400) 4.117 (play-moves [[:a]]) 4.118 (critical-hit) 4.119 - (play-moves (repeat 100 [])) 4.120 + (do-nothing 100) 4.121 (scroll-text) 4.122 - (play-moves 4.123 - (concat (repeat 275 []) [[:a]])) 4.124 + (do-nothing 275) 4.125 + (play-moves [[:a]]) 4.126 (critical-hit) 4.127 - (play-moves (repeat 100 [])) 4.128 + (do-nothing 100) 4.129 (scroll-text) 4.130 - (play-moves 4.131 - (concat (repeat 270 []) [[:a]])) 4.132 - (play-moves [[][][][][][][][][:a]])))) 4.133 + (do-nothing 270) 4.134 + (play-moves [[:a]]) 4.135 + (critical-hit) 4.136 + (do-nothing 100) 4.137 + (scroll-text)))) 4.138 4.139 (defn-memo finish-rival-text 4.140 ([] (finish-rival-text 4.141 @@ -207,11 +153,6 @@ 4.142 (scroll-text 9) 4.143 (end-text)))) 4.144 4.145 -(defn do-nothing [n script] 4.146 - (->> script 4.147 - (play-moves 4.148 - (repeat n [])))) 4.149 - 4.150 (defn-memo pikachu-comes-out 4.151 ([] (pikachu-comes-out 4.152 (finish-rival-text))) 4.153 @@ -239,33 +180,6 @@ 4.154 ↑ ↑ ↑ ↑ ↑ ↑ 4.155 → ↑])))) 4.156 4.157 -(defn move-thru-grass 4.158 - [direction script] 4.159 - (loop [blanks 0] 4.160 - (let [new-script 4.161 - (->> script 4.162 - (play-moves (repeat blanks [])) 4.163 - (move direction)) 4.164 - 4.165 - future-state 4.166 - (run-moves (second new-script) 4.167 - (repeat 600 [])) 4.168 - 4.169 - result (search-string (memory future-state) 4.170 - "Wild")] 4.171 - (if (nil? result) 4.172 - (do 4.173 - (if (< 0 blanks) 4.174 - (do(println "avoided pokemon with" blanks "blank frames"))) 4.175 - new-script) 4.176 - (recur (inc blanks)))))) 4.177 - 4.178 -(defn walk-thru-grass 4.179 - [directions script] 4.180 - (reduce (fn [script direction] 4.181 - (move-thru-grass direction script)) 4.182 - script directions)) 4.183 - 4.184 (defn-memo pallet-edge->viridian-mart 4.185 ([] (pallet-edge->viridian-mart true 4.186 (oaks-lab->pallet-town-edge))) 4.187 @@ -281,11 +195,12 @@ 4.188 ;; leave straight grass 4.189 (walk-thru-grass 4.190 [↑ ↑ ↑ ↑ ↑]) 4.191 - 4.192 + 4.193 (walk [↑ ↑ ↑ ↑]) 4.194 - 4.195 + 4.196 (walk-thru-grass 4.197 [← ← ↑]) 4.198 + 4.199 (walk [↑ ↑ ↑ ↑ → → → ]) 4.200 4.201 (walk-thru-grass 4.202 @@ -583,8 +498,6 @@ 4.203 (advance [] [:a]) 4.204 (advance [:a] [:a :start])))) 4.205 4.206 -(def menu walk) 4.207 - 4.208 (defn-memo corrupt-item-list 4.209 ([] (corrupt-item-list 4.210 (do-save-corruption))) 4.211 @@ -598,16 +511,6 @@ 4.212 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon" 4.213 4.214 (do-nothing 1)))) 4.215 - 4.216 - 4.217 -(defn slowly 4.218 - [delay moves script] 4.219 - (reduce 4.220 - (fn [script move] 4.221 - (->> script 4.222 - (do-nothing delay) 4.223 - (play-moves (vector move)))) 4.224 - script moves)) 4.225 4.226 (defn-memo get-burn-heals 4.227 ([] (get-burn-heals 4.228 @@ -649,18 +552,6 @@ 4.229 4.230 (do-nothing 10)))) 4.231 4.232 -(defn save-game-properly 4.233 - [number-down script] 4.234 - (->> 4.235 - (reduce (fn [script _] 4.236 - (->> script 4.237 - (advance [] [:d]))) 4.238 - script 4.239 - (range number-down)) 4.240 - (play-moves [[] [] [:a]]) 4.241 - (scroll-text) 4.242 - (do-nothing 300))) 4.243 - 4.244 (defn-memo corrupt-item-list-again 4.245 ([] (corrupt-item-list-again (get-burn-heals))) 4.246 ([script] 4.247 @@ -678,8 +569,6 @@ 4.248 ; switching it to 4.249 ))) ; tenth place. 4.250 4.251 - 4.252 - 4.253 (defn-memo viridian-store->viridian-poke-center 4.254 ([] (viridian-store->viridian-poke-center 4.255 (corrupt-item-list-again))) 4.256 @@ -723,16 +612,6 @@ 4.257 (menu [[:d] [:a]]) 4.258 (do-nothing 40)))) 4.259 4.260 - 4.261 -(defn multiple-times 4.262 - ([n command args script] 4.263 - (reduce (fn [script _] 4.264 - (apply command (concat args [script]))) 4.265 - script 4.266 - (range n))) 4.267 - ([n command script] 4.268 - (multiple-times n command [] script))) 4.269 - 4.270 (defn deposit-n-items 4.271 [n script] 4.272 (->> script
5.1 --- a/clojure/com/aurellem/run/save_corruption.clj Sun Apr 01 21:47:04 2012 -0500 5.2 +++ b/clojure/com/aurellem/run/save_corruption.clj Mon Apr 02 20:30:28 2012 -0500 5.3 @@ -2,17 +2,12 @@ 5.4 (:use (com.aurellem.gb gb-driver vbm)) 5.5 (:use (com.aurellem.run title))) 5.6 5.7 -(use 'clojure.repl) 5.8 - 5.9 (defn-memo start-walking 5.10 ([script] 5.11 (->> script 5.12 (advance [:b] [:b :r]))) 5.13 ([] (start-walking (finish-title)))) 5.14 - 5.15 -(def move 5.16 - (partial advance [])) 5.17 - 5.18 + 5.19 (defn-memo walk-to-stairs 5.20 ([] (walk-to-stairs (start-walking))) 5.21 ([script]
6.1 --- a/clojure/com/aurellem/run/title.clj Sun Apr 01 21:47:04 2012 -0500 6.2 +++ b/clojure/com/aurellem/run/title.clj Mon Apr 02 20:30:28 2012 -0500 6.3 @@ -1,34 +1,6 @@ 6.4 (ns com.aurellem.run.title 6.5 (:use (com.aurellem.gb gb-driver vbm))) 6.6 6.7 -(defn first-difference [base alt summary root] 6.8 - (loop [branch-point root 6.9 - actions []] 6.10 - (let [base-branch (step branch-point base) 6.11 - base-val (summary base-branch) 6.12 - alt-branch (step branch-point alt) 6.13 - alt-val (summary alt-branch)] 6.14 - (if (not= base-val alt-val) 6.15 - [(conj actions alt) alt-branch] 6.16 - (recur base-branch (conj actions base)))))) 6.17 - 6.18 -(defn advance 6.19 - ([base alt summary [commands state]] 6.20 - (let [[c s] (first-difference base alt summary state)] 6.21 - [(concat commands c) s])) 6.22 - ([base alt [commands state]] 6.23 - (advance base alt AF [commands state])) 6.24 - ([alt [commands state]] 6.25 - (advance [] alt [commands state]))) 6.26 - 6.27 -(defn scroll-text 6.28 - ([script] 6.29 - (advance [:b] [:a :b] script)) 6.30 - ([n script] 6.31 - (reduce (fn [script _] 6.32 - (scroll-text script)) 6.33 - script 6.34 - (range n)))) 6.35 6.36 (defn start [] [[] (root)]) 6.37
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/clojure/com/aurellem/run/util.clj Mon Apr 02 20:30:28 2012 -0500 7.3 @@ -0,0 +1,232 @@ 7.4 +(ns com.aurellem.run.util 7.5 + (:use (com.aurellem.gb util gb-driver vbm characters saves)) 7.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 7.7 + 7.8 +(def ↑ [:u]) 7.9 +(def ↓ [:d]) 7.10 +(def ← [:l]) 7.11 +(def → [:r]) 7.12 + 7.13 +(defn first-difference 7.14 + [base alt difference-metric [moves root :as script]] 7.15 + (loop [branch-point root 7.16 + actions moves] 7.17 + (let [base-branch (step branch-point base) 7.18 + base-val (difference-metric base-branch) 7.19 + alt-branch (step branch-point alt) 7.20 + alt-val (difference-metric alt-branch)] 7.21 + (if (not= base-val alt-val) 7.22 + [(conj actions alt) alt-branch] 7.23 + (recur base-branch (conj actions base)))))) 7.24 + 7.25 +(defn repeat-until-different 7.26 + [buttons metric [moves root :as script]] 7.27 + (let [baseline (metric root)] 7.28 + (loop [actions (vec moves) 7.29 + state root] 7.30 + (let [new-state (step state buttons) 7.31 + new-actions (conj actions buttons)] 7.32 + (if (not= (metric new-state) baseline) 7.33 + [new-actions new-state] 7.34 + (recur new-actions new-state)))))) 7.35 + 7.36 +(defn delayed-difference 7.37 + [base alt delay difference-metric [moves root :as script]] 7.38 + (loop [branch-point root 7.39 + actions moves] 7.40 + (let [base-branch (step branch-point base) 7.41 + base-val 7.42 + (difference-metric 7.43 + (run-moves base-branch 7.44 + (repeat delay base))) 7.45 + alt-branch (step branch-point alt) 7.46 + alt-val 7.47 + (difference-metric 7.48 + (run-moves alt-branch 7.49 + (repeat delay base)))] 7.50 + (if (not= base-val alt-val) 7.51 + [(conj actions alt) alt-branch] 7.52 + (recur base-branch (conj actions base)))))) 7.53 + 7.54 + 7.55 + 7.56 +;; (defn advance 7.57 +;; ([base alt difference-metric [commands state]] 7.58 +;; (let [[c s] 7.59 +;; (first-difference base alt difference-metric state)] 7.60 +;; [(concat commands c) s])) 7.61 +;; ([base alt [commands state]] 7.62 +;; (advance base alt AF [commands state])) 7.63 +;; ([alt [commands state]] 7.64 +;; (advance [] alt [commands state]))) 7.65 + 7.66 + 7.67 +(def x-position-address 0xD361) 7.68 +(def y-position-address 0xD362) 7.69 + 7.70 +(defn x-position 7.71 + ([^SaveState state] 7.72 + (aget (memory state) x-position-address)) 7.73 + ([] (x-position @current-state))) 7.74 + 7.75 +(defn y-position 7.76 + ([^SaveState state] 7.77 + (aget (memory state) y-position-address)) 7.78 + ([] (y-position @current-state))) 7.79 + 7.80 +(defn move 7.81 + [dir script] 7.82 + (let [current-position-fn 7.83 + (cond (#{← →} dir) x-position 7.84 + (#{↑ ↓} dir) y-position)] 7.85 + (repeat-until-different dir current-position-fn script))) 7.86 + 7.87 +(defn walk 7.88 + "Move the character along the given directions." 7.89 + [directions script] 7.90 + (reduce (fn [script dir] 7.91 + (move dir script)) script directions)) 7.92 + 7.93 +(defn menu 7.94 + [directions script] 7.95 + (reduce (fn [script direction] 7.96 + (move direction script)) 7.97 + script directions)) 7.98 + 7.99 + 7.100 +(defn search-string 7.101 + [^SaveState state string] 7.102 + (let [codes 7.103 + (str->character-codes string) 7.104 + codes-length (count codes) 7.105 + mem (vec (memory state)) 7.106 + mem-length (count mem)] 7.107 + (loop [idx 0] 7.108 + (if (< (- mem-length idx) codes-length) 7.109 + nil 7.110 + (if (= (subvec mem idx (+ idx codes-length)) 7.111 + codes) 7.112 + idx 7.113 + (recur (inc idx))))))) 7.114 + 7.115 +(def text-address 0x9DC1) 7.116 + 7.117 +(defn displayed-text 7.118 + ([^SaveState state] 7.119 + (character-codes->str 7.120 + (subvec (vec (memory state)) 7.121 + text-address 7.122 + (+ text-address 82)))) 7.123 + ([] (displayed-text @current-state))) 7.124 + 7.125 +;; (defn scroll-text 7.126 +;; ([script] 7.127 +;; (first-difference [:b] [:a :b] AF script)) 7.128 +;; ([n script] 7.129 +;; (reduce (fn [script _] 7.130 +;; (scroll-text script)) 7.131 +;; script 7.132 +;; (range n)))) 7.133 + 7.134 +(defn scroll-text 7.135 + ([script] 7.136 + (delayed-difference 7.137 + [:b] [:a :b] 25 displayed-text script)) 7.138 + ([n script] 7.139 + (reduce (fn [script _] 7.140 + (scroll-text script)) 7.141 + script 7.142 + (range n)))) 7.143 + 7.144 + 7.145 +(defn end-text [script] 7.146 + (->> script 7.147 + (scroll-text) 7.148 + (play-moves [[] [:a]]))) 7.149 + 7.150 + 7.151 + 7.152 +(common-differences 7.153 + (vec (memory (step (talk-to-oak) [:a]))) 7.154 + (vec (memory (step (talk-to-oak) [])))) 7.155 + 7.156 + 7.157 + 7.158 + 7.159 + 7.160 +(defn do-nothing [n script] 7.161 + (->> script 7.162 + (play-moves 7.163 + (repeat n [])))) 7.164 + 7.165 + 7.166 +(defn critical-hit 7.167 + "Put the cursor over the desired attack. This program will 7.168 + determine the appropriate amount of blank frames to 7.169 + insert before pressing [:a] to ensure that the attack is 7.170 + a critical hit." 7.171 + [script] 7.172 + (loop [blanks 6] 7.173 + (let [new-script 7.174 + (->> script 7.175 + (play-moves 7.176 + (concat (repeat blanks []) 7.177 + [[:a][]])))] 7.178 + (if (let [future-state 7.179 + (run-moves (second new-script) 7.180 + (repeat 400 [])) 7.181 + 7.182 + result (search-string (memory future-state) 7.183 + "Critical")] 7.184 + (if result 7.185 + (println "critical hit with" blanks "blank frames")) 7.186 + result) 7.187 + new-script 7.188 + (recur (inc blanks)))))) 7.189 + 7.190 +(defn move-thru-grass 7.191 + [direction script] 7.192 + (loop [blanks 0] 7.193 + (let [new-script 7.194 + (->> script 7.195 + (play-moves (repeat blanks [])) 7.196 + (move direction)) 7.197 + 7.198 + future-state 7.199 + (run-moves (second new-script) 7.200 + (repeat 600 [])) 7.201 + 7.202 + result (search-string (memory future-state) 7.203 + "Wild")] 7.204 + (if (nil? result) 7.205 + (do 7.206 + (if (< 0 blanks) 7.207 + (do 7.208 + (println "avoided pokemon with" 7.209 + blanks "blank frames"))) 7.210 + new-script) 7.211 + (recur (inc blanks)))))) 7.212 + 7.213 +(defn walk-thru-grass 7.214 + [directions script] 7.215 + (reduce (fn [script direction] 7.216 + (move-thru-grass direction script)) 7.217 + script directions)) 7.218 + 7.219 +(defn slowly 7.220 + [delay moves script] 7.221 + (reduce 7.222 + (fn [script move] 7.223 + (->> script 7.224 + (do-nothing delay) 7.225 + (play-moves (vector move)))) 7.226 + script moves)) 7.227 + 7.228 +(defn multiple-times 7.229 + ([n command args script] 7.230 + (reduce (fn [script _] 7.231 + (apply command (concat args [script]))) 7.232 + script 7.233 + (range n))) 7.234 + ([n command script] 7.235 + (multiple-times n command [] script)))
8.1 Binary file save-states/normal-conversation.sav has changed
9.1 Binary file save-states/talk-to-oak.sav has changed