Mercurial > vba-clojure
view clojure/com/aurellem/title.clj @ 88:65c2854c5875
can now save moves and states and am ready to continue past the title
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Mar 2012 15:36:26 -0600 |
parents | e8855121f413 |
children | 2f478abe57d0 |
line wrap: on
line source
1 (ns com.aurellem.title2 (:use (com.aurellem gb-driver vbm)))4 (defn first-difference [base alt summary root]5 (loop [branch-point root6 actions []]7 (let [base-branch (step branch-point base)8 base-val (summary base-branch)9 alt-branch (step branch-point alt)10 alt-val (summary alt-branch)]11 (if (not= base-val alt-val)12 [(conj actions alt) alt-branch]13 (recur base-branch (conj actions base))))))15 (defn advance16 ([base alt summary [commands state]]17 (let [[c s] (first-difference base alt summary state)]18 [(concat commands c) s]))19 ([base alt [commands state]]20 (advance base alt AF [commands state]))21 ([alt [commands state]]22 (advance [] alt [commands state])))24 (def scroll-text (partial advance [:b] [:a :b]))26 (defn start [] [[] (root)])28 (defn-memo title []29 (->> (start)30 (advance [] [:a])31 (advance [] [:start])32 (advance [] [:a])33 (advance [] [:start])))35 (defn-memo oak []36 (->> (title)37 scroll-text38 scroll-text39 scroll-text40 scroll-text41 scroll-text42 scroll-text43 scroll-text44 scroll-text45 scroll-text46 scroll-text47 scroll-text48 scroll-text49 scroll-text50 (advance [] [:a])))52 (defn-memo name-entry []53 (->> (oak)54 (advance [] [:r] DE)55 (play-moves56 [[]57 [:r] [] [:r] [] [:r] [] [:r] []58 [:r] [] [:r] [] [:r] [] [:d] [:a]59 [:l] [] [:l] [] [:l] [] [:l] []60 [:l] [] [:l] [:a] [] [:r] [:a]61 [:r] [] [:r] [] [:r] [] [:r] []62 [:r] [] [:d] [] [:d] [] [:d] [:a]63 ])))65 (defn-memo rival-name-entry []66 (->> (name-entry)67 scroll-text68 scroll-text69 scroll-text70 scroll-text71 scroll-text72 (advance [] [:d])73 (advance [] [:d])74 (advance [] [:a])))76 (defn-memo finish-title []77 (->> (rival-name-entry)78 scroll-text79 scroll-text80 scroll-text81 scroll-text82 scroll-text83 scroll-text84 scroll-text))86 (defn write-intro! []87 (let [[moves state] (finish-title)]88 [(write-moves! moves) (write-state! state)]))90 (def title-frames 2323)92 (defn intro []93 [(read-moves title-frames)94 (read-state title-frames)])96 (defn test-intro []97 (play-vbm (moves->filename title-frames)))101 ;; TODO might be able to glue these together more elegantly with monads