# HG changeset patch # User Robert McIntyre # Date 1332869868 18000 # Node ID 18336ab5d6ea9f0c2c9e072fd39c4ef2734a35b0 # Parent 68f4e87c8f51c7664616f8085e3f58d7e1b2c256# Parent 69184558fcf366375a5efd5ba235d5021b8932e1 merge. diff -r 69184558fcf3 -r 18336ab5d6ea clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 02:05:16 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Tue Mar 27 12:37:48 2012 -0500 @@ -18,8 +18,7 @@ scroll-text scroll-text scroll-text - scroll-text - ))) + scroll-text))) (defn-memo name-rival-bootstrap ([] (name-rival-bootstrap (to-rival-name))) @@ -397,7 +396,6 @@ (end-text) (scroll-text 7) (end-text) - (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])))) (defn-memo return-to-viridian-mart @@ -406,4 +404,148 @@ ([script] (->> script oaks-lab->pallet-town-edge - (pallet-edge->viridian-mart false)))) \ No newline at end of file + (pallet-edge->viridian-mart false)))) + +(defn-memo walk-to-counter + ([] (walk-to-counter + (return-to-viridian-mart))) + ([script] + (->> script + (walk [↑ ↑ ← ←])))) + +(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] + (->> [(first script) (set-money (second script) + 999999)] + (play-moves + [[] [:a] []]) + (scroll-text) + (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) + (buy-items + [[0 1] + [1 1] + [2 1] + [3 1] + [4 1] + ])))) + + + + \ No newline at end of file