Executing flows now works.

This commit is contained in:
Simon Brooke 2023-07-10 08:15:09 +01:00
parent 5ef93ef4df
commit f60fdb944b
2 changed files with 5 additions and 5 deletions

View file

@ -93,7 +93,7 @@
"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
to its destination."
[flow world]
[world flow]
(try
(let [source (get-cell world (-> flow :source :x) (-> flow :source :y))
dest (get-cell world (-> flow :destination :x) (-> flow :destination :y))
@ -103,11 +103,11 @@
d' (assoc dest p (+ (get-num dest p) q))]
(merge-cell (merge-cell world s') d'))
(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.
world)))
(defn execute-flows
"Return a world like this `world`, but with each of these flows executed."
[flows world]
[world flows]
(reduce execute world (filter #(flow? % world) flows)))

View file

@ -37,7 +37,7 @@
:property :q
:quantity 2.4}]
(is (flow? valid world))
(let [transferred (execute valid world')
(let [transferred (execute world' valid)
source-q (:q (get-cell transferred 0 0))
dest-q (:q (get-cell transferred 1 1))]
(is (= source-q 2.9))
@ -46,7 +46,7 @@
:destination {:x 0 :y 1}
:property :q
:quantity 1}
transferred (execute-flows (list valid valid2) world')
transferred (execute-flows world' (list valid valid2))
source-q (:q (get-cell transferred 0 0))
inter-q (:q (get-cell transferred 1 1))
dest-q (:q (get-cell transferred 0 1))]