# HG changeset patch # User Robert McIntyre # Date 1332869808 18000 # Node ID 68f4e87c8f51c7664616f8085e3f58d7e1b2c256 # Parent 210b465e4720d6f2cc8fa9720613016d0f6b641d added script to automatically buy any combination of items from a store's inventory. diff -r 210b465e4720 -r 68f4e87c8f51 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 11:30:58 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 12:36:48 2012 -0500 @@ -412,32 +412,140 @@ ([script] (->> script (walk [↑ ↑ ← ←])))) - - -(defn-memo buy-initial-objects - ([] (buy-initial-objects + +(defn buy-item + "Assumes that the main item-screen is up, and buys + quantity of the nth item in the list, assuming that you + have enough money." + [n quantity script] + (if (= 0 quantity) + script + (let [after-initial-pause + (do-nothing 20 script) + move-to-item + (reduce (fn [script _] + (->> script + (play-moves [[:d]]) + (do-nothing 3))) + after-initial-pause + (range n)) + select-item + (play-moves [[:a]] move-to-item) + request-items + (reduce (fn [script _] + (->> script + (play-moves [[:u]]) + (do-nothing 1))) + select-item + (range (dec quantity))) + buy-items + (->> request-items + (do-nothing 3) + (play-moves [[:a]]) + (scroll-text) + (scroll-text) + (play-moves [[:a]]) + (scroll-text))] + buy-items))) + + +(defn buy-items + "Given a list of [item-no quantity], buys the quantity + from the shop's list. Assumes that the item list is + already up." + [item-pairs script] + (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs) + initial-purchase + (->> script + (buy-item 0 (item-lookup 0)) + (buy-item 1 (item-lookup 1)) + (buy-item 2 (item-lookup 2)))] + (cond + (and + (not= 0 (item-lookup 3)) + (not= 0 (item-lookup 4))) + (->> initial-purchase + (do-nothing 20) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 10) + (buy-item 0 (item-lookup 3)) + (do-nothing 20) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 10) + (buy-item 0 (item-lookup 4))) + (and (= 0 (item-lookup 3)) + (not= 0 (item-lookup 4))) + (->> initial-purchase + (do-nothing 20) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 10) + (play-moves [[:d]]) + (do-nothing 10) + (buy-item 0 (item-lookup 4))) + (and (not= 0 (item-lookup 3)) + (= 0 (item-lookup 4))) + (->> initial-purchase + (do-nothing 20) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 3) + (play-moves [[:d]]) + (do-nothing 10) + (buy-item 0 (item-lookup 3)))))) + + +(defn test-buy-items + ([] (test-buy-itemss (walk-to-counter))) ([script] - (->> script - ;(do-nothing 200) + (->> [(first script) (set-money (second script) + 999999)] (play-moves [[] [:a] []]) (scroll-text) (do-nothing 100) (play-moves [[:a]]) (do-nothing 100) - (play-moves [[:a]]) - (do-nothing 100) - (play-moves [[:a]]) - (do-nothing 100) + (buy-items + [[0 1] + [1 15] + [2 1] + [3 20] + [4 95] + ])))) + +(defn-memo buy-initial-items + ([] (buy-initial-items + (walk-to-counter))) + ([script] + (->> script + (play-moves + [[] [:a] []]) (scroll-text) (do-nothing 100) (play-moves [[:a]]) (do-nothing 100) - (play-moves [[:a]]) - (do-nothing 100)))) + (buy-items + [[0 1] + [1 1] + [2 1] + [3 1] + [4 1] + ])))) - \ No newline at end of file