;; canon: bot.git src/bot/policies/registry.cljs (ported from src/policies/registry.ts)
;;
;; The policy registry: the seam between the room plumbing and any learned
;; game brains. A game that learns registers a provider object
;; #js {:game :init :forRoom}; __NAME__.rooms asks the registry for an attachment
;; when it joins a game room and wires it in blind — it never knows which
;; games learn. A bot with no learned games simply registers nothing:
;; deleting every provider touches neither this namespace nor __NAME__.rooms.
(ns __NAME__.policies.registry)
(def ^:private providers (js/Map.))
(defn register-policy [^js p]
(.set providers (.-game p) p)
js/undefined)
(defn init-policies
"Process-wide setup (checkpoint stores), once at boot."
[learning log]
(.forEach providers (fn [^js p _k] ((.-init p) learning log)))
js/undefined)
(defn policy-for-room
"A fresh attachment (#js {:joinOptions :attach}) for one room, or nil."
[game epsilon data-dir]
(if-some [^js p (.get providers game)]
((.-forRoom p) epsilon data-dir)
nil))