diff --git a/.travis.yml b/.travis.yml index 455f3c0e..45c29f60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: clojure -lein: lein2 -script: lein2 midje :config .midje-grading-config.clj +lein: lein +script: lein midje :config .midje-grading-config.clj jdk: - openjdk7 notifications: diff --git a/src/p_p_p_pokerface.clj b/src/p_p_p_pokerface.clj index 5ea80094..5a9f4541 100644 --- a/src/p_p_p_pokerface.clj +++ b/src/p_p_p_pokerface.clj @@ -1,34 +1,60 @@ (ns p-p-p-pokerface) (defn rank [card] - nil) + (def replacements {\T 10, + \J 11, + \Q 12, + \K 13, + \A 14}) + (let [[rank _] card] + (if (Character/isDigit rank) + (Integer/valueOf (str rank)) + (replacements rank)))) (defn suit [card] - nil) + (let [[_ suit] card] + (str suit))) (defn pair? [hand] - nil) + (= 2 (apply max (vals (frequencies (map rank hand)))))) (defn three-of-a-kind? [hand] - nil) + (= 3 (apply max (vals (frequencies (map rank hand)))))) (defn four-of-a-kind? [hand] - nil) + (= 4 (apply max (vals (frequencies (map rank hand)))))) (defn flush? [hand] - nil) + (= 5 (apply max (vals (frequencies (map suit hand)))))) (defn full-house? [hand] - nil) + (= [2 3] (sort (vals (frequencies (map rank hand)))))) (defn two-pairs? [hand] - nil) + (or (= [1 2 2] (sort (vals (frequencies (map rank hand))))) + (four-of-a-kind? hand))) (defn straight? [hand] - nil) + (let [sorted-hand (sort (map rank hand)) + minimum (apply min sorted-hand)] + (or (= (range minimum (+ minimum 5)) sorted-hand) + (= [2 3 4 5 14] sorted-hand)))) (defn straight-flush? [hand] - nil) + (and (straight? hand) + (flush? hand))) + +(defn high-card? [hand] + true) (defn value [hand] - nil) + (cond + (straight-flush? hand) 8 + (four-of-a-kind? hand) 7 + (full-house? hand) 6 + (flush? hand) 5 + (straight? hand) 4 + (three-of-a-kind? hand) 3 + (two-pairs? hand) 2 + (pair? hand) 1 + (high-card? hand) 0))