comparison clojure/com/aurellem/gb_funs.clj @ 85:3f4fdd270059

more progress with the title
author Robert McIntyre <rlm@mit.edu>
date Sat, 10 Mar 2012 00:32:11 -0600
parents 26f002f2868c
children 9864032ef3c8
comparison
equal deleted inserted replaced
84:26f002f2868c 85:3f4fdd270059
88 88
89 (def current-state (atom nil)) 89 (def current-state (atom nil))
90 90
91 91
92 (defn set-state! [^SaveState state] 92 (defn set-state! [^SaveState state]
93 (assert (:data state) "Not a valid state!")
93 (if (not @on?) (restart!)) 94 (if (not @on?) (restart!))
94 (if (not= @current-state state) 95 (if (not= @current-state state)
95 (Gb/loadState (:data state))) 96 (Gb/loadState (:data state)))
96 (reset! current-state state)) 97 (reset! current-state state))
97 98
111 [^Move move buttons] 112 [^Move move buttons]
112 (Move. (step (:state move) buttons) buttons)) 113 (Move. (step (:state move) buttons) buttons))
113 114
114 115
115 (defn play 116 (defn play
116 ([state n] 117 ([^SaveState state n]
117 (reduce (fn [s _] (step s)) state (range n))) 118 (reduce (fn [s _] (step s)) state (range n)))
118 ([state] 119 ([n]
119 (dorun (iterate step state)))) 120 (play @current-state n)))
121
122 (defn play-moves
123 ([state moves]
124
125 ([moves]
126 (dorun (map (fn [move] (step @current-state move)) moves))))
127
120 ;;;;;;;;;;; 128 ;;;;;;;;;;;
121 129
122 130
123 ;;;;;;;;;;;;;;; CPU data 131 ;;;;;;;;;;;;;;; CPU data
124 132
151 (nth (registers state) 2)) 159 (nth (registers state) 2))
152 160
153 (defn BC [state] 161 (defn BC [state]
154 (nth (registers state) 3)) 162 (nth (registers state) 3))
155 163
156 164 (defn DE [state]
165 (nth (registers state) 4))
157 166
158 167