Executing flows now works.
This commit is contained in:
parent
5ef93ef4df
commit
f60fdb944b
|
@ -93,7 +93,7 @@
|
||||||
"Return a world like this `world`, except with the quantity of the property
|
"Return a world like this `world`, except with the quantity of the property
|
||||||
described in this `flow` object transferred from the source of that flow
|
described in this `flow` object transferred from the source of that flow
|
||||||
to its destination."
|
to its destination."
|
||||||
[flow world]
|
[world flow]
|
||||||
(try
|
(try
|
||||||
(let [source (get-cell world (-> flow :source :x) (-> flow :source :y))
|
(let [source (get-cell world (-> flow :source :x) (-> flow :source :y))
|
||||||
dest (get-cell world (-> flow :destination :x) (-> flow :destination :y))
|
dest (get-cell world (-> flow :destination :x) (-> flow :destination :y))
|
||||||
|
@ -103,11 +103,11 @@
|
||||||
d' (assoc dest p (+ (get-num dest p) q))]
|
d' (assoc dest p (+ (get-num dest p) q))]
|
||||||
(merge-cell (merge-cell world s') d'))
|
(merge-cell (merge-cell world s') d'))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(warn "Failed to execute flow %s: %s" flow (.getMessage e))
|
(warn (format "Failed to execute flow %s: %s" flow (.getMessage e)))
|
||||||
;; return the world unmodified.
|
;; return the world unmodified.
|
||||||
world)))
|
world)))
|
||||||
|
|
||||||
(defn execute-flows
|
(defn execute-flows
|
||||||
"Return a world like this `world`, but with each of these flows executed."
|
"Return a world like this `world`, but with each of these flows executed."
|
||||||
[flows world]
|
[world flows]
|
||||||
(reduce execute world (filter #(flow? % world) flows)))
|
(reduce execute world (filter #(flow? % world) flows)))
|
|
@ -37,7 +37,7 @@
|
||||||
:property :q
|
:property :q
|
||||||
:quantity 2.4}]
|
:quantity 2.4}]
|
||||||
(is (flow? valid world))
|
(is (flow? valid world))
|
||||||
(let [transferred (execute valid world')
|
(let [transferred (execute world' valid)
|
||||||
source-q (:q (get-cell transferred 0 0))
|
source-q (:q (get-cell transferred 0 0))
|
||||||
dest-q (:q (get-cell transferred 1 1))]
|
dest-q (:q (get-cell transferred 1 1))]
|
||||||
(is (= source-q 2.9))
|
(is (= source-q 2.9))
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
:destination {:x 0 :y 1}
|
:destination {:x 0 :y 1}
|
||||||
:property :q
|
:property :q
|
||||||
:quantity 1}
|
:quantity 1}
|
||||||
transferred (execute-flows (list valid valid2) world')
|
transferred (execute-flows world' (list valid valid2))
|
||||||
source-q (:q (get-cell transferred 0 0))
|
source-q (:q (get-cell transferred 0 0))
|
||||||
inter-q (:q (get-cell transferred 1 1))
|
inter-q (:q (get-cell transferred 1 1))
|
||||||
dest-q (:q (get-cell transferred 0 1))]
|
dest-q (:q (get-cell transferred 0 1))]
|
||||||
|
|
Loading…
Reference in a new issue