Mercurial > vba-clojure
comparison clojure/com/aurellem/run/bootstrap_0.clj @ 260:11cfe6dcb803
script: defeated rival.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Mar 2012 19:56:57 -0500 |
parents | 2a46422902be |
children | 868783405ac2 |
comparison
equal
deleted
inserted
replaced
258:2a46422902be | 260:11cfe6dcb803 |
---|---|
1 (ns com.aurellem.run.bootstrap-0 | 1 (ns com.aurellem.run.bootstrap-0 |
2 (:use (com.aurellem.gb gb-driver vbm)) | 2 (:use (com.aurellem.gb gb-driver vbm characters)) |
3 (:use (com.aurellem.run title save-corruption)) | 3 (:use (com.aurellem.run title save-corruption)) |
4 (:use (com.aurellem.exp item-bridge))) | 4 (:use (com.aurellem.exp item-bridge))) |
5 | 5 |
6 | 6 |
7 (defn-memo boot-root [] | 7 (defn-memo boot-root [] |
126 (scroll-text 7) | 126 (scroll-text 7) |
127 | 127 |
128 (play-moves | 128 (play-moves |
129 (concat | 129 (concat |
130 (repeat 42 []) | 130 (repeat 42 []) |
131 [[:b]]))))) | 131 [[:b] [:b] [:b] [:b]]))))) |
132 | 132 |
133 (defn-memo begin-battle-with-rival | 133 (defn-memo begin-battle-with-rival |
134 ([] (begin-battle-with-rival | 134 ([] (begin-battle-with-rival |
135 (obtain-pikachu))) | 135 (obtain-pikachu))) |
136 ([script] | 136 ([script] |
137 (->> script | 137 (->> script |
138 (play-moves | 138 (walk [↓ ↓ ↓ ↓]) |
139 (repeat 200 [:b])) | 139 (scroll-text 3) |
140 (play-moves | 140 (end-text) |
141 (repeat 200 [])) | 141 (scroll-text)))) |
142 (walk [↓ ↓ ↓])))) | 142 |
143 | 143 (defn search-string |
144 [array string] | |
145 (let [codes | |
146 (str->character-codes string) | |
147 codes-length (count codes) | |
148 mem (vec array) | |
149 mem-length (count mem)] | |
150 (loop [idx 0] | |
151 (if (< (- mem-length idx) codes-length) | |
152 nil | |
153 (if (= (subvec mem idx (+ idx codes-length)) | |
154 codes) | |
155 idx | |
156 (recur (inc idx))))))) | |
157 | |
158 (defn critical-hit | |
159 "Put the cursor over the desired attack. This program will | |
160 determine the appropriate amount of blank frames to | |
161 insert before pressing [:a] to ensure that the attack is | |
162 a critical hit." | |
163 [script] | |
164 (loop [blanks 6] | |
165 (let [new-script | |
166 (->> script | |
167 (play-moves | |
168 (concat (repeat blanks []) | |
169 [[:a][]])))] | |
170 (if (let [future-state | |
171 (run-moves (second new-script) | |
172 (repeat 400 [])) | |
173 | |
174 result (search-string (memory future-state) | |
175 "Critical")] | |
176 (if result | |
177 (println "critical hit with" blanks "blank frames")) | |
178 result) | |
179 new-script | |
180 (recur (inc blanks)))))) | |
181 | |
182 (defn-memo battle-with-rival | |
183 ([] (battle-with-rival | |
184 (begin-battle-with-rival))) | |
185 ([script] | |
186 (->> script | |
187 (play-moves (repeat 381 [])) | |
188 (play-moves [[:a]]) | |
189 (critical-hit) | |
190 (play-moves (repeat 100 [])) | |
191 (scroll-text) | |
192 (play-moves | |
193 (concat (repeat 275 []) [[:a]])) | |
194 (critical-hit) | |
195 (play-moves (repeat 100 [])) | |
196 (scroll-text) | |
197 (play-moves | |
198 (concat (repeat 270 []) [[:a]])) | |
199 (play-moves [[][][][][][][][][:a]])))) | |
200 | |
201 (defn-memo finish-rival-text | |
202 ([] (finish-rival-text | |
203 (battle-with-rival))) | |
204 ([script] | |
205 (->> script | |
206 (scroll-text 2) | |
207 (end-text) | |
208 (scroll-text 9) | |
209 (end-text)))) | |
210 | |
211 | |
212 | |
213 | |
144 | 214 |
145 | 215 |
146 | 216 |
147 | 217 |
148 | 218 |