Mercurial > vba-clojure
diff 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 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj Fri Apr 06 07:22:18 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Fri Apr 06 09:09:52 2012 -0500 1.3 @@ -398,23 +398,25 @@ 1.4 (defn set-quantity 1.5 "Set the quantity of an item to buy or sell to the desired value 1.6 using the fewest possible button presses." 1.7 - [total-quantity desired-quantity [moves state :as script]] 1.8 - (let [current-quantity (item-quantity-selected state) 1.9 - loop-point (if (> total-quantity 99) 0xFF 99) 1.10 - distance (- desired-quantity current-quantity) 1.11 - loop-distance (int(* -1 (Math/signum (float distance)) 1.12 - (- loop-point (Math/abs distance)))) 1.13 - best-path (first (sort-by #(Math/abs %) 1.14 - [distance loop-distance])) 1.15 - direction (if (< 0 best-path) ↑ ↓)] 1.16 - (println "best-path" best-path) 1.17 - (reduce 1.18 - (fn [script _] 1.19 - (delayed-difference [] direction 200 item-quantity-selected 1.20 - script)) 1.21 - 1.22 - script 1.23 - (range (Math/abs best-path))))) 1.24 + ([total-quantity desired-quantity [moves state :as script]] 1.25 + (let [current-quantity (item-quantity-selected state) 1.26 + loop-point (if (> total-quantity 99) 0xFF 99) 1.27 + distance (- desired-quantity current-quantity) 1.28 + loop-distance (int(* -1 (Math/signum (float distance)) 1.29 + (- loop-point (Math/abs distance)))) 1.30 + best-path (first (sort-by #(Math/abs %) 1.31 + [distance loop-distance])) 1.32 + direction (if (< 0 best-path) ↑ ↓)] 1.33 + (println "best-path" best-path) 1.34 + (reduce 1.35 + (fn [script _] 1.36 + (delayed-difference [] direction 5 item-quantity-selected 1.37 + script)) 1.38 + 1.39 + script 1.40 + (range (Math/abs best-path))))) 1.41 + ([desired-quantity [moves state :as script]] 1.42 + (set-quantity 99 desired-quantity script))) 1.43 1.44 (defn-memo do-save-corruption 1.45 ([] (do-save-corruption 1.46 @@ -449,6 +451,43 @@ 1.47 1.48 (def menu do-nothing ) 1.49 1.50 +(defn close-menu [script] 1.51 + (first-difference [] [:b] AF script)) 1.52 + 1.53 +(defn wait-until [script-fn script] 1.54 + (let [wait-time 1.55 + (- (dec (count (first (script-fn script)))) 1.56 + (count (first script)))] 1.57 + (println "wait-time" wait-time) 1.58 + (do-nothing wait-time script))) 1.59 + 1.60 +;; (defn select-menu-entry* [script] 1.61 +;; (let [wait-time 1.62 +;; (- (dec (count (first (set-cursor-relative 1 script)))) 1.63 +;; (count (first script)))] 1.64 +;; (println "wait-time" wait-time) 1.65 +;; (play-moves (concat (repeat wait-time []) [[:a] []]) script))) 1.66 + 1.67 +(defn select-menu-entry [script] 1.68 + (->> script 1.69 + (wait-until (partial set-cursor-relative 1)) 1.70 + (play-moves [[:a] []]))) 1.71 + 1.72 +(defn purchase-item 1.73 + "Assumes that the cursor is over the desired item, and purchases 1.74 + quantity of that item." 1.75 + [n script] 1.76 + (->> script 1.77 + select-menu-entry 1.78 + (set-quantity n) 1.79 + (first-difference [] [:a] AF) 1.80 + scroll-text 1.81 + select-menu-entry 1.82 + scroll-text)) 1.83 + 1.84 +(defn activate-start-menu [script] 1.85 + (first-difference [:b] [:b :start] AF script)) 1.86 + 1.87 (defn-memo corrupt-item-list 1.88 "Corrupt the num-of-items variable by switching a corrupted pokemon 1.89 into out-of-bounds memory." 1.90 @@ -456,95 +495,111 @@ 1.91 (corrupted-checkpoint))) 1.92 ([script] 1.93 (->> script 1.94 - (first-difference [:a] [:a :start] AF) 1.95 - (set-cursor 1) ; select "POKEMON" from 1.96 - (first-difference [] [:a] AF) ; from main menu 1.97 - (set-cursor 5) ; select 6th pokemon 1.98 - (first-difference [] [:a] AF) 1.99 + activate-start-menu 1.100 + (set-cursor 1) ; select "POKEMON" from 1.101 + select-menu-entry ; from main menu. 1.102 + (set-cursor 5) ; select 6th pokemon 1.103 + select-menu-entry 1.104 (set-cursor 1) 1.105 - (first-difference [] [:a] AF) 1.106 + select-menu-entry 1.107 (repeat-until-different [] list-offset) 1.108 (set-cursor 9) 1.109 - (first-difference [] [:a] AF) ; switch 6th with 10th 1.110 - (first-difference [] [:b] AF) 1.111 - (first-difference [] [:b] AF)))) 1.112 + select-menu-entry ; switch 6th with 10th 1.113 + close-menu 1.114 + close-menu))) 1.115 1.116 -(defn get-lots-of-money 1.117 +(defn-memo get-lots-of-money 1.118 "Sell 0xFE cancel buttons to make a tremendous amount of money." 1.119 ([] (get-lots-of-money (corrupt-item-list))) 1.120 ([script] 1.121 (->> script 1.122 - (first-difference [] [:a] AF) 1.123 + (first-difference [] [:a] AF) ; talk to shopkeep 1.124 (repeat-until-different [] list-offset) 1.125 (set-cursor 1) 1.126 - (first-difference [] [:a] AF) 1.127 + select-menu-entry 1.128 (repeat-until-different [] list-offset) 1.129 - (first-difference [] [:a] AF) 1.130 + select-menu-entry 1.131 (set-quantity 0xFF 0xFE) 1.132 - (do-nothing 1) 1.133 - ))) 1.134 + (scroll-text) 1.135 + select-menu-entry))) 1.136 1.137 +(defn note [str script] 1.138 + (println str) script) 1.139 1.140 - 1.141 - 1.142 -(def buy-items do-nothing) 1.143 - 1.144 -(defn-memo get-burn-heals 1.145 - ([] (get-burn-heals 1.146 - (corrupt-item-list))) 1.147 +(defn-memo buy-bootstrapping-items 1.148 + "Buy items that will become part of the bootstrapping 1.149 + program." 1.150 + ([] (buy-bootstrapping-items (get-lots-of-money))) 1.151 ([script] 1.152 (->> script 1.153 - (menu [[:b] [:b]]) 1.154 - (menu [[:a]]) 1.155 - (do-nothing 100) 1.156 - (menu [↓ [:a]]) 1.157 - (do-nothing 100) 1.158 - (menu [[:a] ↓ [:a]]) 1.159 - (scroll-text) 1.160 - (menu [[:b][:b]]) 1.161 - (menu [[:a]]) 1.162 + close-menu 1.163 + select-menu-entry 1.164 + (purchase-item 1) ; buying a pokeball overflows 1.165 + ; the item-counter from 0xFF to 0x00 1.166 + ; repairing the item-list. 1.167 + (set-cursor 1) 1.168 + (purchase-item 1) ; these other items are here to 1.169 + ; protect the burn heals when the 1.170 + (set-cursor 2) ; item list is corrupted again. 1.171 + (purchase-item 1) 1.172 1.173 - (do-nothing 50) 1.174 - (buy-items [[0 1]]) 1.175 - (do-nothing 60) 1.176 - (menu [[:a]]) 1.177 - (scroll-text) 1.178 - 1.179 - (do-nothing 50) 1.180 - (buy-items [[0 1]]) 1.181 - (do-nothing 60) 1.182 - ;;(menu [[:a]]) 1.183 - ;;(scroll-text) 1.184 - 1.185 - ;;(do-nothing 300) 1.186 - ;;(menu [[:b] [:b]]) 1.187 - ;;(do-nothing 300) 1.188 + (set-cursor 3) 1.189 + (purchase-item 1) 1.190 1.191 - (buy-items [[0 1] 1.192 - [1 1] 1.193 - [1 1] 1.194 - [2 1] 1.195 - [3 1] 1.196 - [4 97]]) 1.197 - 1.198 - (do-nothing 10)))) 1.199 + (set-cursor 4) ; 95 burn-heals spells out the 1.200 + (purchase-item 96) ; return address to the pokemon 1.201 + ; kernel. 96 so that they can be 1.202 + ; deposited without causing a shift. 1.203 1.204 -(defn-memo corrupt-item-list-again 1.205 - ([] (corrupt-item-list-again (get-burn-heals))) 1.206 + close-menu ; stop talking to shopkeep 1.207 + (wait-until select-menu-entry) 1.208 + (play-moves [[:b]]) 1.209 + end-text))) 1.210 + 1.211 +(defn corrupt-item-list-again 1.212 + ([] (corrupt-item-list-again (buy-bootstrapping-items))) 1.213 ([script] 1.214 (->> script 1.215 - (do-nothing 10) 1.216 - (play-moves [[:b]]) 1.217 - (do-nothing 100) 1.218 - (play-moves [[:b]]) 1.219 - (do-nothing 40) 1.220 - (play-moves [[:b]]) 1.221 - (first-difference [:b] [:start :b] AF) 1.222 - (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon 1.223 - [:a] ↓ [:a] ; and corrupt the 1.224 - ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by 1.225 - ; switching it to 1.226 - ))) ; tenth place. 1.227 + 1.228 + activate-start-menu 1.229 + (set-cursor-relative 0) 1.230 + select-menu-entry 1.231 + 1.232 + ;; repair list-offset for pokemon-list 1.233 + (set-cursor-relative -1) 1.234 + 1.235 + 1.236 + (set-cursor 4) ; switching it to 1.237 + select-menu-entry ; tenth place. 1.238 + (set-cursor 1) 1.239 + select-menu-entry ; select "switch" on 5th 1.240 + 1.241 + (repeat-until-different [] list-offset) 1.242 + (set-cursor 9) ; goto 10th pokemon 1.243 + select-menu-entry ; do switch 1.244 + close-menu 1.245 + close-menu 1.246 + 1.247 + (do-nothing 1) 1.248 + ;;select-menu-entry 1.249 + ;; 1.250 + ;;(set-cursor 9) 1.251 + ;;select-menu-entry 1.252 + ;;close-menu 1.253 + 1.254 + ))) 1.255 + ;; (do-nothing 10) 1.256 + ;; (play-moves [[:b]]) 1.257 + ;; (do-nothing 100) 1.258 + ;; (play-moves [[:b]]) 1.259 + ;; (do-nothing 40) 1.260 + ;; (play-moves [[:b]]) 1.261 + ;; (first-difference [:b] [:start :b] AF) 1.262 + ;; (menu [[:a] ↑ ↑ ↑ ↑ ↑ 1.263 + ;; [:a] ↓ [:a] 1.264 + ;; ↓ ↓ ↓ ↓ ↓ [:a]]) 1.265 + ;; 1.266 + ;; ))) 1.267 1.268 (defn-memo viridian-store->viridian-poke-center 1.269 ([] (viridian-store->viridian-poke-center