Mercurial > vba-clojure
view clojure/com/aurellem/experiments/items.clj @ 122:e85b53994fac
working on proper timing for modes
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 16 Mar 2012 20:55:28 -0500 |
parents | 3a60bb14a64a |
children |
line wrap: on
line source
1 (ns com.aurellem.experiments.items2 (:use (com.aurellem gb-driver vbm title items))3 (:import [com.aurellem.gb_driver SaveState]))5 ;; try just buying five potions in sequence and see what changes6 ;; each time.8 (defn common-differences [& seqs]9 (let [backbone (range (count (first seqs)))]10 (filter11 (comp (partial apply distinct?) second)12 (zipmap backbone13 (apply (partial map list) seqs)))))15 ;; trying to find how items are represented in memory17 (def zero-potions (read-state "zero-potions"))19 (def one-potion (read-state "one-potion"))21 (def two-potions (read-state "two-potions"))23 (def three-potions (read-state "three-potions"))25 (def four-potions (read-state "four-potions"))27 (def five-potions (read-state "five-potions"))30 ;; result31 (defn canidates []32 (apply common-differences33 (map (comp vec memory)34 [zero-potions one-potion two-potions three-potions35 four-potions five-potions])))37 (comment [55875 (37 15 49 27 14 44)]38 [55876 (30 1 49 56 55 23)]39 [49158 (154 191 78 135 70 73)]40 [54087 (49 40 37 34 25 22)]41 [49160 (7 24 59 243 50 217)]42 [49704 (31 14 72 33 84 27)]43 [49162 (126 159 183 110 176 179)]44 [39984 (0 254 251 248 127 252)]45 [49904 (29 72 64 78 1 95)]46 [65491 (222 127 149 132 226 38)]47 [65492 (44 20 89 11 253 163)]48 [49335 (52 15 6 14 3 17)]49 [49720 (78 152 96 60 83 103)]50 [65304 (19 89 214 33 18 113)]51 [53561 (132 185 145 162 159 183)]52 [54046 (0 1 2 3 4 5)])54 ;;; hmmmmmm...... I guess that the potion quantities are at 54046,55 ;;;huh?59 (defn get-mem []60 (subvec (vec (memory @current-state)) 54040 (+ 54046 100)))63 ;; potion -- 9964 [0 16 0 0 1 20 99 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]66 ;; potion -- 9567 [0 16 0 0 1 20 95 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]69 ;; potion -- 9570 ;; pokeball -- 171 [0 16 0 0 2 20 95 4 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]73 ;; potion -- 9574 ;; pokeball -- 1075 [0 16 0 0 2 20 95 4 10 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]78 ;; pokeball -- 1079 ;; potion -- 9580 [0 16 0 0 2 4 10 20 95 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]82 ;; pokeball -- 1083 ;; potion -- 9584 ;; antidote -- 186 ;;prediction87 ;;[0 16 0 0 3 4 10 20 95 ?? 1 255 0 0 0 0 0 ....]88 [0 16 0 0 3 4 10 20 95 11 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]92 ;; now it's time to learn the item codes94 (def inventory-begin95 (read-state "inventory-begin"))97 (defn show-item98 "Run a saved pokemon with the first item replaced by the item named99 by n."100 [n]101 (set-state! inventory-begin)102 (let [mem (memory)]103 (aset mem 54044 1)104 (aset mem 54045 n)105 (aset mem 54046 1)106 (aset mem 54047 255)107 (write-memory! mem))108 (step)109 (->> [[] @current-state]110 (play-moves111 [[:a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []112 [] [] [] [] []])))115 (defn get-item-names []116 (dorun (map (fn [n] (println n)117 (show-item n)118 (Thread/sleep 5000))119 (range 0x00 0xFF))))121 ;; results (took about 10 minutes to generate)123 ;; 0 garbage124 ;; 1 master-ball125 ;; 2 ultra-ball126 ;; 3 great-ball127 ;; 4 poke-ball128 ;; 5 town-map129 ;; 6 bicycle130 ;; 7 ?????131 ;; 8 safari-ball132 ;; 9 pokedex133 ;; 10 moon-stone134 ;; 11 antidote135 ;; 12 burn-heal136 ;; 13 ice-heal137 ;; 14 awakening138 ;; 15 parlyz-heal139 ;; 16 full-restore140 ;; 17 max-potion141 ;; 18 hyper-potion142 ;; 19 super-potion143 ;; 20 potion144 ;; 21 boulderbadge145 ;; 22 cascadebadge146 ;; 23 thunderbadge147 ;; 24 rainbowbadge148 ;; 25 soulbadge149 ;; 26 marshbadge150 ;; 27 volcanobadge151 ;; 28 earthbadge152 ;; 29 escape-rope153 ;; 30 repel154 ;; 31 old amber155 ;; 32 fire-stone156 ;; 33 thunderstone157 ;; 34 water-stone158 ;; 35 hp-up159 ;; 36 protein160 ;; 37 iron161 ;; 38 carbos162 ;; 39 calcium163 ;; 40 rare-candy164 ;; 41 dome-fossil165 ;; 42 helix-fossil166 ;; 43 secret-key167 ;; 44 ?????168 ;; 45 bike-voucher169 ;; 46 x-accuracy170 ;; 47 leaf-stone171 ;; 48 card-key172 ;; 49 nugget173 ;; 50 pp-up174 ;; 51 poke-doll175 ;; 52 full-heal176 ;; 53 revive177 ;; 54 max-revive178 ;; 55 guard-spec.179 ;; 56 super-repel180 ;; 57 max-repel181 ;; 58 dire-hit182 ;; 59 coin183 ;; 60 fresh-water184 ;; 61 soda-pop185 ;; 62 lemonade186 ;; 63 s.s.ticket187 ;; 64 gold-teeth188 ;; 65 x-attach189 ;; 66 x-defend190 ;; 67 x-speed191 ;; 68 x-special192 ;; 69 coin-case193 ;; 70 oak's-parcel194 ;; 71 itemfinder195 ;; 72 silph-scope196 ;; 73 poke-flute197 ;; 74 lift-key198 ;; 75 exp.all199 ;; 76 old-rod200 ;; 77 good-rod201 ;; 78 super-rod202 ;; 79 pp-up203 ;; 80 ether204 ;; 81 max-ether205 ;; 82 elixer206 ;; 83 max-elixer207 ;; 84 B2F208 ;; 85 B1F209 ;; 86 1F210 ;; 87 2F211 ;; 88 3F212 ;; 89 4F213 ;; 90 5F214 ;; 91 6F215 ;; 92 7F216 ;; 93 8F217 ;; 94 9F218 ;; 95 10F219 ;; 96 11F220 ;; 97 B4F221 ;; 98 garbage222 ;; 99 garbage223 ;; 100 garbage224 ;; 101 garbage225 ;; 102 garbage226 ;; 103 garbage227 ;; 104 garbage228 ;; 105 garbage229 ;; 106 garbage230 ;; 107 garbage231 ;; 108 garbage232 ;; 109 garbage233 ;; 110 garbage234 ;; 111 garbage235 ;; 112 garbage236 ;; 113 garbage237 ;; 114 garbage238 ;; 115 garbage239 ;; 116 garbage240 ;; 117 garbage241 ;; 118 garbage242 ;; 119 4243 ;; 120 garbage244 ;; 121 garbage245 ;; 122 slow246 ;; 123 garbage247 ;; 124 garbage248 ;; 125 garbage249 ;; 126 garbage250 ;; 127 garbage251 ;; 128 garbage252 ;; 129 garbage253 ;; 130 garbage254 ;; 131 slow255 ;; 132 slow256 ;; 133 garbage257 ;; 134 slow258 ;; 135 garbage259 ;; 136 garbage260 ;; 137 slow261 ;; 138 garbage262 ;; 139 garbage263 ;; 140 garbage264 ;; 141 slow265 ;; 142 garbage266 ;; 143 garbage267 ;; 144 garbage268 ;; 145 garbage269 ;; 146 garbage270 ;; 147 garbage271 ;; 148 garbage272 ;; 149 garbage273 ;; 150 slow274 ;; 151 garbage275 ;; 152 Q276 ;; 153 garbage277 ;; 154 garbage278 ;; 155 garbage279 ;; 156 garbage280 ;; 157 garbage281 ;; 158 garbage282 ;; 159 garbage283 ;; 160 garbage (alaphabet)284 ;; 161 garbage285 ;; 162 garbage286 ;; 163 garbage287 ;; 164 rival's288 ;; 165 name?289 ;; 166 nickname?290 ;; 167 slow291 ;; 168 garbage292 ;; 169 slow293 ;; 170 garbage294 ;; 171 garbage295 ;; 172 garbage296 ;; 173 garbage297 ;; 174 garbage298 ;; 175 yellow299 ;; 176 ash300 ;; 177 jack301 ;; 178 new-name302 ;; 179 blue303 ;; 180 gary304 ;; 181 john305 ;; 182 garbage306 ;; 183 garbage307 ;; 184 garbage308 ;; 185 garbage309 ;; 186 slow310 ;; 187 garbage311 ;; 188 garbage312 ;; 189 garbage313 ;; 190 garbage314 ;; 191 garbage315 ;; 192 garbage316 ;; 193 garbage317 ;; 194 garbage318 ;; 195 slow319 ;; 196 HM01320 ;; 197 HM02321 ;; 198 HM03322 ;; 199 HM04323 ;; 200 HM05324 ;; 201 TM01325 ;; 202 TM02326 ;; 203 TM03327 ;; 204 TM04328 ;; 205 TM05329 ;; 206 TM06330 ;; 207 TM07331 ;; 208 TM08332 ;; 209 TM09333 ;; 210 TM10334 ;; 211 TM11335 ;; 212 TM12336 ;; 213 TM13337 ;; 214 TM13338 ;; 215 TM15339 ;; 216 TM16340 ;; 217 TM17341 ;; 218 TM18342 ;; 219 TM19343 ;; 220 TM20344 ;; 221 TM21345 ;; 222 TM22346 ;; 223 TM23347 ;; 224 TM24348 ;; 225 TM25349 ;; 226 TM26350 ;; 227 TM27351 ;; 228 TM28352 ;; 229 TM29353 ;; 230 TM30354 ;; 231 TM31355 ;; 232 TM32356 ;; 233 TM33357 ;; 234 TM34358 ;; 235 TM35359 ;; 236 TM36360 ;; 237 TM37361 ;; 238 TM38362 ;; 239 TM39363 ;; 240 TM40364 ;; 241 TM41365 ;; 242 TM42366 ;; 243 TM43367 ;; 244 TM44368 ;; 245 TM45369 ;; 246 TM46370 ;; 247 TM47371 ;; 248 TM48372 ;; 249 TM49373 ;; 250 TM50374 ;; 251 TM51375 ;; 252 TM52376 ;; 253 TM53377 ;; 254 TM54378 ;; 255 end-of-list-sentinel382 (defn run-item-program383 "This is my first assembly/item program!384 it just increments BC by one.386 The code places a 3 'great balls' at the beginning of the387 inventory, then directly sets the program counter to start388 executing at the position of the 'great balls' in memory.390 Since a 'great ball' is represented in memory as 0x03, which391 corresponts to the opcode which increments BC by one, that is392 what happens. Then the program counter to the 0x03 quantity entry393 and BC is incremented again.395 Obviously, the game crashes more or less immediately after the396 program counter advances past the 'great balls' into the next items397 in the inventory, thus I call shutdown! before anything bad happens."398 []399 (set-inventory (read-state "mid-game") [[:great-ball 3]])400 (print-inventory)401 (println "3 ticks") (tick) (tick) (tick)402 (println "PC before:" (PC))403 (println "BC before:" (BC))404 (PC! (inc item-list-start))405 (println "PC after setting:" (PC))406 (println "data at PC:" (aget (memory) (PC)))407 (println "one tick")408 (tick)409 (println "PC after one tick:" (PC))410 (println "BC after one tick:" (BC))411 (tick)412 (println "PC after two ticks:" (PC))413 (println "BC after two ticks:" (BC))415 (shutdown!))420 (defn test-opcodes-1421 []422 (let [final-state423 (->424 (read-state "mid-game")425 (set-inv-mem426 [20 0x02 0x00 0x00 0x02 0x00 0x00427 0x00 0x0 0xFF])428 (print-inventory)429 ;;((fn [_] (println "3 ticks") _))430 (tick) (tick) (tick)432 ;;(println "PC before:" (PC))433 ;;(println "BC before:" (BC))434 ;;(println "AF:" (AF))435 (PC! (inc item-list-start))436 (BC! (+ 1 item-list-start))437 ;;(println "PC after setting:" (PC))438 ;;(println "data at PC:" (aget (memory) (PC)))439 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))441 ;;(println "one tick")442 (tick)443 ;;(println "PC after one tick:" (PC))444 ;;(println "BC after one tick:" (BC))445 ;;(println "data at PC:" (aget (memory) (PC)))446 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))447 (tick)448 (AF! 0xFFFF)449 ;;(println "PC after two ticks:" (PC))450 ;;(println "BC after two ticks:" (BC))451 ;;(println "data at PC:" (aget (memory) (PC)))452 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))453 (tick)454 ;;(println "PC after three ticks:" (PC))455 ;;(println "BC after three ticks:" (BC))456 ;;(println "data at PC:" (aget (memory) (PC)))457 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))458 (tick)459 ;;(println "PC after four ticks:" (PC))460 ;;(println "BC after four ticks:" (BC))461 ;;(println "data at PC:" (aget (memory) (PC)))462 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))463 (tick)464 ;;(println "PC after five ticks:" (PC))465 ;;(println "BC after five ticks:" (BC))466 ;;(println "data at PC:" (aget (memory) (PC)))467 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))468 (print-inventory)469 )]471 (shutdown!)472 final-state))476 (defn test-opcodes-2477 []478 (set-inv-mem (read-state "mid-game")479 [20 0x08 0x1D 0xD3 0x00 0x00 0x00480 0x00 0x0 0xFF])481 (print-inventory)482 (println "3 ticks") (tick) (tick) (tick)483 (println "PC before:" (PC))484 (println "SP:" (SP))485 (PC! (inc item-list-start))486 (println "PC after setting:" (PC))487 (println "SP:" (Integer/toBinaryString (SP)))488 (println "data at PC:" (aget (memory) (PC)))489 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))490 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))491 (println "one tick")492 (tick)493 (println "PC after one tick:" (PC))494 (println "data at PC:" (aget (memory) (PC)))495 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))496 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))497 (tick) (tick) (tick)498 (println "PC aftter four tick:" (PC))499 (println "data at PC:" (aget (memory) (PC)))500 (println "data at 0xD31D:" (aget (memory) 0xD31D))502 (print-inventory)503 (shutdown!))