Skip to content

Instantly share code, notes, and snippets.

@luxbock
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxbock/e192b33d2d578ef8b696 to your computer and use it in GitHub Desktop.
Save luxbock/e192b33d2d578ef8b696 to your computer and use it in GitHub Desktop.
(defn branch-off
"Draws the game tree from an initial node and rules of the game."
[rules {:keys [pid id] :as node}]
(cond
(node/terminal? node) node
(nil? pid) (branch-off rules (assoc node :pid -1 :id 0))
:else (assoc node
:actions (map-vals (partial branch-off rules)
(add-ids id (map-actions rules node))))))
;; vs.
(defn branch-off
"Draws the game tree from an initial node and rules of the game."
[rules {:keys [pid id] :as node}]
(if (node/terminal? node)
node
(if (nil? pid)
(branch-off rules (assoc node :pid -1 :id 0))
(assoc node
:actions (map-vals (partial branch-off rules)
(map-actions rules node))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment