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..eb1b463e 100644 --- a/src/p_p_p_pokerface.clj +++ b/src/p_p_p_pokerface.clj @@ -1,34 +1,61 @@ (ns p-p-p-pokerface) (defn rank [card] - nil) + (let [rnk (get card 0)] + (if (Character/isDigit rnk) + (Integer/valueOf (str rnk)) + (get {\T 10 \J 11 \Q 12 \K 13 \A 14} rnk)))) (defn suit [card] - nil) + (str (get card 1))) (defn pair? [hand] - nil) + (let [freqs (vals (frequencies (map rank hand)))] + (not (empty? (filter #(= 2 %) freqs))))) (defn three-of-a-kind? [hand] - nil) + (let [freqs (vals (frequencies (map rank hand)))] + (not (empty? (filter #(= 3 %) freqs))))) (defn four-of-a-kind? [hand] - nil) + (let [freqs (vals (frequencies (map rank hand)))] + (not (empty? (filter #(= 4 %) freqs))))) (defn flush? [hand] - nil) + (let [freqs (vals (frequencies (map suit hand)))] + (not (empty? (filter #(= 5 %) freqs))))) (defn full-house? [hand] - nil) + (and (pair? hand) + (three-of-a-kind? hand))) (defn two-pairs? [hand] - nil) + (let [freqs (vals (frequencies (map rank hand)))] + (or (= (count (filter #(= 2 %) freqs)) 2) + (= (count (filter #(= 4 %) freqs)) 1)))) (defn straight? [hand] - nil) + (let [ranks (map rank hand) + sorted-ranks (sort ranks) + rank-range (range (apply min sorted-ranks) + (inc (apply max sorted-ranks)))] + (if (and (= (take 4 sorted-ranks) (range 2 6)) + (= (get (vec sorted-ranks) 4) 14)) + true + (= sorted-ranks rank-range)))) (defn straight-flush? [hand] - nil) + (and (straight? hand) + (flush? hand))) (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 + :else 0))