 ;; Assumes this will always be called on a "source", and asserts correspondingly.
 (defn make-greedy-fire-action [s effect-var]
   (let [{:keys [name precond-map effect-map reward] :as factored-primitive}
-          (->> effect-var action-var (state/get-var s))
+        (->> effect-var action-var (state/get-var s))
         precond-vars (keys (dissoc precond-map effect-var))
         [free-pv unfree-pv] (util/separate #(state/get-var s (free-var %)) precond-vars)]
     (assert (every? #(contains? #{nil :frozen} (state/get-var s (action-var %))) precond-vars))
-    (assert (every? #(contains? #{nil :frozen} (state/get-var s (action-var %))) unfree-pv))
-    (doto (env-util/make-factored-primitive
-           [::GreedyFire name]
-           (into precond-map 
-                 (concat [[(action-var effect-var) factored-primitive]]
-                         (for [v free-pv]   [(free-var v)              true])
-                         (for [v unfree-pv] [(parent-var v effect-var) true])
-                         (for [v precond-vars] [(action-var v) (state/get-var s (action-var v))])))           
-           (into effect-map 
-                 (concat [[(action-var effect-var) nil]]
-                         (for [v unfree-pv] [(free-var v)              true])
-                         (for [v unfree-pv] [(parent-var v effect-var) false])
-                         (for [v precond-vars] [(action-var v) nil])))
-           0)
-      (-> (env/applicable? s) assert))))
-
-
-;; TODO: sloppy (var can be reserved for someone else, no action),
-;;       extra-sloppy (if it has the right value now, who cares about anything else?)
-
-;; TODO: should fail if I own parent, it has right value, but an action. (right now, we assert)...
-
-(comment ;; Version of above that allows "stealing"
- (defn make-greedy-fire-action [s effect-var]
-   (let [{:keys [name precond-map effect-map reward] :as factored-primitive}
-         (->> effect-var action-var (state/get-var s))
-         precond-vars (keys (dissoc precond-map effect-var))
-         [free-pv unfree-pv] (util/separate #(state/get-var s (free-var %)) precond-vars)
-         [reserved-pv external-pv] (util/separate #(state/get-var s (parent-var % effect-var))
-                                                  unfree-pv)]
-     (when (state/state-matches-map? s precond-map)
-       (env-util/make-factored-primitive
-        [::GreedyFire name]
-        (into precond-map 
-              (concat [[(action-var effect-var) factored-primitive]]
-                      (for [v free-pv]   [(free-var v)              true])
-                      (for [v reserved-pv] [(parent-var v effect-var) true])
-                      (for [v external-pv] [(free-var v) false])
-                      (for [v external-pv] [(parent-var v effect-var) false])))
-        (into effect-map 
-              (concat [[(action-var effect-var) nil]]
-                      (for [v reserved-pv] [(free-var v)              true])
-                      (for [v reserved-pv] [(parent-var v effect-var) false])))
-        0)))))
+    (env-util/make-factored-primitive
+     [::Fire name]
+     (into precond-map 
+           (concat [[(action-var effect-var) factored-primitive]]
+                   (for [v free-pv]   [(free-var v)              true])
+                   (for [v unfree-pv] [(parent-var v effect-var) true])
+                   (for [v precond-vars] [(action-var v) (state/get-var s (action-var v))])))           
+     (into effect-map 
+           (concat [[(action-var effect-var) nil]]
+                   (for [v unfree-pv] [(free-var v)              true])
+                   (for [v unfree-pv] [(parent-var v effect-var) false])
+                   (for [v precond-vars] [(action-var v) nil])))
+     0)))
+
+(defn make-sloppy-fire-action [s effect-var]
+  (let [{:keys [name precond-map effect-map reward] :as factored-primitive}
+        (->> effect-var action-var (state/get-var s))
+        precond-vars (keys (dissoc precond-map effect-var))
+        [free-pv unfree-pv] (util/separate #(state/get-var s (free-var %)) precond-vars)
+        [reserved-pv external-pv] (util/separate #(state/get-var s (parent-var % effect-var))
+                                                 unfree-pv)]
+    (assert (every? #(contains? #{nil :frozen} (state/get-var s (action-var %))) reserved-pv))
+    (env-util/make-factored-primitive
+     [::Fire name]
+     (into precond-map 
+           (concat [[(action-var effect-var) factored-primitive]]
+                   (for [v free-pv]   [(free-var v)              true])
+                   (for [v reserved-pv] [(parent-var v effect-var) true])
+                   (for [v external-pv] [(free-var v) false])
+                   (for [v external-pv] [(parent-var v effect-var) false])))
+     (into effect-map 
+           (concat [[(action-var effect-var) nil]]
+                   (for [v reserved-pv] [(free-var v)              true])
+                   (for [v reserved-pv] [(parent-var v effect-var) false])
+                   (for [v reserved-pv] [(action-var v) nil])))
+     0)))
+
+(defn make-fire-action-type [s edge-rule effect-var]
+  (doto (case edge-rule
+          :naive (make-fire-action (->> effect-var action-var (state/get-var s)))
+          :greedy (make-greedy-fire-action s effect-var)
+          (:sloppy :extra-sloppy) (make-sloppy-fire-action s effect-var))
+    (-> (env/applicable? s) assert)))
 
 
 

    (3)(b) sloppy:       If (action-var c) has precondition on p, value mismatch or action on p and reserved by o!=c, o --> c
    (3)(c) extra-sloppy: If (action-var c) has precondition on p, value mismatch and reserved by o!=c, o --> c"   
  [s child-map rule]
  (assert (contains? #{:naive :greedy :sloppy :extra-sloppy} rule))
  (assert (contains? #{:greedy} rule))  
  (apply concat
         (for [v (cons sas/goal-var-name (keys child-map))]
           (let [a (state/get-var s (action-var v))]

                          (ancestor-map pv)))]
    (not-every? live-set
                (concat (map second extra-edges)
                        (for [p (keys child-map)
                              :let [a (state/get-var s (action-var p))]
                              :when (and a (not (= a :frozen)))]
                          p)
                        (for [[p cs] child-map, c cs
                              :when (state/get-var s (parent-var p c))]
                          c)))))


;; TODO: remove redundant dead-end check ?
(defn possible-activation-actions  
   "Return a list of possible activation actions for var v possible in state s.
   To be possible parent, must be supported from below. "
   [s ancestor-map child-map v]
;   (activation-actions child-map v) #_   
   (for [c (child-map v) :when (not (or (dead-end? s ancestor-map child-map [[ v c]])))]
     (make-set-parent-var-action v c)))
;   (or (deadlocked? s child-map [[v c]]))

