-
-
Save luxbock/e192b33d2d578ef8b696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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