Created
March 30, 2019 16:31
-
-
Save punchagan/4d80c76692135ed1ce07cd5229a7f146 to your computer and use it in GitHub Desktop.
Quidditch simulation - ClojureBridge BLR workshop
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
(ns teaching-clojure.quidditch) | |
(def game-at-start | |
{:gryffindor {:score 0 | |
:players 7} | |
:slytherin {:score 0 | |
:players 7}}) | |
(def opposition {:gryffindor :slytherin | |
:slytherin :gryffindor}) | |
(defn score-team [game team] | |
(update-in game [team :score] + 1)) | |
(defn catch-snitch [game team] | |
(update-in game [team :score] + 5)) | |
(defn beat-team [game team] | |
(-> | |
game | |
(score-team team) | |
(update-in [(team opposition) :players] dec))) | |
(defn won? [game team] | |
(and (> (get-in game [team :score]) | |
(get-in game [(team opposition) :score])) | |
(pos? (get-in game [team :players])))) | |
(-> | |
game-at-start | |
(score-team :slytherin) | |
(score-team :slytherin) | |
(beat-team :gryffindor) | |
(catch-snitch :gryffindor) | |
(won? :gryffindor)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment