dev / templates / bot / src / __NAME__ / policies / index.cljs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;; Learned-game providers: requiring a namespace registers its policy.
;; No games learn yet — this namespace is the fill-in point for
;; docs/NEW-BOT-PROMPT.md §5 (which delegates the brain itself to train-kit's
;; NEW-BRAIN-PROMPT.md). Dropping a learned game = deleting its provider
;; namespace + one require here.
;;
;; The complete pattern, worked for a hypothetical valley-blocks brain
;; (adapt the hook name and feature code to your game; bot.git's
;; src/bot/policies/*.cljs are the live worked examples):
;;
;;   ;; ---- src/__NAME__/policies/valley_blocks.cljs ----------------------
;;   (ns __NAME__.policies.valley-blocks
;;     (:require ["ardegazu-train-kit" :refer (CheckpointStore checkpointPath
;;                                             EpisodeWriter isMlpModel)]
;;               [__NAME__.policies.registry :refer (register-policy)]
;;               [__NAME__.rl.valleyblocks-policy :as vp]))
;;
;;   ;; one checkpoint store for the whole process — every room reads it,
;;   ;; the trainer (a different process) is the only writer
;;   (def ^:private store (atom nil))
;;
;;   (register-policy
;;    #js {:game "valley-blocks"
;;         :init (fn [^js learning log]
;;                 (reset! store
;;                         (CheckpointStore. (checkpointPath (.-modelDir learning) "valley-blocks")
;;                                           (.-reloadMs learning)
;;                                           (fn [^js m] (log (str "model valley-blocks loaded ("
;;                                                                 (.-episodes m) " episodes)"))))))
;;         :forRoom (fn [epsilon data-dir]
;;                    ;; per-room recorder: ε-greedy inference from the shared
;;                    ;; checkpoint (stock fallback before the first promotion)
;;                    ;; + transition logging to episode JSONL for the trainer.
;;                    ;; Guard the checkpoint's shape — the recorder sees its
;;                    ;; own game's model or nil, never junk.
;;                    (let [model (fn []
;;                                  (let [m (some-> ^js @store .-model)]
;;                                    (when (and (some? m) (isMlpModel m "valley-blocks")) m)))
;;                          rec (vp/make-recorder model epsilon (EpisodeWriter. data-dir))]
;;                      #js {:joinOptions #js {:onPiece (fn [view] (.onPiece ^js rec view))}
;;                           :attach (fn [room] (.attach ^js rec room))}))})
;;   ;; --------------------------------------------------------------------
;;
;; Then one require here per learned game:
;;
;;   (ns __NAME__.policies.index
;;     (:require [__NAME__.policies.valley-blocks]))
(ns __NAME__.policies.index)

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git