001  (ns cc.journeyman.the-great-game.merchants.merchants
002    "Trade planning for merchants, primarily."
003    (:require [cc.journeyman.the-great-game.utils :refer [deep-merge]]
004              [cc.journeyman.the-great-game.merchants.strategies.simple :refer [move-merchant]]
005              [taoensso.timbre :as l]))
006  
007  
008  (defn run
009    "Return a partial world based on this `world`, but with each merchant moved."
010    [world]
011    (try
012      (reduce
013       deep-merge
014       world
015       (map
016        #(try
017           (let [move-fn (or
018                          (-> world :merchants % :move-fn)
019                          move-merchant)]
020             (apply move-fn (list % world)))
021           (catch Exception any
022             (l/error any "Failure while moving merchant " %)
023             {}))
024        (keys (:merchants world))))
025      (catch Exception any
026        (l/error any "Failure while moving merchants")
027        world)))
028