Mercurial > vba-clojure
comparison clojure/com/aurellem/run/bootstrap_0.clj @ 330:ecff37d22293
made more progress, have burn heals and correct name for rival.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 06 Apr 2012 09:09:52 -0500 |
parents | a452deec2882 |
children | 6ec288064d49 |
comparison
equal
deleted
inserted
replaced
329:a452deec2882 | 330:ecff37d22293 |
---|---|
396 (set-cursor-relative difference script))) | 396 (set-cursor-relative difference script))) |
397 | 397 |
398 (defn set-quantity | 398 (defn set-quantity |
399 "Set the quantity of an item to buy or sell to the desired value | 399 "Set the quantity of an item to buy or sell to the desired value |
400 using the fewest possible button presses." | 400 using the fewest possible button presses." |
401 [total-quantity desired-quantity [moves state :as script]] | 401 ([total-quantity desired-quantity [moves state :as script]] |
402 (let [current-quantity (item-quantity-selected state) | 402 (let [current-quantity (item-quantity-selected state) |
403 loop-point (if (> total-quantity 99) 0xFF 99) | 403 loop-point (if (> total-quantity 99) 0xFF 99) |
404 distance (- desired-quantity current-quantity) | 404 distance (- desired-quantity current-quantity) |
405 loop-distance (int(* -1 (Math/signum (float distance)) | 405 loop-distance (int(* -1 (Math/signum (float distance)) |
406 (- loop-point (Math/abs distance)))) | 406 (- loop-point (Math/abs distance)))) |
407 best-path (first (sort-by #(Math/abs %) | 407 best-path (first (sort-by #(Math/abs %) |
408 [distance loop-distance])) | 408 [distance loop-distance])) |
409 direction (if (< 0 best-path) ↑ ↓)] | 409 direction (if (< 0 best-path) ↑ ↓)] |
410 (println "best-path" best-path) | 410 (println "best-path" best-path) |
411 (reduce | 411 (reduce |
412 (fn [script _] | 412 (fn [script _] |
413 (delayed-difference [] direction 200 item-quantity-selected | 413 (delayed-difference [] direction 5 item-quantity-selected |
414 script)) | 414 script)) |
415 | 415 |
416 script | 416 script |
417 (range (Math/abs best-path))))) | 417 (range (Math/abs best-path))))) |
418 ([desired-quantity [moves state :as script]] | |
419 (set-quantity 99 desired-quantity script))) | |
418 | 420 |
419 (defn-memo do-save-corruption | 421 (defn-memo do-save-corruption |
420 ([] (do-save-corruption | 422 ([] (do-save-corruption |
421 (walk-to-counter))) | 423 (walk-to-counter))) |
422 ([script] | 424 ([script] |
447 [(read-moves "cor-checkpoint") | 449 [(read-moves "cor-checkpoint") |
448 (read-state "cor-checkpoint")]) | 450 (read-state "cor-checkpoint")]) |
449 | 451 |
450 (def menu do-nothing ) | 452 (def menu do-nothing ) |
451 | 453 |
454 (defn close-menu [script] | |
455 (first-difference [] [:b] AF script)) | |
456 | |
457 (defn wait-until [script-fn script] | |
458 (let [wait-time | |
459 (- (dec (count (first (script-fn script)))) | |
460 (count (first script)))] | |
461 (println "wait-time" wait-time) | |
462 (do-nothing wait-time script))) | |
463 | |
464 ;; (defn select-menu-entry* [script] | |
465 ;; (let [wait-time | |
466 ;; (- (dec (count (first (set-cursor-relative 1 script)))) | |
467 ;; (count (first script)))] | |
468 ;; (println "wait-time" wait-time) | |
469 ;; (play-moves (concat (repeat wait-time []) [[:a] []]) script))) | |
470 | |
471 (defn select-menu-entry [script] | |
472 (->> script | |
473 (wait-until (partial set-cursor-relative 1)) | |
474 (play-moves [[:a] []]))) | |
475 | |
476 (defn purchase-item | |
477 "Assumes that the cursor is over the desired item, and purchases | |
478 quantity of that item." | |
479 [n script] | |
480 (->> script | |
481 select-menu-entry | |
482 (set-quantity n) | |
483 (first-difference [] [:a] AF) | |
484 scroll-text | |
485 select-menu-entry | |
486 scroll-text)) | |
487 | |
488 (defn activate-start-menu [script] | |
489 (first-difference [:b] [:b :start] AF script)) | |
490 | |
452 (defn-memo corrupt-item-list | 491 (defn-memo corrupt-item-list |
453 "Corrupt the num-of-items variable by switching a corrupted pokemon | 492 "Corrupt the num-of-items variable by switching a corrupted pokemon |
454 into out-of-bounds memory." | 493 into out-of-bounds memory." |
455 ([] (corrupt-item-list | 494 ([] (corrupt-item-list |
456 (corrupted-checkpoint))) | 495 (corrupted-checkpoint))) |
457 ([script] | 496 ([script] |
458 (->> script | 497 (->> script |
459 (first-difference [:a] [:a :start] AF) | 498 activate-start-menu |
460 (set-cursor 1) ; select "POKEMON" from | 499 (set-cursor 1) ; select "POKEMON" from |
461 (first-difference [] [:a] AF) ; from main menu | 500 select-menu-entry ; from main menu. |
462 (set-cursor 5) ; select 6th pokemon | 501 (set-cursor 5) ; select 6th pokemon |
463 (first-difference [] [:a] AF) | 502 select-menu-entry |
464 (set-cursor 1) | 503 (set-cursor 1) |
465 (first-difference [] [:a] AF) | 504 select-menu-entry |
466 (repeat-until-different [] list-offset) | 505 (repeat-until-different [] list-offset) |
467 (set-cursor 9) | 506 (set-cursor 9) |
468 (first-difference [] [:a] AF) ; switch 6th with 10th | 507 select-menu-entry ; switch 6th with 10th |
469 (first-difference [] [:b] AF) | 508 close-menu |
470 (first-difference [] [:b] AF)))) | 509 close-menu))) |
471 | 510 |
472 (defn get-lots-of-money | 511 (defn-memo get-lots-of-money |
473 "Sell 0xFE cancel buttons to make a tremendous amount of money." | 512 "Sell 0xFE cancel buttons to make a tremendous amount of money." |
474 ([] (get-lots-of-money (corrupt-item-list))) | 513 ([] (get-lots-of-money (corrupt-item-list))) |
475 ([script] | 514 ([script] |
476 (->> script | 515 (->> script |
477 (first-difference [] [:a] AF) | 516 (first-difference [] [:a] AF) ; talk to shopkeep |
478 (repeat-until-different [] list-offset) | 517 (repeat-until-different [] list-offset) |
479 (set-cursor 1) | 518 (set-cursor 1) |
480 (first-difference [] [:a] AF) | 519 select-menu-entry |
481 (repeat-until-different [] list-offset) | 520 (repeat-until-different [] list-offset) |
482 (first-difference [] [:a] AF) | 521 select-menu-entry |
483 (set-quantity 0xFF 0xFE) | 522 (set-quantity 0xFF 0xFE) |
523 (scroll-text) | |
524 select-menu-entry))) | |
525 | |
526 (defn note [str script] | |
527 (println str) script) | |
528 | |
529 (defn-memo buy-bootstrapping-items | |
530 "Buy items that will become part of the bootstrapping | |
531 program." | |
532 ([] (buy-bootstrapping-items (get-lots-of-money))) | |
533 ([script] | |
534 (->> script | |
535 close-menu | |
536 select-menu-entry | |
537 (purchase-item 1) ; buying a pokeball overflows | |
538 ; the item-counter from 0xFF to 0x00 | |
539 ; repairing the item-list. | |
540 (set-cursor 1) | |
541 (purchase-item 1) ; these other items are here to | |
542 ; protect the burn heals when the | |
543 (set-cursor 2) ; item list is corrupted again. | |
544 (purchase-item 1) | |
545 | |
546 (set-cursor 3) | |
547 (purchase-item 1) | |
548 | |
549 (set-cursor 4) ; 95 burn-heals spells out the | |
550 (purchase-item 96) ; return address to the pokemon | |
551 ; kernel. 96 so that they can be | |
552 ; deposited without causing a shift. | |
553 | |
554 close-menu ; stop talking to shopkeep | |
555 (wait-until select-menu-entry) | |
556 (play-moves [[:b]]) | |
557 end-text))) | |
558 | |
559 (defn corrupt-item-list-again | |
560 ([] (corrupt-item-list-again (buy-bootstrapping-items))) | |
561 ([script] | |
562 (->> script | |
563 | |
564 activate-start-menu | |
565 (set-cursor-relative 0) | |
566 select-menu-entry | |
567 | |
568 ;; repair list-offset for pokemon-list | |
569 (set-cursor-relative -1) | |
570 | |
571 | |
572 (set-cursor 4) ; switching it to | |
573 select-menu-entry ; tenth place. | |
574 (set-cursor 1) | |
575 select-menu-entry ; select "switch" on 5th | |
576 | |
577 (repeat-until-different [] list-offset) | |
578 (set-cursor 9) ; goto 10th pokemon | |
579 select-menu-entry ; do switch | |
580 close-menu | |
581 close-menu | |
582 | |
484 (do-nothing 1) | 583 (do-nothing 1) |
584 ;;select-menu-entry | |
585 ;; | |
586 ;;(set-cursor 9) | |
587 ;;select-menu-entry | |
588 ;;close-menu | |
589 | |
485 ))) | 590 ))) |
486 | 591 ;; (do-nothing 10) |
487 | 592 ;; (play-moves [[:b]]) |
488 | 593 ;; (do-nothing 100) |
489 | 594 ;; (play-moves [[:b]]) |
490 (def buy-items do-nothing) | 595 ;; (do-nothing 40) |
491 | 596 ;; (play-moves [[:b]]) |
492 (defn-memo get-burn-heals | 597 ;; (first-difference [:b] [:start :b] AF) |
493 ([] (get-burn-heals | 598 ;; (menu [[:a] ↑ ↑ ↑ ↑ ↑ |
494 (corrupt-item-list))) | 599 ;; [:a] ↓ [:a] |
495 ([script] | 600 ;; ↓ ↓ ↓ ↓ ↓ [:a]]) |
496 (->> script | 601 ;; |
497 (menu [[:b] [:b]]) | 602 ;; ))) |
498 (menu [[:a]]) | |
499 (do-nothing 100) | |
500 (menu [↓ [:a]]) | |
501 (do-nothing 100) | |
502 (menu [[:a] ↓ [:a]]) | |
503 (scroll-text) | |
504 (menu [[:b][:b]]) | |
505 (menu [[:a]]) | |
506 | |
507 (do-nothing 50) | |
508 (buy-items [[0 1]]) | |
509 (do-nothing 60) | |
510 (menu [[:a]]) | |
511 (scroll-text) | |
512 | |
513 (do-nothing 50) | |
514 (buy-items [[0 1]]) | |
515 (do-nothing 60) | |
516 ;;(menu [[:a]]) | |
517 ;;(scroll-text) | |
518 | |
519 ;;(do-nothing 300) | |
520 ;;(menu [[:b] [:b]]) | |
521 ;;(do-nothing 300) | |
522 | |
523 (buy-items [[0 1] | |
524 [1 1] | |
525 [1 1] | |
526 [2 1] | |
527 [3 1] | |
528 [4 97]]) | |
529 | |
530 (do-nothing 10)))) | |
531 | |
532 (defn-memo corrupt-item-list-again | |
533 ([] (corrupt-item-list-again (get-burn-heals))) | |
534 ([script] | |
535 (->> script | |
536 (do-nothing 10) | |
537 (play-moves [[:b]]) | |
538 (do-nothing 100) | |
539 (play-moves [[:b]]) | |
540 (do-nothing 40) | |
541 (play-moves [[:b]]) | |
542 (first-difference [:b] [:start :b] AF) | |
543 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon | |
544 [:a] ↓ [:a] ; and corrupt the | |
545 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by | |
546 ; switching it to | |
547 ))) ; tenth place. | |
548 | 603 |
549 (defn-memo viridian-store->viridian-poke-center | 604 (defn-memo viridian-store->viridian-poke-center |
550 ([] (viridian-store->viridian-poke-center | 605 ([] (viridian-store->viridian-poke-center |
551 (corrupt-item-list-again))) | 606 (corrupt-item-list-again))) |
552 ([script] | 607 ([script] |