comparison clojure/com/aurellem/run/util.clj @ 320:9637a0f52e7b

located item-list related addresses.
author Robert McIntyre <rlm@mit.edu>
date Tue, 03 Apr 2012 23:17:33 -0500
parents 92c47a9cdaea
children fe6fd2323264
comparison
equal deleted inserted replaced
319:92c47a9cdaea 320:9637a0f52e7b
105 [directions script] 105 [directions script]
106 (reduce (fn [script dir] 106 (reduce (fn [script dir]
107 (move dir script)) script directions)) 107 (move dir script)) script directions))
108 108
109 (defn search-string 109 (defn search-string
110 [^SaveState state string] 110 ([^SaveState state string]
111 (let [codes 111 (let [codes
112 (str->character-codes string) 112 (str->character-codes string)
113 codes-length (count codes) 113 codes-length (count codes)
114 mem (vec (memory state)) 114 mem (vec (memory state))
115 mem-length (count mem)] 115 mem-length (count mem)]
116 (loop [idx 0] 116 (loop [idx 0]
117 (if (< (- mem-length idx) codes-length) 117 (if (< (- mem-length idx) codes-length)
118 nil 118 nil
119 (if (= (subvec mem idx (+ idx codes-length)) 119 (if (= (subvec mem idx (+ idx codes-length))
120 codes) 120 codes)
121 idx 121 idx
122 (recur (inc idx))))))) 122 (recur (inc idx)))))))
123 ([string]
124 (search-string @current-state string)))
123 125
124 (def text-address 0x9DC1) 126 (def text-address 0x9DC1)
125 127
126 (defn displayed-text 128 (defn displayed-text
127 ([^SaveState state] 129 ([^SaveState state]
141 script 143 script
142 (range n)))) 144 (range n))))
143 145
144 (defn end-text 146 (defn end-text
145 ([script] 147 ([script]
146 (->> (do-nothing 150) 148 (->>
147 (play-moves [[:b]])))) 149 script
150 (do-nothing 150)
151 (play-moves [[:b]]))))
148 152
149 (defn do-nothing [n script] 153 (defn do-nothing [n script]
150 (->> script 154 (->> script
151 (play-moves 155 (play-moves
152 (repeat n [])))) 156 (repeat n []))))