Mercurial > vba-clojure
view clojure/com/aurellem/cruft/title.clj @ 104:d2e00ea31508
checking in continue!, which let's the GB run for an unlimited time.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 13 Mar 2012 00:03:02 -0500 |
parents | e8855121f413 |
children |
line wrap: on
line source
1 (ns com.aurellem.title2 (:use (com.aurellem gb-driver vbm)))4 (defn delayed-key5 ([key delay total]6 (concat (repeat delay []) [key] (repeat (- total delay 1) [])))7 ([key total]8 (delayed-key key (dec total) total)))10 (defn no-action [length]11 (repeat length []))13 (defn start-summary []14 (nth (registers) 2))16 (defn common-initial-elements [baseline moves]17 (loop [common 0 b baseline m moves]18 (if (empty? m) common19 (if (= (first b) (first m))20 (recur (inc common) (rest b) (rest m))21 common))))23 (defn earliest-press24 [start-frame25 end-frame26 key27 summary-fn]28 (let [action-length (- end-frame start-frame)29 baseline (no-action action-length)]30 (print "establishing baseline...")31 (play-moves start-frame baseline)32 (let [bad-value (summary-fn)]33 (println bad-value)34 (loop [n 0]35 (let [moves (delayed-key key n action-length)36 header-length37 (common-initial-elements moves baseline)]38 (print "length" (inc n) "...")39 (without-saves40 (play-moves41 (+ start-frame header-length)42 (drop header-length moves)))43 (let [result (summary-fn)]44 (println result)45 (if (not= result bad-value)46 (let [keys (delayed-key key (inc n))]47 (play-moves start-frame keys)48 keys)49 (recur (inc n)))))))))52 (defn search-first53 [start-frame54 baseline55 gen-move-fn56 summary-fn]57 (print "establishing baseline...")58 (play-moves start-frame baseline)59 (let [bad-value (summary-fn)]60 (println bad-value)61 (loop [n 0]62 (let [trial-moves (gen-move-fn n)63 header-length64 (common-initial-elements trial-moves baseline)]65 (print "length" (inc n) "...")66 (without-saves67 (play-moves68 (+ start-frame header-length)69 (drop header-length trial-moves)))70 (let [result (summary-fn)]71 (println result)72 (if (not= result bad-value)73 (let [keys (take (inc n) trial-moves)]74 (play-moves start-frame keys)75 keys)76 (recur (inc n))))))))78 (defn title-search79 [start-frame80 end-frame81 key82 summary-fn]83 (let [action-length (- end-frame start-frame)]84 (search-first85 start-frame86 (no-action action-length)87 (fn [n] (delayed-key key n action-length))88 summary-fn)))90 (defn gen-title []91 (let [start0 (no-action 300)]92 (play-moves 0 start0)93 (let [start->first-press94 (title-search (frame) (+ 50 (frame)) [:a] start-summary)95 first-press->second-press96 (title-search (frame) (+ 100 (frame)) [:start] start-summary)97 second-press->third-press98 (title-search (frame) (+ 151 (frame)) [:a] start-summary)99 new-game100 (title-search (frame) (+ 151 (frame)) [:a] start-summary)]101 (concat102 start0103 start->first-press104 first-press->second-press105 second-press->third-press106 new-game))))108 (def title109 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []110 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []111 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []112 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []113 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []114 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []115 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []116 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []117 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []118 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []119 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []120 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []121 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []122 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []123 [] [] [] [] [] [] [] [] [] [] [] [] [] [ :a] [] [] [] [] [] [] []124 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []125 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []126 [] [] [] [] [] [] [] [] [] [:start] [] [] [] [] [] [] [] [] [] []127 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []128 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []129 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []130 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []131 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []132 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []133 [] [] [] [] [ :a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []134 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []135 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []136 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []137 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []138 [] [] [] [] [] [ :a]])141 (require '(clojure [zip :as zip]))