comparison clojure/com/aurellem/run/bootstrap_0.clj @ 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 710bfbb1e048
comparison
equal deleted inserted replaced
274:210b465e4720 275:68f4e87c8f51
410 ([] (walk-to-counter 410 ([] (walk-to-counter
411 (return-to-viridian-mart))) 411 (return-to-viridian-mart)))
412 ([script] 412 ([script]
413 (->> script 413 (->> script
414 (walk [↑ ↑ ← ←])))) 414 (walk [↑ ↑ ← ←]))))
415 415
416 416 (defn buy-item
417 (defn-memo buy-initial-objects 417 "Assumes that the main item-screen is up, and buys
418 ([] (buy-initial-objects 418 quantity of the nth item in the list, assuming that you
419 have enough money."
420 [n quantity script]
421 (if (= 0 quantity)
422 script
423 (let [after-initial-pause
424 (do-nothing 20 script)
425 move-to-item
426 (reduce (fn [script _]
427 (->> script
428 (play-moves [[:d]])
429 (do-nothing 3)))
430 after-initial-pause
431 (range n))
432 select-item
433 (play-moves [[:a]] move-to-item)
434 request-items
435 (reduce (fn [script _]
436 (->> script
437 (play-moves [[:u]])
438 (do-nothing 1)))
439 select-item
440 (range (dec quantity)))
441 buy-items
442 (->> request-items
443 (do-nothing 3)
444 (play-moves [[:a]])
445 (scroll-text)
446 (scroll-text)
447 (play-moves [[:a]])
448 (scroll-text))]
449 buy-items)))
450
451
452 (defn buy-items
453 "Given a list of [item-no quantity], buys the quantity
454 from the shop's list. Assumes that the item list is
455 already up."
456 [item-pairs script]
457 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)
458 initial-purchase
459 (->> script
460 (buy-item 0 (item-lookup 0))
461 (buy-item 1 (item-lookup 1))
462 (buy-item 2 (item-lookup 2)))]
463 (cond
464 (and
465 (not= 0 (item-lookup 3))
466 (not= 0 (item-lookup 4)))
467 (->> initial-purchase
468 (do-nothing 20)
469 (play-moves [[:d]])
470 (do-nothing 3)
471 (play-moves [[:d]])
472 (do-nothing 3)
473 (play-moves [[:d]])
474 (do-nothing 10)
475 (buy-item 0 (item-lookup 3))
476 (do-nothing 20)
477 (play-moves [[:d]])
478 (do-nothing 3)
479 (play-moves [[:d]])
480 (do-nothing 3)
481 (play-moves [[:d]])
482 (do-nothing 10)
483 (buy-item 0 (item-lookup 4)))
484 (and (= 0 (item-lookup 3))
485 (not= 0 (item-lookup 4)))
486 (->> initial-purchase
487 (do-nothing 20)
488 (play-moves [[:d]])
489 (do-nothing 3)
490 (play-moves [[:d]])
491 (do-nothing 3)
492 (play-moves [[:d]])
493 (do-nothing 10)
494 (play-moves [[:d]])
495 (do-nothing 10)
496 (buy-item 0 (item-lookup 4)))
497 (and (not= 0 (item-lookup 3))
498 (= 0 (item-lookup 4)))
499 (->> initial-purchase
500 (do-nothing 20)
501 (play-moves [[:d]])
502 (do-nothing 3)
503 (play-moves [[:d]])
504 (do-nothing 3)
505 (play-moves [[:d]])
506 (do-nothing 10)
507 (buy-item 0 (item-lookup 3))))))
508
509
510 (defn test-buy-items
511 ([] (test-buy-itemss
419 (walk-to-counter))) 512 (walk-to-counter)))
420 ([script] 513 ([script]
421 (->> script 514 (->> [(first script) (set-money (second script)
422 ;(do-nothing 200) 515 999999)]
423 (play-moves 516 (play-moves
424 [[] [:a] []]) 517 [[] [:a] []])
425 (scroll-text) 518 (scroll-text)
426 (do-nothing 100) 519 (do-nothing 100)
427 (play-moves [[:a]]) 520 (play-moves [[:a]])
428 (do-nothing 100) 521 (do-nothing 100)
429 (play-moves [[:a]]) 522 (buy-items
523 [[0 1]
524 [1 15]
525 [2 1]
526 [3 20]
527 [4 95]
528 ]))))
529
530 (defn-memo buy-initial-items
531 ([] (buy-initial-items
532 (walk-to-counter)))
533 ([script]
534 (->> script
535 (play-moves
536 [[] [:a] []])
537 (scroll-text)
430 (do-nothing 100) 538 (do-nothing 100)
431 (play-moves [[:a]]) 539 (play-moves [[:a]])
432 (do-nothing 100) 540 (do-nothing 100)
433 (scroll-text) 541 (buy-items
434 (do-nothing 100) 542 [[0 1]
435 (play-moves [[:a]]) 543 [1 1]
436 (do-nothing 100) 544 [2 1]
437 (play-moves [[:a]]) 545 [3 1]
438 (do-nothing 100)))) 546 [4 1]
439 547 ]))))
440 548
441 549
442 550
443 551