-
-
Save KirinDave/3d800d9dfc8c437e548d 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
(ns kirindave.foosball.player | |
(:use [clojure.contrib str-utils] [clojure.set]) | |
(:import [java.util Date])) | |
(def players (ref #{})) | |
(def teams (ref #{})) | |
(def games (ref ())) | |
(def ladder (ref [])) | |
(destruct history :wins :losses) | |
(defstruct player :name :history) | |
(defstruct team :players) | |
(defstruct game :team1 :team2 :winner :date-played) | |
(defn make-history | |
([wins losses] (struct history wins losses)) | |
([] (struct history 0 0))) | |
(defn make-player | |
([name] (struct player name (ref (make-history)))) | |
([name wins] (struct player name (ref (make-history wins 0)))) | |
([name wins games] (struct player name (ref (make-history wins (- games wins)))))) | |
(defn make-team [& players] | |
(struct team (set players))) | |
(defn make-game | |
([team1 team2 winner] (struct game team1 team2 winner (Date.))) | |
([team1 team2 winner when] (struct game team1 team2 winner when))) | |
(defn add-player! [player] | |
(dosync (commute players conj player))) | |
(defn add-team! [team] | |
(dosync (commute teams conj team))) | |
(defn push-game! [game] | |
(dosync (commute games conj team))) | |
; Data helpers | |
(defn- initials [{name :name}] | |
(apply str (map #(-> % first Character/toUpperCase) (re-split #" " name)))) | |
(defn team-nickname [{player1 :player1 player2 :player2}] | |
(apply str (sort (interpose "/" (list (initials player1) (initials player2)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment