comparison clojure/com/aurellem/run/util.clj @ 318:9a4d3f801c89

fixing runs to use new util functions.
author Robert McIntyre <rlm@mit.edu>
date Mon, 02 Apr 2012 23:13:49 -0500
parents 3c5bf2221ea0
children 92c47a9cdaea
comparison
equal deleted inserted replaced
317:3c5bf2221ea0 318:9a4d3f801c89
4 4
5 (def ↑ [:u]) 5 (def ↑ [:u])
6 (def ↓ [:d]) 6 (def ↓ [:d])
7 (def ← [:l]) 7 (def ← [:l])
8 (def → [:r]) 8 (def → [:r])
9
10 [↑ ↓ ← →]
9 11
10 (defn first-difference 12 (defn first-difference
11 [base alt difference-metric [moves root :as script]] 13 [base alt difference-metric [moves root :as script]]
12 (loop [branch-point root 14 (loop [branch-point root
13 actions moves] 15 actions moves]
143 (defn do-nothing [n script] 145 (defn do-nothing [n script]
144 (->> script 146 (->> script
145 (play-moves 147 (play-moves
146 (repeat n [])))) 148 (repeat n []))))
147 149
150 (defn delayed-improbability-search
151 "insert blank frames before calling script-fn until
152 metric returns true."
153 [delay metric script-fn script]
154 (loop [blanks 0]
155 (let [new-script
156 (->> script
157 (play-moves
158 (concat (repeat blanks [])))
159 script-fn)
160 future-state
161 (run-moves (second new-script)
162 (repeat delay []))
163 result (metric future-state)]
164 (if result
165 (do
166 (println "improbability factor:" blanks)
167 new-script)
168 (recur (inc blanks))))))
148 169
149 (defn critical-hit 170 (defn critical-hit
150 "Put the cursor over the desired attack. This program will 171 "Put the cursor over the desired attack. This program will
151 determine the appropriate amount of blank frames to 172 determine the appropriate amount of blank frames to
152 insert before pressing [:a] to ensure that the attack is 173 insert before pressing [:a] to ensure that the attack is
153 a critical hit." 174 a critical hit."
154 [script] 175 [script]
155 (loop [blanks 6] 176 (delayed-improbability-search
156 (let [new-script 177 400
157 (->> script 178 #(search-string % "Critical")
158 (play-moves 179 (partial play-moves [[:a][]])
159 (concat (repeat blanks []) 180 script))
160 [[:a][]])))]
161 (if (let [future-state
162 (run-moves (second new-script)
163 (repeat 400 []))
164
165 result (search-string (memory future-state)
166 "Critical")]
167 (if result
168 (println "critical hit with" blanks "blank frames"))
169 result)
170 new-script
171 (recur (inc blanks))))))
172 181
173 (defn move-thru-grass 182 (defn move-thru-grass
174 [direction script] 183 [direction script]
175 (loop [blanks 0] 184 (delayed-improbability-search
176 (let [new-script 185 600
177 (->> script 186 #(nil? (search-string % "Wild"))
178 (play-moves (repeat blanks [])) 187 (partial move direction)
179 (move direction)) 188 script))
180
181 future-state
182 (run-moves (second new-script)
183 (repeat 600 []))
184
185 result (search-string (memory future-state)
186 "Wild")]
187 (if (nil? result)
188 (do
189 (if (< 0 blanks)
190 (do
191 (println "avoided pokemon with"
192 blanks "blank frames")))
193 new-script)
194 (recur (inc blanks))))))
195 189
196 (defn walk-thru-grass 190 (defn walk-thru-grass
197 [directions script] 191 [directions script]
198 (reduce (fn [script direction] 192 (reduce (fn [script direction]
199 (move-thru-grass direction script)) 193 (move-thru-grass direction script))