comparison clojure/com/aurellem/run/bootstrap_0.clj @ 332:5c2041d1cdda

solving problem with rival name becomming a key item.
author Robert McIntyre <rlm@mit.edu>
date Fri, 06 Apr 2012 13:52:08 -0500
parents 6ec288064d49
children 61a096a53330
comparison
equal deleted inserted replaced
331:6ec288064d49 332:5c2041d1cdda
26 (play-moves 26 (play-moves
27 [[] 27 [[]
28 [] [] [:r] [] [:d] [:a] ;; L 28 [] [] [:r] [] [:d] [:a] ;; L
29 [:r] [] [:r] [] [:r] [] [:r] [] 29 [:r] [] [:r] [] [:r] [] [:r] []
30 [:r] [] [:d] [] [:d] [:a] ;; [PK] 30 [:r] [] [:d] [] [:d] [:a] ;; [PK]
31 [:u] [] [:l] [] [:l] [] 31 [:u] [] [:l] [] [:l] [] [:l] []
32 [:l] [] [:l] [] [:l] [:a] ;; U 32 [:l] [] [:l] [] [:a] ;; U
33 [:r] [] [:r] [] [:r] [] 33 [:r] [] [:r] [] [:r] [] [:r] []
34 [:r] [] [:r] [] [:d] [:a] ;; [PK] 34 [:r] [] [] [:d] [:a] ;; [PK]
35 [] [:a] ;; [PK] 35 [] [:a] ;; [PK]
36 [] [:a] ;; [PK] 36 [] [:a] ;; [PK]
37 [:r] [] [:d] [:a] ;; END 37 [:r] [] [:d] [:a] ;; END
38 ])))) 38 ]))))
39
40 ;; (defn-memo name-rival-bootstrap
41 ;; ([] (name-rival-bootstrap (to-rival-name)))
42 ;; ([script]
43 ;; (->> script
44 ;; (first-difference [] [:a] AF)
45 ;; (first-difference [] [:r] DE)
46 ;; (play-moves
47 ;; [[]
48 ;; [] [] [:r] []
49 ;; [:r] [] [:r] [] [:r] [] [:r] []
50 ;; [:r] [] [:d] [] [:d] [] [:d] [:a];; PK
51 ;; [] [:a] ;; PK
52 ;; [:u] [] [:l] [] [:l] [] [:l] []
53 ;; [:l] [] [:l] [:a] ;; U
54 ;; [:d] [] [:r] [] [:r] [] [:r] []
55 ;; [:r] [] [:r] [:a] ;; PK
56 ;; [:u] [] [:l] [] [:l] [] [:l] []
57 ;; [:l] [] [:l] [] [:u] [:a] ;; L
58 ;; [:d] [] [:r] [] [:r] [] [:r] []
59 ;; [:r] [] [:r] [] [:d] [:a] ;; PK
60 ;; [:r] [] [:d] [:a] ;; END
61 ;; ]))))
39 62
40 (defn-memo leave-house 63 (defn-memo leave-house
41 ([] (leave-house (name-rival-bootstrap))) 64 ([] (leave-house (name-rival-bootstrap)))
42 ([script] 65 ([script]
43 (->> script 66 (->> script
268 [↓ ↓ ← ↓ 291 [↓ ↓ ← ↓
269 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 292 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
270 → → → ↓]) 293 → → → ↓])
271 294
272 (walk-thru-grass 295 (walk-thru-grass
273 [↓ ↓ ↓]) 296 [↓ ↓ ↓ ↓])
274 297
275 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓]) 298 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓])
276 299
277 (walk-thru-grass 300 (walk-thru-grass
278 [↓ ↓ ↓ ↓ ↓ ↓]) 301 [↓ ↓ ↓ ↓ ↓ ↓])
279 302
280 (walk [↓ ↓ ↓ ← ↓ ↓ ↓ 303 (walk [↓ ↓ ↓ ← ↓ ↓ ↓
349 ([^SaveState state] 372 ([^SaveState state]
350 (let [mem (memory state)] 373 (let [mem (memory state)]
351 (+ (aget mem list-screen-offset-address) 374 (+ (aget mem list-screen-offset-address)
352 (aget mem list-cursor-offset-address)))) 375 (aget mem list-cursor-offset-address))))
353 ([] (list-offset @current-state))) 376 ([] (list-offset @current-state)))
354
355
356 377
357 (defn exp-item-selection [] 378 (defn exp-item-selection []
358 (clojure.pprint/pprint 379 (clojure.pprint/pprint
359 (apply memory-compare 380 (apply memory-compare
360 (map read-state 381 (map read-state
419 (set-quantity 99 desired-quantity script))) 440 (set-quantity 99 desired-quantity script)))
420 441
421 (defn activate-start-menu [script] 442 (defn activate-start-menu [script]
422 (first-difference [:b] [:b :start] AF script)) 443 (first-difference [:b] [:b :start] AF script))
423 444
445 (defn wait-until [script-fn script]
446 (let [wait-time
447 (- (dec (count (first (script-fn script))))
448 (count (first script)))]
449 (println "wait-time" wait-time)
450 (do-nothing wait-time script)))
451
452 (defn select-menu-entry [script]
453 (->> script
454 (wait-until (partial set-cursor-relative 1))
455 (play-moves [[:a] []])))
456
424 (defn-memo do-save-corruption 457 (defn-memo do-save-corruption
425 ([] (do-save-corruption 458 ([] (do-save-corruption
426 (walk-to-counter))) 459 (walk-to-counter)))
427 ([script] 460 ([script]
428 (->> script 461 (->> script
453 (def menu do-nothing ) 486 (def menu do-nothing )
454 487
455 (defn close-menu [script] 488 (defn close-menu [script]
456 (first-difference [] [:b] AF script)) 489 (first-difference [] [:b] AF script))
457 490
458 (defn wait-until [script-fn script] 491
459 (let [wait-time
460 (- (dec (count (first (script-fn script))))
461 (count (first script)))]
462 (println "wait-time" wait-time)
463 (do-nothing wait-time script)))
464 492
465 ;; (defn select-menu-entry* [script] 493 ;; (defn select-menu-entry* [script]
466 ;; (let [wait-time 494 ;; (let [wait-time
467 ;; (- (dec (count (first (set-cursor-relative 1 script)))) 495 ;; (- (dec (count (first (set-cursor-relative 1 script))))
468 ;; (count (first script)))] 496 ;; (count (first script)))]
469 ;; (println "wait-time" wait-time) 497 ;; (println "wait-time" wait-time)
470 ;; (play-moves (concat (repeat wait-time []) [[:a] []]) script))) 498 ;; (play-moves (concat (repeat wait-time []) [[:a] []]) script)))
471 499
472 (defn select-menu-entry [script]
473 (->> script
474 (wait-until (partial set-cursor-relative 1))
475 (play-moves [[:a] []])))
476 500
477 (defn purchase-item 501 (defn purchase-item
478 "Assumes that the cursor is over the desired item, and purchases 502 "Assumes that the cursor is over the desired item, and purchases
479 quantity of that item." 503 quantity of that item."
480 [n script] 504 [n script]
504 select-menu-entry 528 select-menu-entry
505 (repeat-until-different [] list-offset) 529 (repeat-until-different [] list-offset)
506 (set-cursor 9) 530 (set-cursor 9)
507 select-menu-entry ; switch 6th with 10th 531 select-menu-entry ; switch 6th with 10th
508 close-menu 532 close-menu
509 close-menu))) 533 close-menu )))
510 534
511 (defn-memo get-lots-of-money 535 (defn-memo get-lots-of-money
512 "Sell 0xFE cancel buttons to make a tremendous amount of money." 536 "Sell 0xFE cancel buttons to make a tremendous amount of money."
513 ([] (get-lots-of-money (corrupt-item-list))) 537 ([] (get-lots-of-money (corrupt-item-list)))
514 ([script] 538 ([script]
517 (repeat-until-different [] list-offset) 541 (repeat-until-different [] list-offset)
518 (set-cursor 1) 542 (set-cursor 1)
519 select-menu-entry 543 select-menu-entry
520 (repeat-until-different [] list-offset) 544 (repeat-until-different [] list-offset)
521 select-menu-entry 545 select-menu-entry
522 (set-quantity 0xFF 0xFE) 546 (set-quantity 0xFF 0xF7)
523 (scroll-text) 547 (first-difference [] [:a] AF)
524 select-menu-entry))) 548 select-menu-entry
549 close-menu
550 )))
551
525 552
526 (defn note [str script] 553 (defn note [str script]
527 (println str) script) 554 (println str) script)
528 555
529 (defn-memo buy-bootstrapping-items 556 (defn-memo buy-bootstrapping-items
703 5 730 5
704 [0xFF 0x01]) 731 [0xFF 0x01])
705 732
706 [;; first part of item manipulation program 733 [;; first part of item manipulation program
707 0x00 734 0x00
708 0x21 ;; load target into HL 735 0x21 ;; load target + 1 into HL
709 736
710 0x94 ;; this is the target address 737 0x95 ;; this is the target address + 1
711 0xD5 738 0xD5
712 739
713 0x00 ;; relative jump back to first part 740 0x00 ;; relative jump back to first part
714 0x18 741 0x18
715 742