Skip to content

Instantly share code, notes, and snippets.

@punchagan
Created March 30, 2019 16:31
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 punchagan/4d80c76692135ed1ce07cd5229a7f146 to your computer and use it in GitHub Desktop.
Save punchagan/4d80c76692135ed1ce07cd5229a7f146 to your computer and use it in GitHub Desktop.
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