comparison clojure/com/aurellem/gb_driver.clj @ 82:04d539d26bdc

going to try using zippers
author Robert McIntyre <rlm@mit.edu>
date Fri, 09 Mar 2012 13:24:02 -0600
parents db8e0a563c8e
children 95cb2152d7cd
comparison
equal deleted inserted replaced
81:db8e0a563c8e 82:04d539d26bdc
135 (defn rewind 135 (defn rewind
136 ([] (rewind 1)) 136 ([] (rewind 1))
137 ([n] (goto (- @current-frame n)))) 137 ([n] (goto (- @current-frame n))))
138 138
139 (defn backup-state 139 (defn backup-state
140 [frame] 140 ([] (backup-state (frame)))
141 ([frame]
141 (let [save (save-state)] 142 (let [save (save-state)]
142 (swap! history #(assoc % frame save)) 143 (swap! history #(assoc % frame save))
143 ;;(store-save-to-disk save) 144 ;;(store-save-to-disk save)
144 (if (> (count @history) *max-history*) 145 (if (> (count @history) *max-history*)
145 (swap! history #(dissoc % (first (first %))))))) 146 (swap! history #(dissoc % (first (first %))))))))
146 147
147 (defn advance [] 148 (defn advance []
148 (if *save-history* 149 (if *save-history*
149 (backup-state @current-frame)) 150 (backup-state @current-frame))
150 (swap! current-frame inc)) 151 (swap! current-frame inc))
158 (Gb/step (button-mask mask-or-buttons))))) 159 (Gb/step (button-mask mask-or-buttons)))))
159 160
160 (defn play-moves 161 (defn play-moves
161 ([start moves] 162 ([start moves]
162 (goto start) 163 (goto start)
163 (dorun (map step moves))) 164 (dorun (map step moves))
165 (backup-state)
166 (frame))
164 ([moves] 167 ([moves]
165 (dorun (map step moves)))) 168 (dorun (map step moves))
169 (backup-state)
170 (frame)))
166 171
167 (defn play 172 (defn play
168 ([] (play Integer/MAX_VALUE)) 173 ([] (play Integer/MAX_VALUE))
169 ([n] (dorun (dotimes [_ n] (step))))) 174 ([n] (dorun (dotimes [_ n] (step)))))
170 175