 (defonce last-time nil)
 
 (defn moving-inc-c [vbl width limit]
-  [[:lt vbl (- limit width)]
+  [:and
+   [:lt vbl (- limit width)]
    [:geq vbl (list '- limit width [:d vbl])]])
 
 (defn moving-dec-c [vbl limit]
-  [[:gt vbl limit]
+  [:and
+   [:gt vbl limit]
    [:leq vbl (list '- limit [:d vbl])]])
 
 (defn moving-inc [vbl width other-ha]
-  [[:lt vbl [other-ha vbl] (- width)]
+  [:and
+   [:lt vbl [other-ha vbl] (- width)]
    [:geq vbl [other-ha vbl] (list '- [:d other-ha vbl] [:d vbl] width)]])
 
 (defn moving-dec [vbl width other-ha]
-  [[:gt vbl [other-ha vbl] width]
+  [:and
+   [:gt vbl [other-ha vbl] width]
    [:leq vbl [other-ha vbl] (list '+ [:d other-ha vbl] width (list '- [:d vbl]))]])
 
 (defn between-c [vbl min max]
-  [[:geq vbl min]
+  [:and
+   [:geq vbl min]
    [:lt vbl max]])
 
 (defn goomba [id x y speed state others walls]

        intervals))

(defn flatten-intervals [intervals]
  (reduce (fn [sofar interval]
            (if (simple? interval)
              (conj sofar interval)
              (into sofar (flatten-intervals interval))))
          []
          intervals))

(defn merge-overlapping [intervals]
  (let [intervals (flatten-intervals intervals)
        intervals (sort-intervals intervals)
        [last-i merged] (reduce (fn [[[amin amax :as a] merged] [bmin bmax :as b]]
                                  (if (intersection a b)
                                    [[amin (.max js/Math amax bmax)] merged]
                                    [[bmin bmax] (conj merged a)]))
                                [(first intervals) []]
                                (rest intervals))]
    (if (empty? intervals)
      []
      (conj merged last-i))))

(defn constrain-times [interval]
  (if (simple? interval)

               (mapcat (fn [[x y w h]]
                         ; left-transition means bumping into left side of wall
                         [(make-edge :left
                                     [:and
                                      (moving-inc-c :x 16 x)
                                      (between-c :y 0 100 #_(- y 16) #_(+ y h))]
                                     #{:required [:this id] [:other [:wall x y w h]]})])
                       walls)
               ; x + 16 < x2 && x + dx*frame + 16 >= x2 + dx2*frame
