Created
January 22, 2011 16:44
-
-
Save swannodette/791233 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
; helper method | |
(defn grant-resource | |
[location resource buildings players] | |
(let [building (@buildings location) | |
building-type (if-not (nil? building) (building :type) :none)] | |
(case building-type | |
:settlement (dosync (alter players update-in [(building :owner) resource] (partial + 1))) | |
:city (dosync (alter players update-in [(building :owner) resource] (partial + 2))) | |
:none nil))) | |
(defn harvest-resources | |
[number fields buildings players robber] | |
(for [field (filter #(and (> (key %) 0) ((val %) number)) fields) | |
neighbor (fields-to-nodes (key field))] | |
(if-not (= (key field) @robber) | |
(grant-resource neighbor ((val field) number) buildings players)))) | |
(defn roll-dice | |
[] | |
(harvest-resources @dice-result fields buildings players robber)) | |
(defn execute | |
"takes a player's name + an expression | |
(must be quoted to prevent prior execution) | |
and executes the expression if it's the player's | |
turn" | |
[player f] | |
(if (and (true? @game-started) | |
(= @current-player player)) | |
(f)) | |
(execute :blue roll-dice) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment