comparison clojure/com/aurellem/run/util.clj @ 317:3c5bf2221ea0

remove crufty functions.
author Robert McIntyre <rlm@mit.edu>
date Mon, 02 Apr 2012 21:25:24 -0500
parents d263df762c59
children 9a4d3f801c89
comparison
equal deleted inserted replaced
316:d263df762c59 317:3c5bf2221ea0
77 (repeat (inc delay) base)))))) 77 (repeat (inc delay) base))))))
78 new-moves (concat moves (repeat len base) [alt]) 78 new-moves (concat moves (repeat len base) [alt])
79 new-state (run-moves (generator len) [alt])] 79 new-state (run-moves (generator len) [alt])]
80 [new-moves new-state])) 80 [new-moves new-state]))
81 81
82 (defn delayed-difference
83 [base alt delay difference-metric [moves root :as script]]
84 (loop [branch-point root
85 actions moves]
86 (let [base-branch (step branch-point base)
87 base-val
88 (difference-metric
89 (run-moves base-branch
90 (repeat delay base)))
91 alt-branch (step branch-point alt)
92 alt-val
93 (difference-metric
94 (run-moves alt-branch
95 (repeat delay base)))]
96 (if (not= base-val alt-val)
97 [(conj actions alt) alt-branch]
98 (recur base-branch (conj actions base))))))
99
100
101
102
103
104
105
106 ;; (defn advance
107 ;; ([base alt difference-metric [commands state]]
108 ;; (let [[c s]
109 ;; (first-difference base alt difference-metric state)]
110 ;; [(concat commands c) s]))
111 ;; ([base alt [commands state]]
112 ;; (advance base alt AF [commands state]))
113 ;; ([alt [commands state]]
114 ;; (advance [] alt [commands state])))
115
116
117 (def x-position-address 0xD361) 82 (def x-position-address 0xD361)
118 (def y-position-address 0xD362) 83 (def y-position-address 0xD362)
119 84
120 (defn x-position 85 (defn x-position
121 ([^SaveState state] 86 ([^SaveState state]
137 (defn walk 102 (defn walk
138 "Move the character along the given directions." 103 "Move the character along the given directions."
139 [directions script] 104 [directions script]
140 (reduce (fn [script dir] 105 (reduce (fn [script dir]
141 (move dir script)) script directions)) 106 (move dir script)) script directions))
142
143 (defn menu
144 [directions script]
145 (reduce (fn [script direction]
146 (move direction script))
147 script directions))
148
149 107
150 (defn search-string 108 (defn search-string
151 [^SaveState state string] 109 [^SaveState state string]
152 (let [codes 110 (let [codes
153 (str->character-codes string) 111 (str->character-codes string)
170 (subvec (vec (memory state)) 128 (subvec (vec (memory state))
171 text-address 129 text-address
172 (+ text-address 82)))) 130 (+ text-address 82))))
173 ([] (displayed-text @current-state))) 131 ([] (displayed-text @current-state)))
174 132
175 ;; (defn scroll-text
176 ;; ([script]
177 ;; (first-difference [:b] [:a :b] AF script))
178 ;; ([n script]
179 ;; (reduce (fn [script _]
180 ;; (scroll-text script))
181 ;; script
182 ;; (range n))))
183
184 (defn scroll-text 133 (defn scroll-text
185 ([script] 134 ([script]
186 (delayed-difference 135 (delayed-difference
187 [:b] [:a :b] 25 displayed-text script)) 136 [:b] [:a :b] 25 displayed-text script))
188 ([n script] 137 ([n script]
189 (reduce (fn [script _] 138 (reduce (fn [script _]
190 (scroll-text script)) 139 (scroll-text script))
191 script 140 script
192 (range n)))) 141 (range n))))
193
194
195 (defn end-text [script]
196 (->> script
197 (scroll-text)
198 (play-moves [[] [:a]])))
199
200
201
202 (memory-compare
203 (step (talk-to-oak) [:a])
204 (step (talk-to-oak) [])
205 (step (oak-battle) [])
206 (step (oak-battle) [:a]))
207
208
209
210
211
212 142
213 (defn do-nothing [n script] 143 (defn do-nothing [n script]
214 (->> script 144 (->> script
215 (play-moves 145 (play-moves
216 (repeat n [])))) 146 (repeat n []))))