Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quidditch simulation - ClojureBridge BLR workshop
(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
You can’t perform that action at this time.