changeset 85:3f4fdd270059

more progress with the title
author Robert McIntyre <rlm@mit.edu>
date Sat, 10 Mar 2012 00:32:11 -0600
parents 26f002f2868c
children 9864032ef3c8
files clojure/com/aurellem/gb_funs.clj clojure/com/aurellem/title2.clj org/todo.org
diffstat 3 files changed, 65 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb_funs.clj	Fri Mar 09 23:28:07 2012 -0600
     1.2 +++ b/clojure/com/aurellem/gb_funs.clj	Sat Mar 10 00:32:11 2012 -0600
     1.3 @@ -90,6 +90,7 @@
     1.4  
     1.5  
     1.6  (defn set-state! [^SaveState state]
     1.7 +  (assert (:data state) "Not a valid state!")
     1.8    (if (not @on?) (restart!))
     1.9    (if (not= @current-state state)
    1.10      (Gb/loadState (:data state)))
    1.11 @@ -113,10 +114,17 @@
    1.12  
    1.13  
    1.14  (defn play
    1.15 -  ([state n]
    1.16 +  ([^SaveState state n]
    1.17       (reduce (fn [s _] (step s)) state (range n)))
    1.18 -  ([state]
    1.19 -     (dorun (iterate step state))))
    1.20 +  ([n]
    1.21 +     (play @current-state n)))
    1.22 +
    1.23 +(defn play-moves
    1.24 +  ([state moves]
    1.25 +     
    1.26 +  ([moves]
    1.27 +     (dorun (map (fn [move] (step @current-state move)) moves))))
    1.28 +  
    1.29  ;;;;;;;;;;;
    1.30  
    1.31  
    1.32 @@ -153,6 +161,7 @@
    1.33  (defn BC [state]
    1.34    (nth (registers state) 3))
    1.35  
    1.36 -        
    1.37 +(defn DE [state]
    1.38 +  (nth (registers state) 4))
    1.39              
    1.40    
    1.41 \ No newline at end of file
     2.1 --- a/clojure/com/aurellem/title2.clj	Fri Mar 09 23:28:07 2012 -0600
     2.2 +++ b/clojure/com/aurellem/title2.clj	Sat Mar 10 00:32:11 2012 -0600
     2.3 @@ -12,36 +12,60 @@
     2.4          [(conj actions alt) alt-branch]
     2.5          (recur base-branch (conj actions base))))))
     2.6  
     2.7 +(defn advance
     2.8 +  ([base alt summary [commands state]]
     2.9 +     (let [[c s] (first-difference base alt summary state)]
    2.10 +       [(concat commands c) s]))
    2.11 +  ([base alt [commands state]]
    2.12 +     (advance base alt AF [commands state]))
    2.13 +  ([alt [commands state]]
    2.14 +     (advance [] alt [commands state])))
    2.15 +
    2.16 +(def scroll-text (partial advance [:b] [:a :b]))
    2.17 +
    2.18  (defn title []
    2.19 -  (let [[c-1 s-1] (first-difference [] [:a] AF (root))
    2.20 -        [c-2 s-2] (first-difference [] [:start] AF s-1)
    2.21 -        [c-3 s-3] (first-difference [] [:a] AF s-2)
    2.22 -        [c-4 s-4] (first-difference [] [:start] AF s-3)]
    2.23 -    [(concat c-1 c-2 c-3 c-3 c-4) s-4]))
    2.24 +  (->> [[] (root)]
    2.25 +       (advance [] [:a])
    2.26 +       (advance [] [:start])
    2.27 +       (advance [] [:a])
    2.28 +       (advance [] [:start])))
    2.29  
    2.30 -(def menu-end (second (title)))
    2.31 -
    2.32 -(defn scroll-text [[commands state]]
    2.33 -  (let [[c s] (first-difference [:b] [:a :b] AF state)]
    2.34 -    [(concat commands c) s]))
    2.35 +(def title-end (second (title)))
    2.36  
    2.37  (defn oak []
    2.38 -  (-> [[] menu-end]
    2.39 -      scroll-text
    2.40 -      scroll-text
    2.41 -      scroll-text
    2.42 -      scroll-text
    2.43 -      scroll-text
    2.44 -      scroll-text
    2.45 -      scroll-text
    2.46 -      scroll-text
    2.47 -      scroll-text
    2.48 -      scroll-text
    2.49 -      scroll-text
    2.50 -      scroll-text
    2.51 -      scroll-text))
    2.52 +  (->> [[] title-end]
    2.53 +       scroll-text
    2.54 +       scroll-text
    2.55 +       scroll-text
    2.56 +       scroll-text
    2.57 +       scroll-text
    2.58 +       scroll-text
    2.59 +       scroll-text
    2.60 +       scroll-text
    2.61 +       scroll-text
    2.62 +       scroll-text
    2.63 +       scroll-text
    2.64 +       scroll-text
    2.65 +       scroll-text
    2.66 +       (advance [] [:a])))
    2.67 +
    2.68 +;; looks like it might need a monad here if this pattern continues
    2.69  
    2.70  (def oak-end (second (oak)))
    2.71 -  
    2.72 +           
    2.73 +(defn name-entry []
    2.74 +  (->> [[] oak-end]
    2.75 +       (advance [] [:r] DE)
    2.76 +       ((fn [[moves state]]
    2.77 +          (play-moves
    2.78 +           state
    2.79 +            [[]
    2.80 +             [:r] [] [:r] [] [:r] [] [:r] []
    2.81 +             [:r] [] [:r] [] [:r] [] [:d] [:a]  
    2.82 +             [:l] [] [:l] [] [:l] [] [:l] []
    2.83 +             [:l] [] [:l] [:a] [] [:r] [:a]
    2.84 +             [:r] [] [:r] [] [:r] [] [:r] []
    2.85 +             [:r] [] [:d] [] [:d] [] [:d] [:a]
    2.86 +             ])))))
    2.87 +          
    2.88  
    2.89 -;; looks like it might need a monad here if this pattern continues
    2.90 \ No newline at end of file
     3.1 --- a/org/todo.org	Fri Mar 09 23:28:07 2012 -0600
     3.2 +++ b/org/todo.org	Sat Mar 10 00:32:11 2012 -0600
     3.3 @@ -15,8 +15,8 @@
     3.4   - [X] send button presses to the GB
     3.5  
     3.6  * high level
     3.7 - - [ ] write vbm files from clojure
     3.8 - - [ ] remove battery backup files
     3.9 + - [X] write vbm files from clojure
    3.10 + - [X] remove battery backup files
    3.11  
    3.12  
    3.13