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..f9904bea 100644 --- a/src/p_p_p_pokerface.clj +++ b/src/p_p_p_pokerface.clj @@ -1,34 +1,62 @@ (ns p-p-p-pokerface) +(def two-digit-ranks {\T 10, \J 11, \Q 12, \K 13, \A 14}) + (defn rank [card] - nil) + (let [[rank-character _] card] + (if (Character/isDigit rank-character) + (Integer/valueOf (str rank-character)) + (two-digit-ranks rank-character)))) (defn suit [card] - nil) + (let [[_ suit-character] card] + (str suit-character))) + +(defn ranks [hand] + (map rank hand)) + +(defn rank-freq-values [hand] + (vals (frequencies (ranks hand)))) (defn pair? [hand] - nil) + (= [1 1 1 2] (sort (rank-freq-values hand)))) (defn three-of-a-kind? [hand] - nil) + (= [1 1 3] (sort (rank-freq-values hand)))) (defn four-of-a-kind? [hand] - nil) + (= 4 (apply max (rank-freq-values hand)))) (defn flush? [hand] - nil) + (= 1 (count (set (map suit hand))))) (defn full-house? [hand] - nil) + (= [2 3] (sort (rank-freq-values hand)))) (defn two-pairs? [hand] - nil) + (= [1 2 2] (sort (rank-freq-values hand)))) (defn straight? [hand] - nil) + (letfn [(is-straight? [rankss] + (= (sort rankss) (range (apply min rankss) (inc (apply max rankss)))))] + (or (let [low-aces-ranks (replace {14 1} (ranks hand))] + (is-straight? low-aces-ranks)) + (is-straight? (ranks hand))))) (defn straight-flush? [hand] - nil) + (and (straight? hand) (flush? hand))) + +(defn high-card? [hand] + true) (defn value [hand] - nil) + (let [checkers #{[high-card? 0] + [pair? 1] + [two-pairs? 2] + [three-of-a-kind? 3] + [straight? 4] + [flush? 5] + [full-house? 6] + [four-of-a-kind? 7] + [straight-flush? 8]}] + (apply max (map second (filter (fn [x] ((first x) hand)) checkers)))))