Mercurial > vba-clojure
changeset 275:68f4e87c8f51
added script to automatically buy any combination of items from a store's inventory.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 27 Mar 2012 12:36:48 -0500 |
parents | 210b465e4720 |
children | 18336ab5d6ea |
files | clojure/com/aurellem/run/bootstrap_0.clj |
diffstat | 1 files changed, 121 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 11:30:58 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 12:36:48 2012 -0500 1.3 @@ -412,32 +412,140 @@ 1.4 ([script] 1.5 (->> script 1.6 (walk [↑ ↑ ← ←])))) 1.7 - 1.8 - 1.9 -(defn-memo buy-initial-objects 1.10 - ([] (buy-initial-objects 1.11 + 1.12 +(defn buy-item 1.13 + "Assumes that the main item-screen is up, and buys 1.14 + quantity of the nth item in the list, assuming that you 1.15 + have enough money." 1.16 + [n quantity script] 1.17 + (if (= 0 quantity) 1.18 + script 1.19 + (let [after-initial-pause 1.20 + (do-nothing 20 script) 1.21 + move-to-item 1.22 + (reduce (fn [script _] 1.23 + (->> script 1.24 + (play-moves [[:d]]) 1.25 + (do-nothing 3))) 1.26 + after-initial-pause 1.27 + (range n)) 1.28 + select-item 1.29 + (play-moves [[:a]] move-to-item) 1.30 + request-items 1.31 + (reduce (fn [script _] 1.32 + (->> script 1.33 + (play-moves [[:u]]) 1.34 + (do-nothing 1))) 1.35 + select-item 1.36 + (range (dec quantity))) 1.37 + buy-items 1.38 + (->> request-items 1.39 + (do-nothing 3) 1.40 + (play-moves [[:a]]) 1.41 + (scroll-text) 1.42 + (scroll-text) 1.43 + (play-moves [[:a]]) 1.44 + (scroll-text))] 1.45 + buy-items))) 1.46 + 1.47 + 1.48 +(defn buy-items 1.49 + "Given a list of [item-no quantity], buys the quantity 1.50 + from the shop's list. Assumes that the item list is 1.51 + already up." 1.52 + [item-pairs script] 1.53 + (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs) 1.54 + initial-purchase 1.55 + (->> script 1.56 + (buy-item 0 (item-lookup 0)) 1.57 + (buy-item 1 (item-lookup 1)) 1.58 + (buy-item 2 (item-lookup 2)))] 1.59 + (cond 1.60 + (and 1.61 + (not= 0 (item-lookup 3)) 1.62 + (not= 0 (item-lookup 4))) 1.63 + (->> initial-purchase 1.64 + (do-nothing 20) 1.65 + (play-moves [[:d]]) 1.66 + (do-nothing 3) 1.67 + (play-moves [[:d]]) 1.68 + (do-nothing 3) 1.69 + (play-moves [[:d]]) 1.70 + (do-nothing 10) 1.71 + (buy-item 0 (item-lookup 3)) 1.72 + (do-nothing 20) 1.73 + (play-moves [[:d]]) 1.74 + (do-nothing 3) 1.75 + (play-moves [[:d]]) 1.76 + (do-nothing 3) 1.77 + (play-moves [[:d]]) 1.78 + (do-nothing 10) 1.79 + (buy-item 0 (item-lookup 4))) 1.80 + (and (= 0 (item-lookup 3)) 1.81 + (not= 0 (item-lookup 4))) 1.82 + (->> initial-purchase 1.83 + (do-nothing 20) 1.84 + (play-moves [[:d]]) 1.85 + (do-nothing 3) 1.86 + (play-moves [[:d]]) 1.87 + (do-nothing 3) 1.88 + (play-moves [[:d]]) 1.89 + (do-nothing 10) 1.90 + (play-moves [[:d]]) 1.91 + (do-nothing 10) 1.92 + (buy-item 0 (item-lookup 4))) 1.93 + (and (not= 0 (item-lookup 3)) 1.94 + (= 0 (item-lookup 4))) 1.95 + (->> initial-purchase 1.96 + (do-nothing 20) 1.97 + (play-moves [[:d]]) 1.98 + (do-nothing 3) 1.99 + (play-moves [[:d]]) 1.100 + (do-nothing 3) 1.101 + (play-moves [[:d]]) 1.102 + (do-nothing 10) 1.103 + (buy-item 0 (item-lookup 3)))))) 1.104 + 1.105 + 1.106 +(defn test-buy-items 1.107 + ([] (test-buy-itemss 1.108 (walk-to-counter))) 1.109 ([script] 1.110 - (->> script 1.111 - ;(do-nothing 200) 1.112 + (->> [(first script) (set-money (second script) 1.113 + 999999)] 1.114 (play-moves 1.115 [[] [:a] []]) 1.116 (scroll-text) 1.117 (do-nothing 100) 1.118 (play-moves [[:a]]) 1.119 (do-nothing 100) 1.120 - (play-moves [[:a]]) 1.121 - (do-nothing 100) 1.122 - (play-moves [[:a]]) 1.123 - (do-nothing 100) 1.124 + (buy-items 1.125 + [[0 1] 1.126 + [1 15] 1.127 + [2 1] 1.128 + [3 20] 1.129 + [4 95] 1.130 + ])))) 1.131 + 1.132 +(defn-memo buy-initial-items 1.133 + ([] (buy-initial-items 1.134 + (walk-to-counter))) 1.135 + ([script] 1.136 + (->> script 1.137 + (play-moves 1.138 + [[] [:a] []]) 1.139 (scroll-text) 1.140 (do-nothing 100) 1.141 (play-moves [[:a]]) 1.142 (do-nothing 100) 1.143 - (play-moves [[:a]]) 1.144 - (do-nothing 100)))) 1.145 + (buy-items 1.146 + [[0 1] 1.147 + [1 1] 1.148 + [2 1] 1.149 + [3 1] 1.150 + [4 1] 1.151 + ])))) 1.152 1.153 - 1.154 1.155 1.156 1.157 \ No newline at end of file